]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Support 'requires' Line in Test Runner
authorSolly Ross <sross@redhat.com>
Tue, 17 Dec 2013 23:00:57 +0000 (18:00 -0500)
committerSolly Ross <sross@redhat.com>
Tue, 17 Dec 2013 23:00:57 +0000 (18:00 -0500)
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.

tests/run_from_console.js

index 4d0cae4ae0fdfd9a6a0e06c470944f7c1e643694..7525c8b47000659ec278a330984c417053d9bc45 100755 (executable)
@@ -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();