Skip to content

Commit 77f4c83

Browse files
author
Robin Thrift
committed
added tests
1 parent 97fc237 commit 77f4c83

File tree

12 files changed

+384
-0
lines changed

12 files changed

+384
-0
lines changed

test/_browser.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>TESTING REQUIRE JS STUFF</title>
6+
</head>
7+
<body>
8+
This document can be used to test if everything is loaded correct in the browser by require.js
9+
<!--script data-main="fixtures/simple_init" src="require.js"></script-->
10+
<!--script data-main="fixtures/umd_init" src="require.js"></script-->
11+
<!--script data-main="fixtures/complex_init" src="require.js"></script-->
12+
<script src="almond.js"></script>
13+
<!--script src="expected/simple_init.js"></script-->
14+
<!--script src="expected/umd_init.js"></script-->
15+
<script src="expected/complex_init.js"></script>
16+
</body>
17+
</html>

test/expected/complex_init.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
2+
define('simple_amd_file',[],function() {
3+
4+
var Mult = function(a, b) {
5+
return a * b;
6+
}
7+
8+
return Mult;
9+
10+
});
11+
// src for the wrapper: https://github.com/umdjs/umd/blob/master/amdWeb.js
12+
(function (root, factory) {
13+
if (typeof define === 'function' && define.amd) {
14+
// AMD. Register as an anonymous module.
15+
define('umd_file',factory);
16+
} else {
17+
// Browser globals
18+
root.amdWeb = factory(root.b);
19+
}
20+
}(this, function() {
21+
//use b in some fashion.
22+
23+
// Just return a value to define the module export.
24+
// This example returns an object, but the module
25+
// can return a function as the exported value.
26+
return {
27+
test: function() {
28+
console.log('Test Log from the UMD file');
29+
}
30+
};
31+
}));
32+
(function(root) {
33+
34+
root.myLib = {};
35+
36+
myLib.sum = function(a, b) {
37+
return a + b;
38+
} // END PROTYPE OF sum
39+
40+
})(this);
41+
define("non_md_file", (function (global) {
42+
return function () {
43+
var ret, fn;
44+
return ret || global.myLib;
45+
};
46+
}(this)));
47+
48+
define('complex_amd_file',['non_md_file', 'simple_amd_file'], function(MyLib, Mult) {
49+
50+
var SumMulti = function(a, b) {
51+
return Mult(MyLib.sum(a, b), b);
52+
}
53+
54+
return SumMulti;
55+
56+
});
57+
requirejs.config({
58+
baseUrl: '/fixtures/vendor',
59+
60+
shim: {
61+
'non_md_file': {
62+
exports: 'myLib'
63+
}
64+
}
65+
})
66+
67+
requirejs(['simple_amd_file', 'umd_file', 'complex_amd_file'], function(Mult, UMDLib, SumMulti) {
68+
console.log("executing the COMPLEX init file");
69+
console.log(Mult(3, 5), '<= this should be 15');
70+
UMDLib.test(); // should log 'Test Log from the UMD file'
71+
console.log(SumMulti(5, 8), '<= this should be 104');
72+
});
73+
define("../complex_init", function(){});
74+
75+
define("../complex_init", function(){});

test/expected/simple_init.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
define('vendor/simple_amd_file',[],function() {
3+
4+
var Mult = function(a, b) {
5+
return a * b;
6+
}
7+
8+
return Mult;
9+
10+
});
11+
requirejs(['vendor/simple_amd_file'], function(Mult) {
12+
console.log("executing the simple init file");
13+
console.log(Mult(3, 5));
14+
});
15+
define("simple_init", function(){});
16+
17+
define("simple_init", function(){});

test/expected/umd_init.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
define('vendor/simple_amd_file',[],function() {
3+
4+
var Mult = function(a, b) {
5+
return a * b;
6+
}
7+
8+
return Mult;
9+
10+
});
11+
// src for the wrapper: https://github.com/umdjs/umd/blob/master/amdWeb.js
12+
(function (root, factory) {
13+
if (typeof define === 'function' && define.amd) {
14+
// AMD. Register as an anonymous module.
15+
define('vendor/umd_file',factory);
16+
} else {
17+
// Browser globals
18+
root.amdWeb = factory(root.b);
19+
}
20+
}(this, function() {
21+
//use b in some fashion.
22+
23+
// Just return a value to define the module export.
24+
// This example returns an object, but the module
25+
// can return a function as the exported value.
26+
return {
27+
test: function() {
28+
console.log('Test Log from the UMD file');
29+
}
30+
};
31+
}));
32+
requirejs(['vendor/simple_amd_file', 'vendor/umd_file'], function(Mult, UMDLib) {
33+
console.log("executing the UMD+AMD init file");
34+
console.log(Mult(3, 5));
35+
UMDLib.test(); // should log 'Test Log from the UMD file'
36+
});
37+
define("umd_init", function(){});
38+
39+
define("umd_init", function(){});

test/fixtures/complex_init.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
requirejs.config({
2+
baseUrl: '/fixtures/vendor',
3+
4+
shim: {
5+
'non_md_file': {
6+
exports: 'myLib'
7+
}
8+
}
9+
})
10+
11+
requirejs(['simple_amd_file', 'umd_file', 'complex_amd_file'], function(Mult, UMDLib, SumMulti) {
12+
console.log("executing the COMPLEX init file");
13+
console.log(Mult(3, 5), '<= this should be 15');
14+
UMDLib.test(); // should log 'Test Log from the UMD file'
15+
console.log(SumMulti(5, 8), '<= this should be 104');
16+
});

test/fixtures/simple_init.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
requirejs(['vendor/simple_amd_file'], function(Mult) {
2+
console.log("executing the simple init file");
3+
console.log(Mult(3, 5));
4+
});

test/fixtures/umd_init.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
requirejs(['vendor/simple_amd_file', 'vendor/umd_file'], function(Mult, UMDLib) {
2+
console.log("executing the UMD+AMD init file");
3+
console.log(Mult(3, 5));
4+
UMDLib.test(); // should log 'Test Log from the UMD file'
5+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
define(['non_md_file', 'simple_amd_file'], function(MyLib, Mult) {
2+
3+
var SumMulti = function(a, b) {
4+
return Mult(MyLib.sum(a, b), b);
5+
}
6+
7+
return SumMulti;
8+
9+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(function(root) {
2+
3+
root.myLib = {};
4+
5+
myLib.sum = function(a, b) {
6+
return a + b;
7+
} // END PROTYPE OF sum
8+
9+
})(this);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
define(function() {
2+
3+
var Mult = function(a, b) {
4+
return a * b;
5+
}
6+
7+
return Mult;
8+
9+
});

0 commit comments

Comments
 (0)