Skip to content

Commit

Permalink
Add support for buster test in browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Chrapka committed Apr 24, 2016
1 parent b123f54 commit a0cd7a2
Show file tree
Hide file tree
Showing 64 changed files with 431 additions and 144 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/
experiments/
.idea/
*~
*.log
bower_components/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and check out a few [example applications](docs/introduction.md#example-apps).
1. [Getting Started](docs/get.md)
1. [Reference Documentation](docs/README.md)
1. [Example Code and Apps](docs/introduction.md#example-apps)
1. [Testing](docs/testing.md)
1. [Full Changelog](CHANGES.md)

# License
Expand Down
26 changes: 26 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Testing wire.js

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.

# Testing in node.js:

[Install wire.js](docs/get.md) and run in installation directory
$ npm install
$ npm test

# Testing in browser

[Install wire.js](docs/get.md) and run in installation directory

```
$ npm install
$ npm run-script start-test-server
```

Open http://localhost:1111 in your browser and click "Capture browser" button. Browser is now connected to test server
and will be used by it to run tests.

Run in wire.js installation directory (without closing browser and test server)
```
$ npm run-script browser-test
```
115 changes: 60 additions & 55 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,57 +1,62 @@
{
"name": "wire",
"version": "0.10.11",
"description": "A light, fast, flexible Javascript IOC container.",
"keywords": [
"ioc",
"aop",
"dependency injection",
"dependency inversion",
"application composition",
"cujo"
],
"licenses": [
{
"type": "MIT",
"url": "http://www.opensource.org/licenses/mit-license.php"
}
],
"repository": {
"type": "git",
"url": "https://github.com/cujojs/wire"
},
"bugs": "https://github.com/cujojs/wire/issues",
"maintainers": [
{
"name": "Brian Cavalier",
"web": "http://hovercraftstudios.com"
}
],
"contributors": [
{
"name": "Brian Cavalier",
"web": "http://hovercraftstudios.com"
},
{
"name": "John Hann",
"web": "http://unscriptable.com"
}
],
"dependencies": {
"meld": "~1",
"when": ">=2.6.0 <4"
},
"devDependencies": {
"buster": "~0.7",
"bower": "~1",
"gent": "~0.6"
},
"main": "./wire",
"directories": {
"test": "test"
},
"scripts": {
"test": "buster-test -e node",
"prepublish": "bower install"
}
"name": "wire",
"version": "0.10.11",
"description": "A light, fast, flexible Javascript IOC container.",
"keywords": [
"ioc",
"aop",
"dependency injection",
"dependency inversion",
"application composition",
"cujo"
],
"licenses": [
{
"type": "MIT",
"url": "http://www.opensource.org/licenses/mit-license.php"
}
],
"repository": {
"type": "git",
"url": "https://github.com/cujojs/wire"
},
"bugs": "https://github.com/cujojs/wire/issues",
"maintainers": [
{
"name": "Brian Cavalier",
"web": "http://hovercraftstudios.com"
}
],
"contributors": [
{
"name": "Brian Cavalier",
"web": "http://hovercraftstudios.com"
},
{
"name": "John Hann",
"web": "http://unscriptable.com"
}
],
"dependencies": {
"meld": "~1",
"when": ">=2.6.0 <4"
},
"devDependencies": {
"bower": "~1",
"buster": "~0.7",
"buster-amd": "^0.3.1",
"gent": "~0.6",
"glob": "^7.0.3",
"requirejs": "^2.2.0"
},
"main": "./wire",
"directories": {
"test": "test"
},
"scripts": {
"test": "buster-test -e node",
"start-test-server": "buster-server",
"browser-test": "buster-test -e browser",
"prepublish": "bower install"
}
}
53 changes: 46 additions & 7 deletions test/buster.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
'use strict';
var fs = require('fs');

var glob = require('glob');
var busterAmd = require('buster-amd');

var conditionalLoadGenerator = require('./node-es6/conditional-load-generator');

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

var tests = ['node/**/*.js'];
var nodeTests = tests.slice();
var es6Tests = glob.sync('node-es6/**/*-test.js');
var conditionalBrowserLoaders = [ 'node-es6/var/conditional-load.js'];

// begin node test setup

function evaluates (statement) {
try {
/* jshint evil: true */
Expand All @@ -21,22 +34,48 @@ function isSpreadAvailable() {
return evaluates('parseInt(...["20", 10])');
}

var tests = ['node/**/*-test.js'];

console.log('class operator %savailable', isClassAvailable() ? '' : 'not ');
console.log('spread operator %savailable', isSpreadAvailable() ? '' : 'not ');

console.log('class operator %savailable in node', isClassAvailable() ? '' : 'not ');
console.log('spread operator %savailable in node', isSpreadAvailable() ? '' : 'not ');
if(
isClassAvailable()
&& isSpreadAvailable()
&& !('ES_VERSION' in process.env && parseFloat(process.env.ES_VERSION) < 6)
) {
tests.push('node-es6/**/*-test.js');
nodeTests = nodeTests.concat(es6Tests);
}

module.exports['node'] = {
environment: 'node',
tests: tests
tests: tests.concat(nodeTests)
// TODO: Why doesn't this work?
//, testHelpers:['gent/test-adapter/buster']
};

// begin browser test setup

// hack, we have to detect if browser is es6 capable in browser itself
// and load es6 tests only when that is true
// but to load es6 tests in browser we have to have list of them after decision
// whether to load them is made. I found no other way to pass this list to browser
// than with static file
fs.writeFileSync(
__dirname+'/node-es6/var/conditional-load.js',
conditionalLoadGenerator(es6Tests.map(function(e){return 'test/'+e;}))
);


module.exports['browser'] = {
environment: 'browser',
rootPath: '../',
libs: [
'node_modules/requirejs/require.js',
'test/requirejs-main.js',
],
sources:
['lib/**/*.js', 'lib/*.js', 'node_modules/{gent,meld,when}/**/*.js', 'dom/**/*.js', '*.js']
.concat(es6Tests.map(function(e){return 'test/'+e;})),
tests: tests
.concat(conditionalBrowserLoaders)
.map(function(e){return 'test/'+e;}),
extensions: [busterAmd]
};
39 changes: 39 additions & 0 deletions test/node-es6/conditional-load-generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

var templ = '(function(define){\n'+
'\n'+
' function evaluates (statement) {\n'+
' try {\n'+
' eval(statement);\n'+
' return true;\n'+
' } catch (err) {\n'+
' return false;\n'+
' }\n'+
' }\n'+
'\n'+
' function isClassAvailable() {\n'+
' return evaluates(\'class es6TestClass_ibyechBaloodren7 {}\');\n'+
' }\n'+
'\n'+
' function isSpreadAvailable() {\n'+
' return evaluates(\'parseInt(...[\"20\", 10])\');\n'+
' }\n'+
'\n'+
' var tests = TEST_FILES;\n'+
' var requires = [];\n'+
'\n'+
' if(\n'+
' isClassAvailable()\n'+
' && isSpreadAvailable()\n'+
' && !(typeof(process) !== \'undefined\' && \'ES_VERSION\' in process.env && parseFloat(process.env.ES_VERSION) < 6)\n'+
' ) {\n'+
' requires = tests;\n'+
' }\n'+
' console.log(\'class operator \'+ (isClassAvailable() ? \'\' : \'not \') + \'available in browser\');\n'+
' console.log(\'spread operator \'+ (isSpreadAvailable() ? \'\' : \'not \') + \'available in browser\');\n'+
' define(requires, function(){});\n'+
'\n'+
'})(typeof define !== \'undefined\' ? define : function(factory){module.exports = factory(require);});';

module.exports = function (testFiles){
return templ.replace(/TEST_FILES/, JSON.stringify(testFiles));
};
6 changes: 5 additions & 1 deletion test/node-es6/lib/plugin/basePlugin-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* jshint esversion: 6 */
(function(buster, context) {
(function(define){define(function(require){
'use strict';

(function(buster, context) {

var assert, refute, fail, sentinel;

assert = buster.assert;
Expand Down Expand Up @@ -93,3 +95,5 @@ buster.testCase('es6/lib/plugin/basePlugin', {
require('buster'),
require('../../../../lib/context')
);

});})(typeof define !== 'undefined' ? define : function(factory){module.exports = factory(require);});
34 changes: 34 additions & 0 deletions test/node-es6/var/conditional-load.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(function(define){

function evaluates (statement) {
try {
eval(statement);
return true;
} catch (err) {
return false;
}
}

function isClassAvailable() {
return evaluates('class es6TestClass_ibyechBaloodren7 {}');
}

function isSpreadAvailable() {
return evaluates('parseInt(...["20", 10])');
}

var tests = [];
var requires = [];

if(
isClassAvailable()
&& isSpreadAvailable()
&& !(typeof(process) !== 'undefined' && 'ES_VERSION' in process.env && parseFloat(process.env.ES_VERSION) < 6)
) {
requires = tests;
}
console.log('class operator '+ (isClassAvailable() ? '' : 'not ') + 'available in browser');
console.log('spread operator '+ (isSpreadAvailable() ? '' : 'not ') + 'available in browser');
define(requires, function(){});

})(typeof define !== 'undefined' ? define : function(factory){module.exports = factory(require);});
2 changes: 2 additions & 0 deletions test/node/ComponentFactory-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(function(define){define(function(require){
var buster, assert, refute, fail, ComponentFactory, sentinel;

buster = require('buster');
Expand Down Expand Up @@ -66,3 +67,4 @@ buster.testCase('lib/ComponentFactory', {
}

});
});})(typeof define !== 'undefined' ? define : function(fac){module.exports = fac(require);});
4 changes: 3 additions & 1 deletion test/node/aop-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(function(define){define(function(require){
(function(buster, wire, aopPlugin, when) {
"use strict";

Expand Down Expand Up @@ -893,4 +894,5 @@ buster.testCase('aop', {
require('../../wire'),
require('../../aop'),
require('when')
);
);
});})(typeof define !== 'undefined' ? define : function(fac){module.exports = fac(require);});
9 changes: 8 additions & 1 deletion test/node/builder/cram-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// test building only in node
if(typeof process !== 'undefined') {

(function(define){define(function(require){
var buster, assert, refute, fail, builder, forEach;

buster = require('buster');
Expand Down Expand Up @@ -232,4 +236,7 @@ function specObjectToModule(spec) {

function removeJsExt(path) {
return path.replace(/\.js$/, '');
}
}
});})(typeof define !== 'undefined' ? define : function(fac){module.exports = fac(require);});

}
6 changes: 4 additions & 2 deletions test/node/circular-refs-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(function(define){define(function(require){
(function(buster, when, timeout, wire, plugin) {
"use strict";

Expand Down Expand Up @@ -85,6 +86,7 @@ buster.testCase('circular-refs', {
require('buster'),
require('when'),
require('when/timeout'),
require('../..'),
require('../../wire'),
require('./fixtures/object')
);
);
});})(typeof define !== 'undefined' ? define : function(fac){module.exports = fac(require);});
4 changes: 3 additions & 1 deletion test/node/connect-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(function(define){define(function(require){
(function(buster, context, connectPlugin, when) {
'use strict';

Expand Down Expand Up @@ -183,4 +184,5 @@ buster.testCase('connect', {
require('../../lib/context'),
require('../../connect'),
require('when')
);
);
});})(typeof define !== 'undefined' ? define : function(fac){module.exports = fac(require);});
Loading

0 comments on commit a0cd7a2

Please sign in to comment.