diff --git a/CHANGELOG.md b/CHANGELOG.md index a0db50c..9af25a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## UNRELEASED + +- Fix #32: only merge "base" data in data/parallel mode if we aren't running "base" profile +- Fix #52: root data inclusion and override for plain JS config use case +- Fix #53: plugin configuration for plain JS config use case + ## 4.9.0 - adding a plain JS/JSON config option (see additional docs in README) diff --git a/lib/flow.js b/lib/flow.js index a826162..fd7c37a 100644 --- a/lib/flow.js +++ b/lib/flow.js @@ -13,6 +13,7 @@ const {getCommonPathStart} = require('common-path-start'); const profile = function profile(cb) { let base = this.config.get('profiles:base'); + base.plugins = this.config.get('plugins') || {}; let profiles = this.program.profile; profiles = profiles || 'base'; profiles = (profiles instanceof Array) ? profiles : [profiles]; @@ -29,7 +30,6 @@ const profile = function profile(cb) { // don't merge data objects here conf = merge({}, omit(base, 'data'), profileObj || {}); - // set baseConfigPath for use by the runner when nemo is instantiated again conf.baseConfigPath = this.config.get('baseConfigPath'); instance = { @@ -128,6 +128,7 @@ const pfile = function pfile(cb) { const pdata = function pdata(cb) { let instances = []; + let rootData = this.config.get('data') || {}; let baseData = this.config.get('profiles:base:data'); // let base = this.config.get('profiles:base'); @@ -143,9 +144,11 @@ const pdata = function pdata(cb) { for (let key in instanceData) { if (Object.prototype.hasOwnProperty.call(instanceData, key)) { let _instance; + // only merge "base" data if this isn't the "base" profile + let mergeData = (instance.tags.profile === 'base') ? {} : baseData; _instance = merge({}, instance); _instance.tags.key = key; - _instance.conf.data = merge({}, baseData, instanceData[key]); + _instance.conf.data = merge({}, rootData, mergeData, instanceData[key]); instances.push(_instance); log('child instance data is %j', _instance.conf.data); } @@ -154,7 +157,7 @@ const pdata = function pdata(cb) { log('child instance data is %j', instance.conf.data); log('child base data is %j', instance.conf.data); - instance.conf.data = merge({}, baseData, instance.conf.data || {}); + instance.conf.data = merge({}, rootData, baseData, instance.conf.data || {}); log('instance.conf.data is %j', instance.conf.data); instances.push(instance); diff --git a/lib/runner/mocha.js b/lib/runner/mocha.js index 87340b6..b987140 100644 --- a/lib/runner/mocha.js +++ b/lib/runner/mocha.js @@ -26,6 +26,7 @@ function MochaRunner(runnerConfig) { driverConf = Object.assign({}, instanceConfig.profile.conf.driver || {}); } let dataConf = Object.assign({}, instanceConfig.profile.conf.data || {}); + let pluginConf = Object.assign({}, instanceConfig.profile.conf.plugins || {}); let NemoBaseConfig; return NemoCore.Configure(instanceConfig.profile.conf.baseConfigPath) .then(function (nemoBaseConfig) { @@ -39,6 +40,7 @@ function MochaRunner(runnerConfig) { } // plain JS config use case return NemoCore.Configure({ + plugins: pluginConf, driver: driverConf, data: dataConf }); diff --git a/package.json b/package.json index 77d680f..0b3fee2 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "4.9.0", "description": "Wrapper to run mocha suites with injected selenium-webdriver instance", "scripts": { - "test": "npm run lint && node test/test-helper clean && npm run nemo && npm run nemo:parallel && npm run nemo:lifecycle:suite && npm run nemo:lifecycle:test && npm run nemo:jsconfig && node test/test-helper verify", + "test": "npm run lint && node test/test-helper clean && npm run nemo && npm run nemo:parallel && npm run nemo:lifecycle:suite && npm run nemo:lifecycle:test && npm run nemo:jsconfig && npm run nemo:env:override && node test/test-helper verify", "nemo": "SELENIUM_PROMISE_MANAGER=0 ./bin/nemo -B test", "nemo:jsconfig": "SELENIUM_PROMISE_MANAGER=0 ./bin/nemo -C test/jsconfig/nemo.config.js", "nemo:debug": "SELENIUM_PROMISE_MANAGER=0 ./bin/nemo -B test --inspect-brk --inspect", @@ -18,6 +18,7 @@ "nemo:lifecycle:test": "SELENIUM_PROMISE_MANAGER=0 ./bin/nemo -B test -P driverPerTest", "nemo:xunit": "./bin/nemo -B test -G @suite1 -P xunit", "nemo:customDriver": "./bin/nemo -B test -G @suite1 -P customDriver", + "nemo:env:override": "NODE_ENV=override ./bin/nemo -B test -P override", "nemo:server": "./bin/nemo -B test -S", "nemo:dynamic": "./bin/nemo -B test -U --url-from-cli 'https://www.wikipedia.org' -P dynamic", "nemo:scaffold": "./bin/nemo -B scaffold -P pay,search,form", diff --git a/test/config/config.json b/test/config/config.json index 1788e78..8529bf7 100644 --- a/test/config/config.json +++ b/test/config/config.json @@ -25,7 +25,8 @@ } }, "data": { - "baseUrl": "https://www.google.com" + "baseUrl": "https://www.google.com", + "foo": "bar" }, "output": { "listeners": "require:./config/listeners", @@ -119,17 +120,14 @@ } }, "chrome": { - "driver": { - "browser": "phantomjs" - //just pretending this is another browser :) - } + }, "firefox": { - "driver": { - "browser": "phantomjs" - //just pretending this is another browser :) - } + }, - "dynamic": "exec:./config/dynamic" + "dynamic": "exec:./config/dynamic", + "override": { + "tests": "path:./override.js" + } } } diff --git a/test/config/override.json b/test/config/override.json new file mode 100644 index 0000000..0dee883 --- /dev/null +++ b/test/config/override.json @@ -0,0 +1,5 @@ +{ + "data": { + "foo": "fighters" + } +} diff --git a/test/jsconfig/nemo.config.js b/test/jsconfig/nemo.config.js index c38d6b9..1bae503 100644 --- a/test/jsconfig/nemo.config.js +++ b/test/jsconfig/nemo.config.js @@ -1,9 +1,13 @@ const path = require('path'); module.exports = { + data: { + foo: 'bar' + }, plugins: { view: { - module: 'nemo-view' + module: 'nemo-view', + arguments: [path.join(__dirname, '../locator')] } }, output: { diff --git a/test/locator/google.json b/test/locator/google.json new file mode 100644 index 0000000..a261290 --- /dev/null +++ b/test/locator/google.json @@ -0,0 +1,4 @@ +{ + "text": "[type=text][name=q]", + "button": "[type=submit][name=btnK]" +} diff --git a/test/nested.js b/test/nested.js index 96edd59..ced109b 100644 --- a/test/nested.js +++ b/test/nested.js @@ -1,55 +1,58 @@ describe('@suite1@suite2@suite3@suite4@', function () { - before(function () { + before(async function () { if (this.nemo) { - return Promise.resolve(); + await Promise.resolve(); + return; } - return Promise.reject(new Error('no nemo')); + await Promise.reject(new Error('no nemo')); }); - after(function () { + after(async function () { if (this.nemo) { - return Promise.resolve(); + await Promise.resolve(); + return; } - return Promise.reject(new Error('no nemo')); + await Promise.reject(new Error('no nemo')); }); - beforeEach(function () { + beforeEach(async function () { if (this.nemo) { - return Promise.resolve(); + await Promise.resolve(); + return; } - return Promise.reject(new Error('no nemo')); + await Promise.reject(new Error('no nemo')); }); - afterEach(function () { + afterEach(async function () { if (this.nemo) { - return Promise.resolve(); + await Promise.resolve(); + return; } - return Promise.reject(new Error('no nemo')); + await Promise.reject(new Error('no nemo')); }); - it('may fail a few times1', function () { + it('may fail a few times1', async function () { let nemo = this.nemo; //verify nemo.mocha property if (!nemo.mocha === this) { - return Promise.reject(new Error('didnt find mocha context at nemo.mocha')); + await Promise.reject(new Error('didnt find mocha context at nemo.mocha')); + return; } - return nemo.driver.get(nemo.data.baseUrl) - .then(function () { - return nemo.snap(); - }) - .then(function () { - return nemo.snap(); - }) + await nemo.driver.get(nemo.data.baseUrl); + await nemo.snap(); + await nemo.snap(); }); describe('@inner@', function () { - before(function () { + before(async function () { if (this.nemo) { - return Promise.resolve(); + await Promise.resolve(); + return; } - return Promise.reject(new Error('no nemo')); + await Promise.reject(new Error('no nemo')); }); - after(function () { + after(async function () { if (this.nemo) { - return Promise.resolve(); + await Promise.resolve(); + return; } - return Promise.reject(new Error('no nemo')); + await Promise.reject(new Error('no nemo')); }); beforeEach(function () { if (this.nemo) { @@ -63,16 +66,26 @@ describe('@suite1@suite2@suite3@suite4@', function () { } return Promise.reject(new Error('no nemo')); }); - it('may fail a few times2', function () { + it('may fail a few times2', async function () { let nemo = this.nemo; //verify nemo.mocha property if (!nemo.mocha === this) { return Promise.reject(new Error('didnt find mocha context at nemo.mocha')); } - return nemo.driver.get(nemo.data.baseUrl) - .then(function () { - return nemo.driver.sleep(500); - }); + await nemo.driver.get(nemo.data.baseUrl); + await nemo.view.google.text().sendKeys('foo'); + await nemo.snap(); + await nemo.driver.sleep(500); + }); + it('merges top level data', async function () { + let nemo = this.nemo; + //verify nemo.mocha property + if (!nemo.data.foo) { + await Promise.reject(new Error('didnt find nemo.data.foo')); + return; + } + await Promise.resolve(); + }); }); diff --git a/test/override.js b/test/override.js new file mode 100644 index 0000000..9bb2c8d --- /dev/null +++ b/test/override.js @@ -0,0 +1,8 @@ +const assert = require('assert'); +describe('@override@', function () { + it('should override nemo.data.foo', async function () { + let nemo = this.nemo; + assert.equal(nemo.data.foo, 'fighters'); + await Promise.resolve(); + }); +}); diff --git a/test/test-helper.js b/test/test-helper.js index f606878..4fa75f8 100644 --- a/test/test-helper.js +++ b/test/test-helper.js @@ -16,23 +16,23 @@ if (process.argv[2] === 'clean') { else if (process.argv[2] === 'verify') { let assertions = [{ glob: '*/*/', - count: 5, + count: 6, description: 'master level run folders' }, { glob: '*/*/summary.json', - count: 5, + count: 6, description: 'instance level summary.json files' }, { glob: '*/*/*/', - count: 12, + count: 13, description: 'instance level run folders' }, { glob: '*/*/*/nemo-report*', - count: 24, + count: 26, description: 'instance level nemo-report* files' }, { glob: '*/*/*/*.png', - count: 12, + count: 18, description: 'screen capture png files' }]; assertions.forEach(assertion => {