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

refactor(test): migrate World to ES2015 #3489

Merged
merged 1 commit into from
Apr 29, 2020
Merged
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
78 changes: 37 additions & 41 deletions test/e2e/support/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,52 @@ const mkdirp = require('mkdirp')
const _ = require('lodash')
const { setWorldConstructor } = require('cucumber')

function World () {
this.proxy = require('./proxy')
this.template = _.template(`process.env.CHROME_BIN = require('puppeteer').executablePath(); module.exports = function (config) {\n config.set(\n <%= content %>\n );\n};`)
class World {
constructor () {
this.proxy = require('./proxy')
this.template = _.template(`process.env.CHROME_BIN = require('puppeteer').executablePath(); module.exports = function (config) {\n config.set(\n <%= content %>\n );\n};`)

this.configFile = {
singleRun: true,
reporters: ['dots'],
frameworks: ['jasmine'],
basePath: __dirname,
colors: false,
__dirname: __dirname,
_resolve: function (name) {
return path.resolve(__dirname, '..', 'support', name)
this.configFile = {
singleRun: true,
reporters: ['dots'],
frameworks: ['jasmine'],
basePath: __dirname,
colors: false,
__dirname: __dirname,
_resolve: (name) => path.resolve(__dirname, '..', 'support', name)
}

this.lastRun = {
error: null,
stdout: '',
stderr: ''
}
}

this.addConfigContent = (function (_this) {
return function (content) {
if (content == null) {
content = ''
}
return vm.runInNewContext(content, _this.configFile)
addConfigContent (content) {
if (content == null) {
content = ''
}
})(this)
return vm.runInNewContext(content, this.configFile)
}

this.writeConfigFile = (function (_this) {
return function (dir, file, done) {
return mkdirp(dir, 0x1ed, function (err) {
let content, hash
if (err) {
return done(err)
}
writeConfigFile (dir, file, done) {
return mkdirp(dir, 0x1ed, (err) => {
let content, hash
if (err) {
return done(err)
}

delete _this.configFile.__dirname
content = _this.generateJS(_this.configFile)
hash = hasher('md5').update(content + Math.random()).digest('hex')
fs.writeFile(path.join(dir, hash + '.' + file), content, function (err) {
done(err, hash)
})
delete this.configFile.__dirname
content = this.generateJS(this.configFile)
hash = hasher('md5').update(content + Math.random()).digest('hex')
fs.writeFile(path.join(dir, hash + '.' + file), content, (err) => {
done(err, hash)
})
}
})(this)
})
}

this.generateJS = function (config) {
generateJS (config) {
return this.template({
content: JSON.stringify(Object.assign({}, config, {
customLaunchers: Object.assign({
Expand All @@ -58,12 +60,6 @@ function World () {
}))
})
}

this.lastRun = {
error: null,
stdout: '',
stderr: ''
}
}

setWorldConstructor(World)