Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): fix tests for new cucumber-js #2765

Merged
merged 1 commit into from
Aug 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -64,7 +64,7 @@ module.exports = function (grunt) {
src: 'test/e2e/*.feature'
},
options: {
tags: '~@not-jenkins'
tags: 'not @not-jenkins'
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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'
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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()
Expand All @@ -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) {
Expand Down Expand Up @@ -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

Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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 () {
Expand All @@ -216,12 +215,12 @@ 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)) {
return callback()
}
callback(new Error('Expected output to match the following:\n ' + expectedOutput + '\nGot:\n ' + data))
})
}
})
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -10,4 +12,4 @@ module.exports = function afterHooks () {
// stop the proxy if it was started
this.proxy.stop(callback)
})
}
})
8 changes: 4 additions & 4 deletions test/e2e/support/env.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var configure = function () {
this.setDefaultTimeout(60 * 1000)
}
var {defineSupportCode} = require('cucumber')

module.exports = configure
defineSupportCode(function ({setDefaultTimeout}) {
setDefaultTimeout(60 * 1000)
})
7 changes: 6 additions & 1 deletion test/e2e/support/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};')
Expand Down Expand Up @@ -61,3 +62,7 @@ exports.World = function World () {
stderr: ''
}
}

defineSupportCode(function ({setWorldConstructor}) {
setWorldConstructor(World)
})