Skip to content

Commit

Permalink
allow unknown command line arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Noyabronok authored and Alex Feldman committed Apr 23, 2018
1 parent 2de5dd4 commit df73386
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
.idea
test/report
scaffold/report
.DS_Store
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ $ ./bin/nemo --help
-S, --server run the nemo web server
-L, --logging info level logging (errors log by default)
-X, --scaffold <path> inject an example nemo suite under <path>
-U, --allow-unknown-args allow command line arguments not specified by Nemo
--debug-brk enable node's debugger breaking on the first line
--inspect activate devtools in chrome
--no-timeouts remove timeouts in debug/inspect use case
Expand Down Expand Up @@ -268,3 +269,15 @@ You should add this to the `"mocha"` property within `"profiles"` of `config.jso
```
`nemo` creates `mocha` instances programmatically. Unfortunately, not all `mocha` command line options are available when instantiating it this way. One of the arguments that is **not** supported is the `--require` flag, which useful if you want to `require` a module, e.g. `babel-register` for transpilation. Thus, we added a `"require"` property in `config.json`, which takes a string of a single npm module name, or an array of npm module names. If it is an array, `nemo` will `require` each one before instantiating the `mocha` instances.
## Custom CLI Options
By default, Nemo will not accept CLI arguments that are not listed under [CLI Arguments](#cli-arguments)
Custom arguments can be useful for programmatically customizing Nemo configuration.
Use `--U` or `--allow-unknown-args` to prevent Nemo from validating CLI arguments
```sh
$ ./bin/nemo -U --myCustomArg myValue --anotherArg
```
8 changes: 8 additions & 0 deletions bin/_nemo
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function cwdPath(rel) {
return path.resolve(cwd, rel);
}

var allowUnknownArgs = (process.argv.indexOf('-U') > -1) || (process.argv.indexOf('--allow-unknown-args') > -1);

program
.version(JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8')).version)
.usage('[options]')
Expand All @@ -35,9 +37,11 @@ program
.option('-S, --server ', 'run the nemo web server')
.option('-L, --logging ', 'info level logging (errors log by default)')
.option('-X, --scaffold <path>', 'inject an example nemo suite under <path>')
.option('-U, --allow-unknown-args', 'allow command line arguments not specified by Nemo')
.option('--debug-brk', 'enable node\'s debugger breaking on the first line')
.option('--inspect', 'activate devtools in chrome')
.option('--no-timeouts', 'remove timeouts in debug/inspect use case')
.allowUnknownOption(allowUnknownArgs)
.parse(process.argv);

program._name = 'nemo';
Expand All @@ -53,6 +57,10 @@ engine = require('../lib/engine');
debug = require('debug');
log = debug('nemo:log');

if(allowUnknownArgs) {
log('allowing unknown command line arguments');
}

// are we launching the server?
if (program.server) {
log('CLI launching server');
Expand Down
25 changes: 16 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nemo",
"version": "4.2.2",
"version": "4.2.3",
"description": "Wrapper to run mocha suites with injected selenium-webdriver instance",
"main": "index.js",
"scripts": {
Expand All @@ -17,6 +17,7 @@
"nemo:form": "SELENIUM_PROMISE_MANAGER=0 ./bin/nemo -B test -P form",
"nemo:xunit": "./bin/nemo -B test -G @suite1 -P xunit",
"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",
"lint": "eslint ./bin/* ./lib/*"
},
Expand Down Expand Up @@ -59,6 +60,7 @@
"graphql": "^0.11.7",
"influx": "^5.0.7",
"lodash.merge": "^4.6.1",
"minimist": "^1.2.0",
"mocha": "^4",
"mochawesome": "^3.0.2",
"moment": "^2.21.0",
Expand Down
3 changes: 2 additions & 1 deletion test/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"browser": "phantomjs"
//just pretending this is another browser :)
}
}
},
"dynamic": "exec:./config/dynamic"
}
}
19 changes: 19 additions & 0 deletions test/config/dynamic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const path = require('path');
const assert = require('assert');
const minimist = require('minimist');

module.exports = function () {
// run tests if running nemo:dynamic npm script
var argv = minimist(process.argv.slice(2));
if(argv['url-from-cli']) {
assert.equal(argv.U, true, '-U not specified as expected');
assert.equal(argv['url-from-cli'], 'https://www.wikipedia.org', 'urlFromCli should equal to https://www.wikipedia.org');
}

return {
tests: path.resolve(__dirname, '../dynamic.js'),
data: {
urlFromCli: argv['url-from-cli']
}
};
};
10 changes: 10 additions & 0 deletions test/dynamic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const assert = require('assert');

describe('@dynamic@', function () {
it('should run quickly', async function () {
let nemo = this.nemo;
let {baseUrl, urlFromCli} = nemo.data;
assert.equal(nemo.data.urlFromCli, 'https://www.wikipedia.org', 'urlFromCli should equal to https://www.wikipedia.org');
await nemo.driver.get(urlFromCli || baseUrl);
});
});

0 comments on commit df73386

Please sign in to comment.