Skip to content

Commit a0cd7a2

Browse files
author
Krzysztof Chrapka
committed
Add support for buster test in browsers
1 parent b123f54 commit a0cd7a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+431
-144
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules/
22
experiments/
33
.idea/
44
*~
5+
*.log
56
bower_components/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and check out a few [example applications](docs/introduction.md#example-apps).
2222
1. [Getting Started](docs/get.md)
2323
1. [Reference Documentation](docs/README.md)
2424
1. [Example Code and Apps](docs/introduction.md#example-apps)
25+
1. [Testing](docs/testing.md)
2526
1. [Full Changelog](CHANGES.md)
2627

2728
# License

docs/testing.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Testing wire.js
2+
3+
Wire.js is using [buster](http://busterjs.org) for testing. You need to have [node.js](https://nodejs.org) installed to run tests of wire.js.
4+
5+
# Testing in node.js:
6+
7+
[Install wire.js](docs/get.md) and run in installation directory
8+
$ npm install
9+
$ npm test
10+
11+
# Testing in browser
12+
13+
[Install wire.js](docs/get.md) and run in installation directory
14+
15+
```
16+
$ npm install
17+
$ npm run-script start-test-server
18+
```
19+
20+
Open http://localhost:1111 in your browser and click "Capture browser" button. Browser is now connected to test server
21+
and will be used by it to run tests.
22+
23+
Run in wire.js installation directory (without closing browser and test server)
24+
```
25+
$ npm run-script browser-test
26+
```

package.json

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,62 @@
11
{
2-
"name": "wire",
3-
"version": "0.10.11",
4-
"description": "A light, fast, flexible Javascript IOC container.",
5-
"keywords": [
6-
"ioc",
7-
"aop",
8-
"dependency injection",
9-
"dependency inversion",
10-
"application composition",
11-
"cujo"
12-
],
13-
"licenses": [
14-
{
15-
"type": "MIT",
16-
"url": "http://www.opensource.org/licenses/mit-license.php"
17-
}
18-
],
19-
"repository": {
20-
"type": "git",
21-
"url": "https://github.com/cujojs/wire"
22-
},
23-
"bugs": "https://github.com/cujojs/wire/issues",
24-
"maintainers": [
25-
{
26-
"name": "Brian Cavalier",
27-
"web": "http://hovercraftstudios.com"
28-
}
29-
],
30-
"contributors": [
31-
{
32-
"name": "Brian Cavalier",
33-
"web": "http://hovercraftstudios.com"
34-
},
35-
{
36-
"name": "John Hann",
37-
"web": "http://unscriptable.com"
38-
}
39-
],
40-
"dependencies": {
41-
"meld": "~1",
42-
"when": ">=2.6.0 <4"
43-
},
44-
"devDependencies": {
45-
"buster": "~0.7",
46-
"bower": "~1",
47-
"gent": "~0.6"
48-
},
49-
"main": "./wire",
50-
"directories": {
51-
"test": "test"
52-
},
53-
"scripts": {
54-
"test": "buster-test -e node",
55-
"prepublish": "bower install"
56-
}
2+
"name": "wire",
3+
"version": "0.10.11",
4+
"description": "A light, fast, flexible Javascript IOC container.",
5+
"keywords": [
6+
"ioc",
7+
"aop",
8+
"dependency injection",
9+
"dependency inversion",
10+
"application composition",
11+
"cujo"
12+
],
13+
"licenses": [
14+
{
15+
"type": "MIT",
16+
"url": "http://www.opensource.org/licenses/mit-license.php"
17+
}
18+
],
19+
"repository": {
20+
"type": "git",
21+
"url": "https://github.com/cujojs/wire"
22+
},
23+
"bugs": "https://github.com/cujojs/wire/issues",
24+
"maintainers": [
25+
{
26+
"name": "Brian Cavalier",
27+
"web": "http://hovercraftstudios.com"
28+
}
29+
],
30+
"contributors": [
31+
{
32+
"name": "Brian Cavalier",
33+
"web": "http://hovercraftstudios.com"
34+
},
35+
{
36+
"name": "John Hann",
37+
"web": "http://unscriptable.com"
38+
}
39+
],
40+
"dependencies": {
41+
"meld": "~1",
42+
"when": ">=2.6.0 <4"
43+
},
44+
"devDependencies": {
45+
"bower": "~1",
46+
"buster": "~0.7",
47+
"buster-amd": "^0.3.1",
48+
"gent": "~0.6",
49+
"glob": "^7.0.3",
50+
"requirejs": "^2.2.0"
51+
},
52+
"main": "./wire",
53+
"directories": {
54+
"test": "test"
55+
},
56+
"scripts": {
57+
"test": "buster-test -e node",
58+
"start-test-server": "buster-server",
59+
"browser-test": "buster-test -e browser",
60+
"prepublish": "bower install"
61+
}
5762
}

test/buster.js

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
'use strict';
2+
var fs = require('fs');
3+
4+
var glob = require('glob');
5+
var busterAmd = require('buster-amd');
6+
7+
var conditionalLoadGenerator = require('./node-es6/conditional-load-generator');
28

39
require('gent/test-adapter/buster');
410

11+
var tests = ['node/**/*.js'];
12+
var nodeTests = tests.slice();
13+
var es6Tests = glob.sync('node-es6/**/*-test.js');
14+
var conditionalBrowserLoaders = [ 'node-es6/var/conditional-load.js'];
15+
16+
// begin node test setup
17+
518
function evaluates (statement) {
619
try {
720
/* jshint evil: true */
@@ -21,22 +34,48 @@ function isSpreadAvailable() {
2134
return evaluates('parseInt(...["20", 10])');
2235
}
2336

24-
var tests = ['node/**/*-test.js'];
25-
26-
console.log('class operator %savailable', isClassAvailable() ? '' : 'not ');
27-
console.log('spread operator %savailable', isSpreadAvailable() ? '' : 'not ');
28-
37+
console.log('class operator %savailable in node', isClassAvailable() ? '' : 'not ');
38+
console.log('spread operator %savailable in node', isSpreadAvailable() ? '' : 'not ');
2939
if(
3040
isClassAvailable()
3141
&& isSpreadAvailable()
3242
&& !('ES_VERSION' in process.env && parseFloat(process.env.ES_VERSION) < 6)
3343
) {
34-
tests.push('node-es6/**/*-test.js');
44+
nodeTests = nodeTests.concat(es6Tests);
3545
}
3646

3747
module.exports['node'] = {
3848
environment: 'node',
39-
tests: tests
49+
tests: tests.concat(nodeTests)
4050
// TODO: Why doesn't this work?
4151
//, testHelpers:['gent/test-adapter/buster']
4252
};
53+
54+
// begin browser test setup
55+
56+
// hack, we have to detect if browser is es6 capable in browser itself
57+
// and load es6 tests only when that is true
58+
// but to load es6 tests in browser we have to have list of them after decision
59+
// whether to load them is made. I found no other way to pass this list to browser
60+
// than with static file
61+
fs.writeFileSync(
62+
__dirname+'/node-es6/var/conditional-load.js',
63+
conditionalLoadGenerator(es6Tests.map(function(e){return 'test/'+e;}))
64+
);
65+
66+
67+
module.exports['browser'] = {
68+
environment: 'browser',
69+
rootPath: '../',
70+
libs: [
71+
'node_modules/requirejs/require.js',
72+
'test/requirejs-main.js',
73+
],
74+
sources:
75+
['lib/**/*.js', 'lib/*.js', 'node_modules/{gent,meld,when}/**/*.js', 'dom/**/*.js', '*.js']
76+
.concat(es6Tests.map(function(e){return 'test/'+e;})),
77+
tests: tests
78+
.concat(conditionalBrowserLoaders)
79+
.map(function(e){return 'test/'+e;}),
80+
extensions: [busterAmd]
81+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
var templ = '(function(define){\n'+
3+
'\n'+
4+
' function evaluates (statement) {\n'+
5+
' try {\n'+
6+
' eval(statement);\n'+
7+
' return true;\n'+
8+
' } catch (err) {\n'+
9+
' return false;\n'+
10+
' }\n'+
11+
' }\n'+
12+
'\n'+
13+
' function isClassAvailable() {\n'+
14+
' return evaluates(\'class es6TestClass_ibyechBaloodren7 {}\');\n'+
15+
' }\n'+
16+
'\n'+
17+
' function isSpreadAvailable() {\n'+
18+
' return evaluates(\'parseInt(...[\"20\", 10])\');\n'+
19+
' }\n'+
20+
'\n'+
21+
' var tests = TEST_FILES;\n'+
22+
' var requires = [];\n'+
23+
'\n'+
24+
' if(\n'+
25+
' isClassAvailable()\n'+
26+
' && isSpreadAvailable()\n'+
27+
' && !(typeof(process) !== \'undefined\' && \'ES_VERSION\' in process.env && parseFloat(process.env.ES_VERSION) < 6)\n'+
28+
' ) {\n'+
29+
' requires = tests;\n'+
30+
' }\n'+
31+
' console.log(\'class operator \'+ (isClassAvailable() ? \'\' : \'not \') + \'available in browser\');\n'+
32+
' console.log(\'spread operator \'+ (isSpreadAvailable() ? \'\' : \'not \') + \'available in browser\');\n'+
33+
' define(requires, function(){});\n'+
34+
'\n'+
35+
'})(typeof define !== \'undefined\' ? define : function(factory){module.exports = factory(require);});';
36+
37+
module.exports = function (testFiles){
38+
return templ.replace(/TEST_FILES/, JSON.stringify(testFiles));
39+
};

test/node-es6/lib/plugin/basePlugin-test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/* jshint esversion: 6 */
2-
(function(buster, context) {
2+
(function(define){define(function(require){
33
'use strict';
44

5+
(function(buster, context) {
6+
57
var assert, refute, fail, sentinel;
68

79
assert = buster.assert;
@@ -93,3 +95,5 @@ buster.testCase('es6/lib/plugin/basePlugin', {
9395
require('buster'),
9496
require('../../../../lib/context')
9597
);
98+
99+
});})(typeof define !== 'undefined' ? define : function(factory){module.exports = factory(require);});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
(function(define){
2+
3+
function evaluates (statement) {
4+
try {
5+
eval(statement);
6+
return true;
7+
} catch (err) {
8+
return false;
9+
}
10+
}
11+
12+
function isClassAvailable() {
13+
return evaluates('class es6TestClass_ibyechBaloodren7 {}');
14+
}
15+
16+
function isSpreadAvailable() {
17+
return evaluates('parseInt(...["20", 10])');
18+
}
19+
20+
var tests = [];
21+
var requires = [];
22+
23+
if(
24+
isClassAvailable()
25+
&& isSpreadAvailable()
26+
&& !(typeof(process) !== 'undefined' && 'ES_VERSION' in process.env && parseFloat(process.env.ES_VERSION) < 6)
27+
) {
28+
requires = tests;
29+
}
30+
console.log('class operator '+ (isClassAvailable() ? '' : 'not ') + 'available in browser');
31+
console.log('spread operator '+ (isSpreadAvailable() ? '' : 'not ') + 'available in browser');
32+
define(requires, function(){});
33+
34+
})(typeof define !== 'undefined' ? define : function(factory){module.exports = factory(require);});

test/node/ComponentFactory-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
(function(define){define(function(require){
12
var buster, assert, refute, fail, ComponentFactory, sentinel;
23

34
buster = require('buster');
@@ -66,3 +67,4 @@ buster.testCase('lib/ComponentFactory', {
6667
}
6768

6869
});
70+
});})(typeof define !== 'undefined' ? define : function(fac){module.exports = fac(require);});

test/node/aop-test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
(function(define){define(function(require){
12
(function(buster, wire, aopPlugin, when) {
23
"use strict";
34

@@ -893,4 +894,5 @@ buster.testCase('aop', {
893894
require('../../wire'),
894895
require('../../aop'),
895896
require('when')
896-
);
897+
);
898+
});})(typeof define !== 'undefined' ? define : function(fac){module.exports = fac(require);});

0 commit comments

Comments
 (0)