Skip to content

Commit

Permalink
test(e2e): Add basic cucumber setup for better e2e testing.
Browse files Browse the repository at this point in the history
This allows end to end tests to be written using cucumber,
making it much easier to read and more robust.
  • Loading branch information
dignifiedquire committed Jan 4, 2015
1 parent 6d2e4a7 commit e21ac6a
Show file tree
Hide file tree
Showing 39 changed files with 424 additions and 849 deletions.
19 changes: 18 additions & 1 deletion Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = (grunt) ->
test:
unit: 'simplemocha:unit'
client: 'test/client/karma.conf.js'
e2e: ['test/e2e/*/karma.conf.js', 'test/e2e/*/karma.conf.coffee', 'test/e2e/*/karma.conf.ls']
e2e: 'cucumberjs:ci'

watch:
client:
Expand All @@ -46,6 +46,22 @@ module.exports = (grunt) ->
'test/unit/mocha-globals.coffee'
'test/unit/**/*.coffee'
]
cucumberjs:
options:
steps: 'test/e2e/steps'
format: 'progress'
all: 'test/e2e/*.feature'
current:
files:
src: 'test/e2e/*.feature'
options:
tags: '@current'
ci:
files:
src: 'test/e2e/*.feature'
options:
tags: '~@not-jenkins'


# JSHint options
# http://www.jshint.com/options/
Expand Down Expand Up @@ -132,6 +148,7 @@ module.exports = (grunt) ->


grunt.loadTasks 'tasks'

# Load grunt tasks automatically
require('load-grunt-tasks') grunt

Expand Down
66 changes: 35 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,46 +181,50 @@
"source-map": "~0.1.31"
},
"devDependencies": {
"LiveScript": "~1.2.0",
"chai": "~1.9.1",
"chai-as-promised": "~4.1.0",
"coffee-errors": "~0.8.6",
"coffee-script": "~1.7.1",
"cucumber": "^0.4.7",
"grunt": "~0.4",
"grunt-simple-mocha": "*",
"grunt-auto-release": "~0.0.3",
"grunt-browserify": "~2.1.3",
"grunt-bump": "~0.0.10",
"grunt-coffeelint": "~0.0.6",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-watch": "~0.6.1",
"grunt-coffeelint": "~0.0.6",
"grunt-npm": "~0.0.1",
"grunt-bump": "~0.0.10",
"grunt-conventional-changelog": "~1.1.0",
"grunt-auto-release": "~0.0.3",
"grunt-browserify": "~2.1.3",
"grunt-cucumberjs": "^0.5.0",
"grunt-jscs-checker": "~0.6.1",
"grunt-npm": "~0.0.1",
"grunt-simple-mocha": "*",
"karma-browserstack-launcher": "*",
"karma-chrome-launcher": "*",
"karma-coffee-preprocessor": "*",
"karma-commonjs": "*",
"karma-coverage": "*",
"karma-firefox-launcher": "*",
"karma-growl-reporter": "*",
"karma-html2js-preprocessor": "*",
"karma-jasmine": "~0.1.1",
"karma-junit-reporter": "*",
"karma-live-preprocessor": "*",
"karma-mocha": "*",
"karma-ng-scenario": "*",
"karma-phantomjs-launcher": "*",
"karma-qunit": "*",
"karma-requirejs": "*",
"karma-sauce-launcher": "*",
"karma-script-launcher": "^0.1.0",
"load-grunt-tasks": "~0.6.0",
"mocks": "~0.0.10",
"which": "~1.0",
"mkdirp": "~0.3.5",
"mocha": "~1.20.1",
"chai": "~1.9.1",
"chai-as-promised": "~4.1.0",
"mocks": "~0.0.10",
"sinon": "~1.10.3",
"sinon-chai": "~2.5.0",
"timer-shim": "~0.3.0",
"karma-jasmine": "~0.1.0",
"karma-mocha": "*",
"karma-qunit": "*",
"karma-coverage": "*",
"karma-requirejs": "*",
"karma-commonjs": "*",
"karma-growl-reporter": "*",
"karma-junit-reporter": "*",
"karma-chrome-launcher": "*",
"karma-firefox-launcher": "*",
"karma-sauce-launcher": "*",
"karma-phantomjs-launcher": "*",
"karma-ng-scenario": "*",
"karma-coffee-preprocessor": "*",
"karma-live-preprocessor": "*",
"karma-html2js-preprocessor": "*",
"karma-browserstack-launcher": "*",
"LiveScript": "~1.2.0",
"coffee-errors": "~0.8.6",
"coffee-script": "~1.7.1",
"grunt-jscs-checker": "~0.6.1"
"which": "~1.0"
},
"main": "./lib/index",
"bin": {},
Expand Down
83 changes: 0 additions & 83 deletions tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = function(grunt) {
* grunt test
* grunt test:unit
* grunt test:client
* grunt test:e2e
*/
grunt.registerMultiTask('test', 'Run tests.', function() {
var specDone = this.async();
Expand Down Expand Up @@ -37,88 +36,6 @@ module.exports = function(grunt) {
});
};


// E2E tests
if (this.target === 'e2e') {
var tests = grunt.file.expand(this.data);
var processToKill;
var args = [
'start', null, '--single-run', '--no-auto-watch'
];


var next = function(err, result, code) {
var testArgs = [];
if (processToKill) {
processToKill.kill();
}

if (err || code) {
console.error(err);
grunt.fail.fatal('E2E test "' + args[1] + '" failed.', code);
} else {
args[1] = tests.shift();
if (args[1]) {
if (args[1] === 'test/e2e/angular-scenario/karma.conf.js') {
processToKill = grunt.util.spawn({
cmd: node,
args: ['test/e2e/angular-scenario/server.js']
}, function() {});
}

if (args[1] === 'test/e2e/pass-opts/karma.conf.js') {
var serverArgs = args.slice();
serverArgs.splice(args.indexOf('--single-run'), 1);
var done = false;
var cont = function() {
if (!done) {
done = true;
next.apply(this, arguments);
}
};

processToKill = grunt.util.spawn({
cmd: node,
args: [cmd].concat(serverArgs),
opts: {stdio: [process.stdin, 'pipe', process.stderr]}
}, cont);

var onData = function(data) {
data = data.toString();
// wait for the browser to connect
if (/Connected on socket/.test(data)) {
processToKill.stdout.removeListener('data', onData);
spawnKarma(['run', '--','arg1','arg2','arg3'], cont);
} else {
console.log(data);
}
};

processToKill.stdout.on('data', onData);
} else {
spawnKarma(args.concat(testArgs), next);
}
} else {
specDone();
}
}
};


// run only e2e tests specified by args
if (arguments.length) {
var slicedArgs = Array.prototype.slice.call(arguments);

tests = tests.filter(function(configFile) {
return slicedArgs.some(function(test) {
return configFile.indexOf(test) !== -1;
});
});
}

return next();
}

// CLIENT unit tests
if (this.target === 'client') {
return exec(['start', this.data, '--single-run', '--no-auto-watch', '--reporters=dots'],
Expand Down
Loading

0 comments on commit e21ac6a

Please sign in to comment.