grunt-contrib-qunit
Advanced tools
Comparing version 0.1.0 to 0.1.1-rc5
# Usage examples | ||
## Wildcards | ||
In this example, `grunt qunit:all` (or `grunt qunit` because `qunit` is a [multi task][]) will test all `.html` files in the test directory _and all subdirectories_. First, the wildcard is expanded to match each individual file. Then, each matched filename is converted to the appropriate `file://` URI. Finally, each URI is passed to [PhantomJS][] (one at a time). | ||
In this example, `grunt qunit:all` (or `grunt qunit` because `qunit` is a [multi task][]) will test all `.html` files in the test directory _and all subdirectories_. First, the wildcard is expanded to match each individual file. Then, each matched filename is passed to [PhantomJS][] (one at a time). | ||
@@ -16,3 +16,3 @@ ```js | ||
## Testing via http:// or https:// | ||
In circumstances where running unit tests from `file://` URIs is inadequate, you can specify `http://` or `https://` URIs instead. If `http://` or `https://` URIs have been specified, those URIs will be passed directly to [PhantomJS][], as-specified. | ||
In circumstances where running unit tests from local files is inadequate, you can specify `http://` or `https://` URLs via the `urls` option. Each URL is passed to [PhantomJS][] (one at a time). | ||
@@ -25,3 +25,10 @@ In this example, `grunt qunit` will test two files, served from the server running at `localhost:8000`. | ||
qunit: { | ||
all: ['http://localhost:8000/test/foo.html', 'http://localhost:8000/test/bar.html'] | ||
all: { | ||
options: { | ||
urls: [ | ||
'http://localhost:8000/test/foo.html', | ||
'http://localhost:8000/test/bar.html' | ||
] | ||
} | ||
} | ||
} | ||
@@ -31,2 +38,4 @@ }); | ||
Wildcards and URLs may be combined by specifying both. | ||
## Using the grunt-contrib-connect plugin | ||
@@ -38,3 +47,3 @@ It's important to note that grunt does not automatically start a `localhost` web server. That being said, the [grunt-contrib-connect plugin][] `connect` task can be run before the `qunit` task to serve files via a simple [connect][] web server. | ||
In the following example, if a web server isn't running at `localhost:8000`, running `grunt qunit` with the following configuration will fail because the `qunit` task won't be able to load the specified URIs. However, running `grunt connect qunit` will first start a static [connect][] web server at `localhost:8000` with its base path set to the Gruntfile's directory. Then, the `qunit` task will be run, requesting the specified URIs. | ||
In the following example, if a web server isn't running at `localhost:8000`, running `grunt qunit` with the following configuration will fail because the `qunit` task won't be able to load the specified URLs. However, running `grunt connect qunit` will first start a static [connect][] web server at `localhost:8000` with its base path set to the Gruntfile's directory. Then, the `qunit` task will be run, requesting the specified URLs. | ||
@@ -41,0 +50,0 @@ ```js |
@@ -15,2 +15,8 @@ # Options | ||
## urls | ||
Type: `Array` | ||
Default: `[]` | ||
Absolute `http://` or `https://` urls to be passed to PhantomJS. Specified URLs will be merged with any specified `src` files first. Note that urls must be served by a web server, and since this task doesn't contain a web server, one will need to be configured separately. The [grunt-contrib-connect plugin](https://github.com/gruntjs/grunt-contrib-connect) provides a basic web server. | ||
## (-- PhantomJS arguments) | ||
@@ -17,0 +23,0 @@ Type: `String` |
@@ -25,5 +25,21 @@ /* | ||
// Create a local web server for testing http:// URIs. | ||
connect: { | ||
root_server: { | ||
options: { | ||
port: 9000, | ||
base: '.', | ||
}, | ||
}, | ||
test_server: { | ||
options: { | ||
port: 9001, | ||
base: 'test', | ||
}, | ||
} | ||
}, | ||
// Unit tests. | ||
qunit: { | ||
all_tests: ['test/*.html'], | ||
all_tests: ['test/*{1,2}.html'], | ||
individual_tests: { | ||
@@ -33,5 +49,18 @@ files: [ | ||
{src: 'test/*{1,2}.html'}, | ||
{src: 'test/*.html'}, | ||
] | ||
} | ||
}, | ||
urls: { | ||
options: { | ||
urls: [ | ||
'http://localhost:9000/test/qunit1.html', | ||
'http://localhost:9001/qunit2.html', | ||
] | ||
}, | ||
}, | ||
urls_and_files: { | ||
options: { | ||
urls: '<%= qunit.urls.options.urls %>', | ||
}, | ||
src: 'test/*{1,2}.html', | ||
}, | ||
} | ||
@@ -41,2 +70,32 @@ | ||
// Build a mapping of url success counters. | ||
var successes = {}; | ||
var currentUrl; | ||
grunt.event.on('qunit.spawn', function(url) { | ||
currentUrl = url; | ||
if (!successes[currentUrl]) { successes[currentUrl] = 0; } | ||
}); | ||
grunt.event.on('qunit.done', function(failed, passed) { | ||
if (failed === 0 && passed === 2) { successes[currentUrl]++; } | ||
}); | ||
grunt.registerTask('really-test', 'Test to see if qunit task actually worked.', function() { | ||
var assert = require('assert'); | ||
var difflet = require('difflet')({indent: 2, comment: true}); | ||
var actual = successes; | ||
var expected = { | ||
'test/qunit1.html': 3, | ||
'test/qunit2.html': 3, | ||
'http://localhost:9000/test/qunit1.html': 2, | ||
'http://localhost:9001/qunit2.html': 2 | ||
}; | ||
try { | ||
assert.deepEqual(actual, expected, 'Actual should match expected.'); | ||
} catch (err) { | ||
grunt.log.subhead('Actual should match expected.'); | ||
console.log(difflet.compare(expected, actual)); | ||
throw new Error(err.message); | ||
} | ||
}); | ||
// Actually load this plugin's task(s). | ||
@@ -47,6 +106,7 @@ grunt.loadTasks('tasks'); | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-contrib-connect'); | ||
grunt.loadNpmTasks('grunt-contrib-internal'); | ||
// Whenever the "test" task is run, run some basic tests. | ||
grunt.registerTask('test', ['qunit']); | ||
grunt.registerTask('test', ['connect', 'qunit', 'really-test']); | ||
@@ -53,0 +113,0 @@ // By default, lint and run all tests. |
{ | ||
"name": "grunt-contrib-qunit", | ||
"description": "Run QUnit unit tests in a headless PhantomJS instance.", | ||
"version": "0.1.0", | ||
"version": "0.1.1rc5", | ||
"homepage": "https://github.com/gruntjs/grunt-contrib-qunit", | ||
@@ -34,9 +34,9 @@ "author": { | ||
"devDependencies": { | ||
"grunt-contrib-jshint": "~0.1.0", | ||
"grunt-contrib-jshint": "~0.1.1rc5", | ||
"grunt-contrib-connect": "~0.1.0", | ||
"grunt-contrib-internal": "*", | ||
"grunt": "~0.4.0rc2", | ||
"grunt-cli": "~0.1.1" | ||
"grunt": "~0.4.0rc5", | ||
"difflet": "~0.2.3" | ||
}, | ||
"keywords": [ | ||
] | ||
"keywords": [] | ||
} |
@@ -46,2 +46,8 @@ # grunt-contrib-qunit [![Build Status](https://secure.travis-ci.org/gruntjs/grunt-contrib-qunit.png?branch=master)](http://travis-ci.org/gruntjs/grunt-contrib-qunit) | ||
#### urls | ||
Type: `Array` | ||
Default: `[]` | ||
Absolute `http://` or `https://` urls to be passed to PhantomJS. Specified URLs will be merged with any specified `src` files first. Note that urls must be served by a web server, and since this task doesn't contain a web server, one will need to be configured separately. The [grunt-contrib-connect plugin](https://github.com/gruntjs/grunt-contrib-connect) provides a basic web server. | ||
#### (-- PhantomJS arguments) | ||
@@ -56,3 +62,3 @@ Type: `String` | ||
#### Wildcards | ||
In this example, `grunt qunit:all` (or `grunt qunit` because `qunit` is a [multi task][]) will test all `.html` files in the test directory _and all subdirectories_. First, the wildcard is expanded to match each individual file. Then, each matched filename is converted to the appropriate `file://` URI. Finally, each URI is passed to [PhantomJS][] (one at a time). | ||
In this example, `grunt qunit:all` (or `grunt qunit` because `qunit` is a [multi task][]) will test all `.html` files in the test directory _and all subdirectories_. First, the wildcard is expanded to match each individual file. Then, each matched filename is passed to [PhantomJS][] (one at a time). | ||
@@ -69,3 +75,3 @@ ```js | ||
#### Testing via http:// or https:// | ||
In circumstances where running unit tests from `file://` URIs is inadequate, you can specify `http://` or `https://` URIs instead. If `http://` or `https://` URIs have been specified, those URIs will be passed directly to [PhantomJS][], as-specified. | ||
In circumstances where running unit tests from local files is inadequate, you can specify `http://` or `https://` URLs via the `urls` option. Each URL is passed to [PhantomJS][] (one at a time). | ||
@@ -78,3 +84,10 @@ In this example, `grunt qunit` will test two files, served from the server running at `localhost:8000`. | ||
qunit: { | ||
all: ['http://localhost:8000/test/foo.html', 'http://localhost:8000/test/bar.html'] | ||
all: { | ||
options: { | ||
urls: [ | ||
'http://localhost:8000/test/foo.html', | ||
'http://localhost:8000/test/bar.html' | ||
] | ||
} | ||
} | ||
} | ||
@@ -84,2 +97,4 @@ }); | ||
Wildcards and URLs may be combined by specifying both. | ||
#### Using the grunt-contrib-connect plugin | ||
@@ -91,3 +106,3 @@ It's important to note that grunt does not automatically start a `localhost` web server. That being said, the [grunt-contrib-connect plugin][] `connect` task can be run before the `qunit` task to serve files via a simple [connect][] web server. | ||
In the following example, if a web server isn't running at `localhost:8000`, running `grunt qunit` with the following configuration will fail because the `qunit` task won't be able to load the specified URIs. However, running `grunt connect qunit` will first start a static [connect][] web server at `localhost:8000` with its base path set to the Gruntfile's directory. Then, the `qunit` task will be run, requesting the specified URIs. | ||
In the following example, if a web server isn't running at `localhost:8000`, running `grunt qunit` with the following configuration will fail because the `qunit` task won't be able to load the specified URLs. However, running `grunt connect qunit` will first start a static [connect][] web server at `localhost:8000` with its base path set to the Gruntfile's directory. Then, the `qunit` task will be run, requesting the specified URLs. | ||
@@ -163,2 +178,3 @@ ```js | ||
* 2013-01-08 v0.1.1rc5 Updating to work with grunt v0.4.0rc5. Switching to this.filesSrc api. Adding "urls" option for specifying absolute test URLs. | ||
* 2012-10-04 v0.1.0 Work in progress, not yet officially released. | ||
@@ -170,2 +186,2 @@ | ||
*This file was generated on Mon Dec 10 2012 16:42:20.* | ||
*This file was generated on Wed Jan 09 2013 14:12:29.* |
@@ -118,3 +118,3 @@ /* | ||
grunt.log.error(); | ||
grunt.warn('PhantomJS unable to load "' + url + '" URI.', 90); | ||
grunt.warn('PhantomJS unable to load "' + url + '" URI.'); | ||
}); | ||
@@ -125,3 +125,3 @@ | ||
grunt.log.writeln(); | ||
grunt.warn('PhantomJS timed out, possibly due to a missing QUnit start() call.', 90); | ||
grunt.warn('PhantomJS timed out, possibly due to a missing QUnit start() call.'); | ||
}); | ||
@@ -139,6 +139,8 @@ | ||
inject: asset('phantomjs/bridge.js'), | ||
// Explicit non-file URLs to test. | ||
urls: [], | ||
}); | ||
// Get files as URLs. | ||
var urls = grunt.file.expandFileURLs(this.file.srcRaw); | ||
// Combine any specified URLs with src files. | ||
var urls = options.urls.concat(this.filesSrc); | ||
@@ -154,3 +156,3 @@ // This task is asynchronous. | ||
var basename = path.basename(url); | ||
grunt.verbose.subhead('Testing ' + basename).or.write('Testing ' + basename); | ||
grunt.verbose.subhead('Testing ' + url).or.write('Testing ' + url); | ||
@@ -163,4 +165,2 @@ // Reset current module. | ||
phantomjs.spawn(url, { | ||
// Exit code to use if PhantomJS fails in an uncatchable way. | ||
failCode: 90, | ||
// Additional PhantomJS options. | ||
@@ -185,3 +185,5 @@ options: options, | ||
grunt.warn(status.failed + '/' + status.total + ' assertions failed (' + | ||
status.duration + 'ms)', Math.min(99, 90 + status.failed)); | ||
status.duration + 'ms)'); | ||
} else if (status.total === 0) { | ||
grunt.warn('0/0 assertions ran (' + status.duration + 'ms)'); | ||
} else { | ||
@@ -188,0 +190,0 @@ grunt.verbose.writeln(); |
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
78755
1966
180
5
1