Skip to content
Browse files

Added prefixing option to prefix files with a URL path for URL based …

…testing
  • Loading branch information...
1 parent 1b7821f commit 4842a2fffe6f1ca20adf47f5f9e2be4812f3afb9 @davglass committed May 23, 2012
Showing with 23 additions and 0 deletions.
  1. +16 −0 lib/options.js
  2. +7 −0 tests/test.js
View
16 lib/options.js
@@ -36,6 +36,15 @@ var parse = function(args) {
case "--quiet":
options.quiet = true;
break;
+ case "-p":
+ case "--prefix":
+ var p = args.shift();
+ if (p) {
+ options.prefix = p;
+ } else {
+ throw('-p requires an argument');
+ }
+ break;
case "-f":
case "--fail":
options.exitOnFail = true;
@@ -64,6 +73,7 @@ var parse = function(args) {
console.log(' -t, --timeout Specify a timeout (in seconds) for a test file to be considered as failed.');
console.log(' -i, --import <path to js file> - Require this file and use the exports (array)');
console.log(' as the list of files to process.');
+ console.log(' -p, --prefix <string> String to prefix to all urls (for dynamic server names)');
console.log(' -o, --outfile <path to export file>');
console.log(' You can specify an export type with the following:');
console.log(' --tap TAP export (default)');
@@ -117,6 +127,12 @@ var parse = function(args) {
}
}
+ if (options.prefix && options.paths && options.paths.length) {
+ options.paths.forEach(function(p, i) {
+ options.paths[i] = options.prefix + p;
+ });
+ }
+
return options;
};
View
7 tests/test.js
@@ -137,6 +137,13 @@ suite.add(new YUITest.TestCase({
Assert.isTrue(opts.silent, 'Failed to set silent');
Assert.isTrue(opts.quiet, 'Failed to set quiet');
Assert.isTrue(opts.exitOnFail, 'Failed to set exitOnFail');
+ },
+ 'check prefix': function() {
+ var opts = parse(['-p', 'http://localhost:300/', 'foo.html', 'path/to/file.html']);
+
+ Assert.areEqual(opts.paths.length, 2, 'Failed to parse paths');
+ Assert.areEqual(opts.paths[0], 'http://localhost:300/foo.html', 'Failed to add prefix to first item');
+ Assert.areEqual(opts.paths[1], 'http://localhost:300/path/to/file.html', 'Failed to add prefix to second item');
}
}));

0 comments on commit 4842a2f

Please sign in to comment.
Something went wrong with that request. Please try again.