Add ability to run tests selectively.

* Anything on the command line after "run-tests.sh" will be understood
   as a regular expression (if there is more than one argument, they are
   concatenated, with spaces in between) and only the tests whose "full
   names" match that regexp will be run.  The full name of a test is the
   "describe" string plus a space plus the "it" string.  Note well that,
   unlike the test-runner output, there is no colon in there.

 * run-tests.sh and run-tests.js now correctly handle being invoked from
   an arbitrary directory; the cwd does not have to be the project root.

 * Shell portability fixes for run-tests.sh.

 #12230 (Test suite improvements).
2.0
Zack Weinberg 2014-05-14 16:48:56 -04:00 committed by Ariya Hidayat
parent 6fb347d296
commit b524d53d36
2 changed files with 17 additions and 12 deletions

View File

@ -28,6 +28,11 @@
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Set the working directory to the "/test" directory if it's not
// already there.
var fs = require('fs');
fs.changeWorkingDirectory(phantom.libraryPath);
// Load Jasmine and the HTML reporter
phantom.injectJs("./lib/jasmine.js");
phantom.injectJs("./lib/jasmine-console.js");
@ -56,10 +61,6 @@ function expectHasPropertyString(o, name) {
});
}
// Set the working directory to the "/test" directory
var fs = require('fs');
fs.changeWorkingDirectory(phantom.libraryPath);
// Load specs
phantom.injectJs("./phantom-spec.js");
phantom.injectJs("./webserver-spec.js");
@ -75,12 +76,20 @@ require("./module_spec.js");
require("./require/require_spec.js");
require("./cjk-text-codecs.js");
// Launch tests
// Environment configuration
var jasmineEnv = jasmine.getEnv();
// If there are any command line arguments, filter tests based on them.
var sys = require('system');
if (sys.args.length > 1) {
var specFilterRe = new RegExp(sys.args.slice(1).join(" "));
jasmineEnv.specFilter = function (spec) {
return specFilterRe.test(spec.getFullName());
};
}
// Add a ConsoleReporter to 1) print with colors on the console
// 2) exit when finished
var sys = require('system');
jasmineEnv.addReporter(new jasmine.ConsoleReporter(
// Print messages straight to the console, and don't mess with the newlines
sys.stdout.write.bind(sys.stdout),

View File

@ -1,6 +1,2 @@
#!/usr/bin/env bash
# Run tests
bin/phantomjs test/run-tests.js
exit $?
#!/bin/sh
exec "${0%/*}/../bin/phantomjs" "${0%/*}/run-tests.js" "$@"