forked from gruntjs/grunt-contrib-qunit
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathGruntfile.js
112 lines (99 loc) · 2.7 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* grunt-contrib-qunit
* http://gruntjs.com/
*
* Copyright (c) 2013 "Cowboy" Ben Alman, contributors
* Licensed under the MIT license.
*/
'use strict';
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
jshint: {
all: [
'Gruntfile.js',
'tasks/**/*.js',
],
options: {
jshintrc: '.jshintrc'
}
},
// 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/*{1,2}.html'],
individual_tests: {
files: [
{src: 'test/*1.html'},
{src: 'test/*{1,2}.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',
},
}
});
// 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).
grunt.loadTasks('tasks');
// These plugins provide necessary 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', ['connect', 'qunit', 'really-test']);
// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'test', 'build-contrib']);
};