From 255bf6744c2c019aad7f9c095f8da1d9d7fc5d27 Mon Sep 17 00:00:00 2001 From: Yaroslav Admin Date: Thu, 30 Apr 2020 01:54:54 +0200 Subject: [PATCH] refactor(test): migrate World to ES2015 (#3489) --- test/e2e/support/world.js | 78 +++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/test/e2e/support/world.js b/test/e2e/support/world.js index 6f82c9a41..b2f30700d 100644 --- a/test/e2e/support/world.js +++ b/test/e2e/support/world.js @@ -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({ @@ -58,12 +60,6 @@ function World () { })) }) } - - this.lastRun = { - error: null, - stdout: '', - stderr: '' - } } setWorldConstructor(World)