Skip to content

Commit

Permalink
fixing issues #52 and #53
Browse files Browse the repository at this point in the history
  • Loading branch information
grawk committed Dec 10, 2018
1 parent 14100de commit aeff82e
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 52 deletions.
7 changes: 4 additions & 3 deletions lib/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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 = {
Expand Down Expand Up @@ -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');

Expand All @@ -147,7 +148,7 @@ const pdata = function pdata(cb) {
let mergeData = (instance.tags.profile === 'base') ? {} : baseData;
_instance = merge({}, instance);
_instance.tags.key = key;
_instance.conf.data = merge({}, mergeData, instanceData[key]);
_instance.conf.data = merge({}, rootData, mergeData, instanceData[key]);
instances.push(_instance);
log('child instance data is %j', _instance.conf.data);
}
Expand All @@ -156,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);
Expand Down
2 changes: 2 additions & 0 deletions lib/runner/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -39,6 +40,7 @@ function MochaRunner(runnerConfig) {
}
// plain JS config use case
return NemoCore.Configure({
plugins: pluginConf,
driver: driverConf,
data: dataConf
});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
18 changes: 8 additions & 10 deletions test/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
}
},
"data": {
"baseUrl": "https://www.google.com"
"baseUrl": "https://www.google.com",
"foo": "bar"
},
"output": {
"listeners": "require:./config/listeners",
Expand Down Expand Up @@ -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"
}
}
}
5 changes: 5 additions & 0 deletions test/config/override.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"data": {
"foo": "fighters"
}
}
6 changes: 5 additions & 1 deletion test/jsconfig/nemo.config.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
4 changes: 4 additions & 0 deletions test/locator/google.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"text": "[type=text][name=q]",
"button": "[type=submit][name=btnK]"
}
77 changes: 45 additions & 32 deletions test/nested.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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();

});
});

Expand Down
8 changes: 8 additions & 0 deletions test/override.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
10 changes: 5 additions & 5 deletions test/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit aeff82e

Please sign in to comment.