diff --git a/gruntfile.js b/gruntfile.js index 8c8c4541f..e92844ff4 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -46,9 +46,9 @@ module.exports = function (grunt) { }, cucumberjs: { options: { - steps: 'test/e2e/steps', + steps: 'test/e2e/step_definitions', format: 'progress', - require: 'test/e2e/support/env.js' + require: ['test/e2e/support/env.js', 'test/e2e/support/world.js'] }, all: 'test/e2e/*.feature', current: { @@ -64,7 +64,7 @@ module.exports = function (grunt) { src: 'test/e2e/*.feature' }, options: { - tags: '~@not-jenkins' + tags: 'not @not-jenkins' } } }, diff --git a/test/e2e/steps/core_steps.js b/test/e2e/step_definitions/core_steps.js similarity index 83% rename from test/e2e/steps/core_steps.js rename to test/e2e/step_definitions/core_steps.js index 9b4c1fc7a..96e7e8b00 100644 --- a/test/e2e/steps/core_steps.js +++ b/test/e2e/step_definitions/core_steps.js @@ -1,4 +1,6 @@ -module.exports = function coreSteps () { +var {defineSupportCode} = require('cucumber') + +defineSupportCode(function ({defineParameterType, Given, Then, When}) { var fs = require('fs') var path = require('path') var ref = require('child_process') @@ -7,9 +9,6 @@ module.exports = function coreSteps () { var rimraf = require('rimraf') var stopper = require('../../../lib/stopper') - this.World = require('../support/world').World - require('../support/after_hooks').call(this) - var baseDir = fs.realpathSync(path.join(__dirname, '/../../..')) var tmpDir = path.join(baseDir, 'tmp', 'sandbox') var tmpConfigFile = 'karma.conf.js' @@ -29,18 +28,18 @@ module.exports = function coreSteps () { } } - this.Given(/^a configuration with:$/, function (fileContent, callback) { + Given('a configuration with:', function (fileContent, callback) { cleanseIfNeeded() this.addConfigContent(fileContent) return callback() }) - this.Given(/^command line arguments of: "([^"]*)"$/, function (args, callback) { + Given('command line arguments of: {stringInDoubleQuotes}', function (args, callback) { additionalArgs = args return callback() }) - this.When(/^I stop a server programmatically/, function (callback) { + When('I stop a server programmatically', function (callback) { var _this = this setTimeout(function () { stopper.stop(_this.configFile, function (exitCode) { @@ -50,7 +49,7 @@ module.exports = function coreSteps () { }, 1000) }) - this.When(/^I start a server in background/, function (callback) { + When('I start a server in background', function (callback) { this.writeConfigFile(tmpDir, tmpConfigFile, (function (_this) { return function (err, hash) { if (err) { @@ -71,9 +70,9 @@ module.exports = function coreSteps () { })(this)) }) - this.When(/^I (run|runOut|start|init|stop) Karma( with log-level ([a-z]+))?( behind a proxy on port ([0-9]*) that prepends '([^']*)' to the base path)?$/, function (command, withLogLevel, level, behindProxy, proxyPort, proxyPath, callback) { + When("I {run|runOut|start|init|stop} Karma( with log-level {string})( behind a proxy on port {int} that prepends '{string}' to the base path)", function (command, level, proxyPort, proxyPath, callback) { var startProxy = function (done) { - if (behindProxy) { + if (proxyPort) { this.proxy.start(proxyPort, proxyPath, done) } else { done() @@ -88,7 +87,7 @@ module.exports = function coreSteps () { if (err) { return callback.fail(new Error(err)) } - level = withLogLevel === undefined ? 'warn' : level + level = level || 'warn' var configFile = path.join(tmpDir, hash + '.' + tmpConfigFile) var runtimePath = path.join(baseDir, 'bin', 'karma') var execKarma = function (done) { @@ -150,9 +149,9 @@ module.exports = function coreSteps () { })(this)) }) - this.Then(/^it passes with( no debug| like)?:$/, {timeout: 10 * 1000}, function (mode, expectedOutput, callback) { - var noDebug = mode === ' no debug' - var like = mode === ' like' + Then('it passes with( {no debug|like}):', {timeout: 10 * 1000}, function (mode, expectedOutput, callback) { + var noDebug = mode === 'no debug' + var like = mode === 'like' var actualOutput = this.lastRun.stdout.toString() var lines @@ -177,7 +176,7 @@ module.exports = function coreSteps () { callback(new Error('Failed all comparissons')) }) - this.Then(/^it fails with:$/, function (expectedOutput, callback) { + Then('it fails with:', function (expectedOutput, callback) { var actualOutput = this.lastRun.stdout.toString() var actualError = this.lastRun.error var actualStderr = this.lastRun.stderr.toString() @@ -191,7 +190,7 @@ module.exports = function coreSteps () { } }) - this.Then(/^it fails with like:$/, function (expectedOutput, callback) { + Then('it fails with like:', function (expectedOutput, callback) { var actualOutput = this.lastRun.stdout.toString() var actualError = this.lastRun.error var actualStderr = this.lastRun.stderr.toString() @@ -204,8 +203,8 @@ module.exports = function coreSteps () { } }) - this.Then(/^The (server|stopper) is dead( with exit code ([0-9]+))?$/, - function (stopperOrServer, withExitCode, code, callback) { + Then('The {server|stopper} is dead( with exit code {int})', + function (stopperOrServer, code, callback) { var server = stopperOrServer === 'server' var _this = this setTimeout(function () { @@ -216,7 +215,7 @@ module.exports = function coreSteps () { }, 4000) }) - this.Then(/^the file at (.+) contains:$/, + Then('the file at {string} contains:', function (filePath, expectedOutput, callback) { var data = fs.readFileSync(filePath, {encoding: 'UTF-8'}) if (data.match(expectedOutput)) { @@ -224,4 +223,4 @@ module.exports = function coreSteps () { } callback(new Error('Expected output to match the following:\n ' + expectedOutput + '\nGot:\n ' + data)) }) -} +}) diff --git a/test/e2e/support/after_hooks.js b/test/e2e/step_definitions/hooks.js similarity index 63% rename from test/e2e/support/after_hooks.js rename to test/e2e/step_definitions/hooks.js index 155f2cb4e..9be4aa5ce 100644 --- a/test/e2e/support/after_hooks.js +++ b/test/e2e/step_definitions/hooks.js @@ -1,5 +1,7 @@ -module.exports = function afterHooks () { - this.After(function (scenario, callback) { +var {defineSupportCode} = require('cucumber') + +defineSupportCode(function ({After}) { + After(function (scenario, callback) { var running = this.child != null && typeof this.child.kill === 'function' if (running) { @@ -10,4 +12,4 @@ module.exports = function afterHooks () { // stop the proxy if it was started this.proxy.stop(callback) }) -} +}) diff --git a/test/e2e/support/env.js b/test/e2e/support/env.js index 8eb4a74c6..e58cd18c9 100644 --- a/test/e2e/support/env.js +++ b/test/e2e/support/env.js @@ -1,5 +1,5 @@ -var configure = function () { - this.setDefaultTimeout(60 * 1000) -} +var {defineSupportCode} = require('cucumber') -module.exports = configure +defineSupportCode(function ({setDefaultTimeout}) { + setDefaultTimeout(60 * 1000) +}) diff --git a/test/e2e/support/world.js b/test/e2e/support/world.js index 7a2d02e3f..584b3bbd7 100644 --- a/test/e2e/support/world.js +++ b/test/e2e/support/world.js @@ -4,8 +4,9 @@ var path = require('path') var hasher = require('crypto').createHash var mkdirp = require('mkdirp') var _ = require('lodash') +var {defineSupportCode} = require('cucumber') -exports.World = function World () { +function World () { this.proxy = require('./proxy') this.template = _.template('module.exports = function (config) {\n config.set(\n <%= content %>\n );\n};') @@ -61,3 +62,7 @@ exports.World = function World () { stderr: '' } } + +defineSupportCode(function ({setWorldConstructor}) { + setWorldConstructor(World) +})