Skip to content

Commit 255bf67

Browse files
authored
refactor(test): migrate World to ES2015 (#3489)
1 parent be5db67 commit 255bf67

File tree

1 file changed

+37
-41
lines changed

1 file changed

+37
-41
lines changed

test/e2e/support/world.js

+37-41
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,52 @@ const mkdirp = require('mkdirp')
66
const _ = require('lodash')
77
const { setWorldConstructor } = require('cucumber')
88

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

13-
this.configFile = {
14-
singleRun: true,
15-
reporters: ['dots'],
16-
frameworks: ['jasmine'],
17-
basePath: __dirname,
18-
colors: false,
19-
__dirname: __dirname,
20-
_resolve: function (name) {
21-
return path.resolve(__dirname, '..', 'support', name)
14+
this.configFile = {
15+
singleRun: true,
16+
reporters: ['dots'],
17+
frameworks: ['jasmine'],
18+
basePath: __dirname,
19+
colors: false,
20+
__dirname: __dirname,
21+
_resolve: (name) => path.resolve(__dirname, '..', 'support', name)
22+
}
23+
24+
this.lastRun = {
25+
error: null,
26+
stdout: '',
27+
stderr: ''
2228
}
2329
}
2430

25-
this.addConfigContent = (function (_this) {
26-
return function (content) {
27-
if (content == null) {
28-
content = ''
29-
}
30-
return vm.runInNewContext(content, _this.configFile)
31+
addConfigContent (content) {
32+
if (content == null) {
33+
content = ''
3134
}
32-
})(this)
35+
return vm.runInNewContext(content, this.configFile)
36+
}
3337

34-
this.writeConfigFile = (function (_this) {
35-
return function (dir, file, done) {
36-
return mkdirp(dir, 0x1ed, function (err) {
37-
let content, hash
38-
if (err) {
39-
return done(err)
40-
}
38+
writeConfigFile (dir, file, done) {
39+
return mkdirp(dir, 0x1ed, (err) => {
40+
let content, hash
41+
if (err) {
42+
return done(err)
43+
}
4144

42-
delete _this.configFile.__dirname
43-
content = _this.generateJS(_this.configFile)
44-
hash = hasher('md5').update(content + Math.random()).digest('hex')
45-
fs.writeFile(path.join(dir, hash + '.' + file), content, function (err) {
46-
done(err, hash)
47-
})
45+
delete this.configFile.__dirname
46+
content = this.generateJS(this.configFile)
47+
hash = hasher('md5').update(content + Math.random()).digest('hex')
48+
fs.writeFile(path.join(dir, hash + '.' + file), content, (err) => {
49+
done(err, hash)
4850
})
49-
}
50-
})(this)
51+
})
52+
}
5153

52-
this.generateJS = function (config) {
54+
generateJS (config) {
5355
return this.template({
5456
content: JSON.stringify(Object.assign({}, config, {
5557
customLaunchers: Object.assign({
@@ -58,12 +60,6 @@ function World () {
5860
}))
5961
})
6062
}
61-
62-
this.lastRun = {
63-
error: null,
64-
stdout: '',
65-
stderr: ''
66-
}
6763
}
6864

6965
setWorldConstructor(World)

0 commit comments

Comments
 (0)