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

Commit

Permalink
Testify against the machine !
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Jan 23, 2015
1 parent fb6a061 commit 1f62e4b
Show file tree
Hide file tree
Showing 13 changed files with 1,143 additions and 2 deletions.
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
---
git:
depth: 1
language: node_js
node_js:
- 0.10
- 0.11
before_install:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- npm update -g
- npm install -g karma-cli grunt-cli
script:
- grunt
- npm test
- npm run test:browsers -- --polyfill

after_script:
- npm run test:browsers -- --saucelabs
- npm run test:browsers -- --saucelabs --ie8
- npm run test:browsers:perf
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.

_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!_

## Testing

- `npm run test:node` will use node to to run the tests
- `npm run test:browsers` will use karma to run the tests
- `npm run test:browsers:perf` will use karma to run benchmarks
- `npm test` run `npm run test:node && npm run test:browsers`

`npm run test:browsers` supports options after a double dash (`--`) :

- You can use the `--polyfill` option to test ths code with polyfill.

- You can use the `--ie8` option to test ths code in the ie8 scope only.

- You can use the `--saucelabs` option to use karma and saucelabs to run the tests in various browsers.
Note: you will need to export your username and key to launch it.

```sh
export SAUCE_USERNAME={your user name} && export SAUCE_ACCESS_KEY={the access key that you see once logged in}
npm run test:browsers -- --saucelabs
```

## Credit
Copyright (c) 2014 Luke Hoban, Addy Osmani, Guy Bedford

Expand Down
31 changes: 31 additions & 0 deletions karma-benchmark.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = function (config) {

config.set({
basePath: '',
frameworks: ['benchmark'],
files: [
'dist/es6-module-loader.src.js',
'test/perf.js'
],
reporters: ['benchmark'],
browsers: ['Chrome', 'Firefox'],

browserDisconnectTimeout: 10000,
browserDisconnectTolerance: 2,
browserNoActivityTimeout: 30000,
captureTimeout: 120000
});

if(process.env.TRAVIS){
config.set({
customLaunchers: {
'TR_Chrome': {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
browsers: ['TR_Chrome', 'Firefox']
});
}

};
135 changes: 135 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
'use strict';

var util = require('util');
var pkg = require('./package.json');
var extend = util._extend;
var geSaLaKaCuLa = require('gesalakacula');

// No Karma options are passed after the double dash option (`--`)
// Example : karma start --single-run -- --polyfill
// >> { _: [], polyfill: true }

var _argv = process.argv;
var argv = require('minimist')(_argv.slice(_argv.indexOf('--') + 1));


var options = extend({
travis: process.env.TRAVIS,
polyfill: false,
saucelabs: false,
ie8: false
}, argv);

if (options.ie8){
console.log('IE8 Mode !\n - polyfill required\n');
options.polyfill = true;
}

////

module.exports = function (config) {

var files = [
'test/_helper.js',
[!options.ie8 ? 'node_modules/traceur/bin/traceur.js' : ''],

'dist/es6-module-loader' +
(options.polyfill ? '' : '-sans-promises')
+ '.src.js',

'test/_browser.js',
'test/custom-loader.js',

[!options.ie8 ? 'test/*.spec.js' : 'test/*.normalize.spec.js'],

{pattern: 'test/{loader,loads,syntax,worker}/**/*', included: false},
{pattern: 'node_modules/when/es6-shim/Promise.js', included: false},
{pattern: 'dist/es6-module-loader.js', included: false}
];

// Default Config
config.set({
basePath: '',
frameworks: ['mocha', 'expect'],
files: flatten(files),
reporters: ['mocha'],
browsers: ['Chrome', 'Firefox']
});

if (options.travis) {
// TRAVIS config overwrite
config.set({
singleRun: true,
reporters: ['dots'],
customLaunchers: {
'TR_Chrome': {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
browsers: ['TR_Chrome', 'Firefox']
});
}

if (options.saucelabs) {

var customLaunchers = geSaLaKaCuLa({
'Windows 7': {
'internet explorer': '9..11'
}
});

if (options.ie8) {
customLaunchers = geSaLaKaCuLa({
'Windows 7': {
'internet explorer': '8'
}
});
}

var now = new Date();
var buildData = options.travis ?
{
location: 'TRAVIS',
name: process.env.TRAVIS_BUILD_NUMBER,
id: process.env.TRAVIS_BUILD_ID
}
:
{
location: 'LOCAL',
name: now.toString(),
id: +now
};
var build = util.format('%s #%s (%s)',
buildData.location, buildData.name, buildData.id);

console.log('SauceLabs Run\n- Build : ' + build + '\n');

config.set({
reporters: ['dots', 'saucelabs'],

browserDisconnectTimeout: 10000,
browserDisconnectTolerance: 2,
browserNoActivityTimeout: 30000,
captureTimeout: 120000,

browsers: Object.keys(customLaunchers),
sauceLabs: {
testName: pkg.name,
recordScreenshots: false,
build: build,
tunnelIdentifier: options.travis ?
process.env.TRAVIS_JOB_NUMBER : Math.floor(Math.random() * 1000)
},
customLaunchers: customLaunchers
});


}
};

function flatten(arr) {
return arr.reduce(function (memo, val) {
return memo.concat(util.isArray(val) ? flatten(val) : val ? [val] : []);
}, []);
}
20 changes: 18 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,25 @@
}
],
"devDependencies": {
"expect.js": "^0.3.1",
"gesalakacula": "^1.0.0",
"grunt": "~0.4.1",
"grunt-contrib-concat": "^0.5.0",
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-uglify": "~0.6.0",
"grunt-esnext": "0.0.3",
"grunt-string-replace": "^0.2.7"
"grunt-string-replace": "^0.2.7",
"karma": "^0.12.28",
"karma-benchmark": "^0.4.0",
"karma-benchmark-reporter": "^0.1.1",
"karma-chrome-launcher": "^0.1.7",
"karma-expect": "^1.1.0",
"karma-firefox-launcher": "^0.1.3",
"karma-mocha": "^0.1.10",
"karma-mocha-reporter": "^0.3.1",
"karma-sauce-launcher": "^0.2.10",
"minimist": "^1.1.0",
"mocha": "^2.0.1"
},
"keywords": [
"script",
Expand All @@ -40,7 +53,10 @@
},
"main": "lib/index",
"scripts": {
"test": "cd test && node test"
"test": "npm run test:node && npm run test:browsers",
"test:node": "mocha test/_node.js",
"test:browsers": "karma start --single-run",
"test:browsers:perf": "karma start karma-benchmark.conf.js --single-run"
},
"dependencies": {
"traceur": "0.0.79",
Expand Down
3 changes: 3 additions & 0 deletions test/_browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

// Change base url to the karma "base"
System.baseURL += 'base/';
21 changes: 21 additions & 0 deletions test/_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@


(function (__global){
'use strict';

/**
* Describe a block if the bool is true.
* Will skip it otherwise.
* @param bool
* @returns {Function} describe or describe.skip
*/
function describeIf(bool) {
return (bool ? describe : describe.skip)
.apply(null, Array.prototype.slice.call(arguments, 1));
}

__global.describeIf = describeIf;

}(typeof window != 'undefined' ? window : global));


12 changes: 12 additions & 0 deletions test/_node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

global.expect = require('expect.js');

require('./_helper');

require('../lib');

require('./system.spec');

require('./custom-loader');
require('./custom-loader.spec');
Loading

0 comments on commit 1f62e4b

Please # to comment.