diff options
author | Solly Ross <sross@redhat.com> | 2013-12-17 18:00:57 -0500 |
---|---|---|
committer | Solly Ross <sross@redhat.com> | 2013-12-17 18:00:57 -0500 |
commit | 85e899166447866fc2fd9e51a565efbc8308673e (patch) | |
tree | f7f2ee44b99ccbc009937240a1ab388bcce2ff60 | |
parent | d823e8956ecfb6110c82a5bb2e1fe324d51cd380 (diff) | |
download | novnc-85e899166447866fc2fd9e51a565efbc8308673e.tar.gz |
Support 'requires' Line in Test Runner
If the files passed to the '-t' option are all '.js' files (or
the 'run all tests' option is used) and the '-i' option is not
passed, all tests will be search for the string
'require local modules: '. Only the first instance of this string
will be used. Following the colon should be a list of either local
modules (i.e. files in the '../include/' folder relative to the
test runner's directory, without the '.js' extension) or paths
to other Javascript files. The list of modules and/or files should
be comma-separated. These files will then be included in the generated
HTML file for the appropriate tests as if the '-i' option had been used.
-rwxr-xr-x | tests/run_from_console.js | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/tests/run_from_console.js b/tests/run_from_console.js index 4d0cae4..7525c8b 100755 --- a/tests/run_from_console.js +++ b/tests/run_from_console.js @@ -15,8 +15,8 @@ program .option('-c, --color', 'Explicitly enable color (default is to use color when not outputting to a pipe)') .option('-i, --auto-inject <includefiles>', 'Treat the test list as a set of mocha JS files, and automatically generate HTML files with which to test test. \'includefiles\' should be a comma-separated list of paths to javascript files to include in each of the generated HTML files', make_list, null) .option('-p, --provider <name>', 'Use the given provider (defaults to "casper"). Currently, may be "casper" or "zombie"', 'casper') - .option('-g, --generate-html', 'Instead of running the tests, just return the path to the generated HTML file, then wait for user interaction to exit (should be used with -i)') - .option('-o, --output-html', 'Instead of running the tests, just output the generated HTML source to STDOUT (should be used with -i)') + .option('-g, --generate-html', 'Instead of running the tests, just return the path to the generated HTML file, then wait for user interaction to exit (should be used with .js tests)') + .option('-o, --output-html', 'Instead of running the tests, just output the generated HTML source to STDOUT (should be used with .js tests)') .option('-d, --debug', 'Show debug output (the "console" event) from the provider') .parse(process.argv); @@ -27,6 +27,29 @@ if (program.tests.length === 0) { var file_paths = []; +var all_js = program.tests.reduce(function(a,e) { return a && e.slice(-3) == '.js'; }, true); + +if (all_js && !program.autoInject) { + var all_modules = {}; + + // uses the first instance of the string 'requires local modules: ' + program.tests.forEach(function (testname) { + var full_path = path.resolve(process.cwd(), testname); + var content = fs.readFileSync(full_path).toString(); + var ind = content.indexOf('requires local modules: '); + if (ind > -1) { + ind += 'requires local modules: '.length; + var eol = content.indexOf('\n', ind); + var modules = content.slice(ind, eol).split(/,\s*/); + modules.forEach(function (mod) { + all_modules[path.resolve(__dirname, '../include/', mod)+'.js'] = 1; + }); + } + }); + + program.autoInject = Object.keys(all_modules); +} + if (program.autoInject) { var temp = require('temp'); temp.track(); |