Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit 1f62e4b

Browse files
committed
Testify against the machine !
1 parent fb6a061 commit 1f62e4b

13 files changed

+1143
-2
lines changed

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
---
2+
git:
3+
depth: 1
24
language: node_js
35
node_js:
46
- 0.10
57
- 0.11
8+
before_install:
9+
- export CHROME_BIN=chromium-browser
10+
- export DISPLAY=:99.0
11+
- sh -e /etc/init.d/xvfb start
12+
- npm update -g
13+
- npm install -g karma-cli grunt-cli
14+
script:
15+
- grunt
16+
- npm test
17+
- npm run test:browsers -- --polyfill
18+
19+
after_script:
20+
- npm run test:browsers -- --saucelabs
21+
- npm run test:browsers -- --saucelabs --ie8
22+
- npm run test:browsers:perf

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,27 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.
112112

113113
_Also, please don't edit files in the "dist" subdirectory as they are generated via grunt. You'll find source code in the "lib" subdirectory!_
114114

115+
## Testing
116+
117+
- `npm run test:node` will use node to to run the tests
118+
- `npm run test:browsers` will use karma to run the tests
119+
- `npm run test:browsers:perf` will use karma to run benchmarks
120+
- `npm test` run `npm run test:node && npm run test:browsers`
121+
122+
`npm run test:browsers` supports options after a double dash (`--`) :
123+
124+
- You can use the `--polyfill` option to test ths code with polyfill.
125+
126+
- You can use the `--ie8` option to test ths code in the ie8 scope only.
127+
128+
- You can use the `--saucelabs` option to use karma and saucelabs to run the tests in various browsers.
129+
Note: you will need to export your username and key to launch it.
130+
131+
```sh
132+
export SAUCE_USERNAME={your user name} && export SAUCE_ACCESS_KEY={the access key that you see once logged in}
133+
npm run test:browsers -- --saucelabs
134+
```
135+
115136
## Credit
116137
Copyright (c) 2014 Luke Hoban, Addy Osmani, Guy Bedford
117138

karma-benchmark.conf.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = function (config) {
2+
3+
config.set({
4+
basePath: '',
5+
frameworks: ['benchmark'],
6+
files: [
7+
'dist/es6-module-loader.src.js',
8+
'test/perf.js'
9+
],
10+
reporters: ['benchmark'],
11+
browsers: ['Chrome', 'Firefox'],
12+
13+
browserDisconnectTimeout: 10000,
14+
browserDisconnectTolerance: 2,
15+
browserNoActivityTimeout: 30000,
16+
captureTimeout: 120000
17+
});
18+
19+
if(process.env.TRAVIS){
20+
config.set({
21+
customLaunchers: {
22+
'TR_Chrome': {
23+
base: 'Chrome',
24+
flags: ['--no-sandbox']
25+
}
26+
},
27+
browsers: ['TR_Chrome', 'Firefox']
28+
});
29+
}
30+
31+
};

karma.conf.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
'use strict';
2+
3+
var util = require('util');
4+
var pkg = require('./package.json');
5+
var extend = util._extend;
6+
var geSaLaKaCuLa = require('gesalakacula');
7+
8+
// No Karma options are passed after the double dash option (`--`)
9+
// Example : karma start --single-run -- --polyfill
10+
// >> { _: [], polyfill: true }
11+
12+
var _argv = process.argv;
13+
var argv = require('minimist')(_argv.slice(_argv.indexOf('--') + 1));
14+
15+
16+
var options = extend({
17+
travis: process.env.TRAVIS,
18+
polyfill: false,
19+
saucelabs: false,
20+
ie8: false
21+
}, argv);
22+
23+
if (options.ie8){
24+
console.log('IE8 Mode !\n - polyfill required\n');
25+
options.polyfill = true;
26+
}
27+
28+
////
29+
30+
module.exports = function (config) {
31+
32+
var files = [
33+
'test/_helper.js',
34+
[!options.ie8 ? 'node_modules/traceur/bin/traceur.js' : ''],
35+
36+
'dist/es6-module-loader' +
37+
(options.polyfill ? '' : '-sans-promises')
38+
+ '.src.js',
39+
40+
'test/_browser.js',
41+
'test/custom-loader.js',
42+
43+
[!options.ie8 ? 'test/*.spec.js' : 'test/*.normalize.spec.js'],
44+
45+
{pattern: 'test/{loader,loads,syntax,worker}/**/*', included: false},
46+
{pattern: 'node_modules/when/es6-shim/Promise.js', included: false},
47+
{pattern: 'dist/es6-module-loader.js', included: false}
48+
];
49+
50+
// Default Config
51+
config.set({
52+
basePath: '',
53+
frameworks: ['mocha', 'expect'],
54+
files: flatten(files),
55+
reporters: ['mocha'],
56+
browsers: ['Chrome', 'Firefox']
57+
});
58+
59+
if (options.travis) {
60+
// TRAVIS config overwrite
61+
config.set({
62+
singleRun: true,
63+
reporters: ['dots'],
64+
customLaunchers: {
65+
'TR_Chrome': {
66+
base: 'Chrome',
67+
flags: ['--no-sandbox']
68+
}
69+
},
70+
browsers: ['TR_Chrome', 'Firefox']
71+
});
72+
}
73+
74+
if (options.saucelabs) {
75+
76+
var customLaunchers = geSaLaKaCuLa({
77+
'Windows 7': {
78+
'internet explorer': '9..11'
79+
}
80+
});
81+
82+
if (options.ie8) {
83+
customLaunchers = geSaLaKaCuLa({
84+
'Windows 7': {
85+
'internet explorer': '8'
86+
}
87+
});
88+
}
89+
90+
var now = new Date();
91+
var buildData = options.travis ?
92+
{
93+
location: 'TRAVIS',
94+
name: process.env.TRAVIS_BUILD_NUMBER,
95+
id: process.env.TRAVIS_BUILD_ID
96+
}
97+
:
98+
{
99+
location: 'LOCAL',
100+
name: now.toString(),
101+
id: +now
102+
};
103+
var build = util.format('%s #%s (%s)',
104+
buildData.location, buildData.name, buildData.id);
105+
106+
console.log('SauceLabs Run\n- Build : ' + build + '\n');
107+
108+
config.set({
109+
reporters: ['dots', 'saucelabs'],
110+
111+
browserDisconnectTimeout: 10000,
112+
browserDisconnectTolerance: 2,
113+
browserNoActivityTimeout: 30000,
114+
captureTimeout: 120000,
115+
116+
browsers: Object.keys(customLaunchers),
117+
sauceLabs: {
118+
testName: pkg.name,
119+
recordScreenshots: false,
120+
build: build,
121+
tunnelIdentifier: options.travis ?
122+
process.env.TRAVIS_JOB_NUMBER : Math.floor(Math.random() * 1000)
123+
},
124+
customLaunchers: customLaunchers
125+
});
126+
127+
128+
}
129+
};
130+
131+
function flatten(arr) {
132+
return arr.reduce(function (memo, val) {
133+
return memo.concat(util.isArray(val) ? flatten(val) : val ? [val] : []);
134+
}, []);
135+
}

package.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,25 @@
2222
}
2323
],
2424
"devDependencies": {
25+
"expect.js": "^0.3.1",
26+
"gesalakacula": "^1.0.0",
2527
"grunt": "~0.4.1",
2628
"grunt-contrib-concat": "^0.5.0",
2729
"grunt-contrib-jshint": "~0.6.0",
2830
"grunt-contrib-uglify": "~0.6.0",
2931
"grunt-esnext": "0.0.3",
30-
"grunt-string-replace": "^0.2.7"
32+
"grunt-string-replace": "^0.2.7",
33+
"karma": "^0.12.28",
34+
"karma-benchmark": "^0.4.0",
35+
"karma-benchmark-reporter": "^0.1.1",
36+
"karma-chrome-launcher": "^0.1.7",
37+
"karma-expect": "^1.1.0",
38+
"karma-firefox-launcher": "^0.1.3",
39+
"karma-mocha": "^0.1.10",
40+
"karma-mocha-reporter": "^0.3.1",
41+
"karma-sauce-launcher": "^0.2.10",
42+
"minimist": "^1.1.0",
43+
"mocha": "^2.0.1"
3144
},
3245
"keywords": [
3346
"script",
@@ -40,7 +53,10 @@
4053
},
4154
"main": "lib/index",
4255
"scripts": {
43-
"test": "cd test && node test"
56+
"test": "npm run test:node && npm run test:browsers",
57+
"test:node": "mocha test/_node.js",
58+
"test:browsers": "karma start --single-run",
59+
"test:browsers:perf": "karma start karma-benchmark.conf.js --single-run"
4460
},
4561
"dependencies": {
4662
"traceur": "0.0.79",

test/_browser.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
// Change base url to the karma "base"
3+
System.baseURL += 'base/';

test/_helper.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
3+
(function (__global){
4+
'use strict';
5+
6+
/**
7+
* Describe a block if the bool is true.
8+
* Will skip it otherwise.
9+
* @param bool
10+
* @returns {Function} describe or describe.skip
11+
*/
12+
function describeIf(bool) {
13+
return (bool ? describe : describe.skip)
14+
.apply(null, Array.prototype.slice.call(arguments, 1));
15+
}
16+
17+
__global.describeIf = describeIf;
18+
19+
}(typeof window != 'undefined' ? window : global));
20+
21+

test/_node.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
global.expect = require('expect.js');
4+
5+
require('./_helper');
6+
7+
require('../lib');
8+
9+
require('./system.spec');
10+
11+
require('./custom-loader');
12+
require('./custom-loader.spec');

0 commit comments

Comments
 (0)