forked from JamesMGreene/qunit-reporter-junit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
82 lines (70 loc) · 1.81 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
/*jshint node:true, strict:false */
module.exports = function( grunt ) {
grunt.loadNpmTasks( 'grunt-contrib-jshint' );
grunt.loadNpmTasks( 'grunt-git-authors' );
grunt.loadNpmTasks( 'grunt-contrib-connect' );
grunt.initConfig({
jshint: {
options: {
jshintrc: '.jshintrc'
},
main: [ '*.js' ],
tests: [ 'test/**/*.js' ]
},
connect: {
server: {
port: 8000,
hostname: 'localhost',
base: '.'
}
}
});
grunt.registerTask('qunit', 'Run the test suite on PhantomJS', function () {
var done = this.async(),
phantomjs = require('grunt-lib-phantomjs').init(grunt),
fs = require('fs'),
output = '';
function normalise(xmlStr) {
return xmlStr
// Remove timestamp and time attributes as those are variable
.replace(/timestamp="([^"]+)"/g, '')
.replace(/time="([^"]+)"/g, '');
}
phantomjs.on('console', function (data) {
output = data;
phantomjs.halt();
});
phantomjs.on('fail.load', function () {
grunt.warn('PhantomJS unable to load URL.');
phantomjs.halt();
});
phantomjs.on('fail.timeout', function () {
grunt.warn('PhantomJS timed out.');
phantomjs.halt();
});
phantomjs.spawn('http://localhost:8000/test/index.html', {
options: {
timeout: 5 * 1000
},
// Once phantomjs is halted
done: function(err) {
var expected = fs.readFileSync(__dirname + '/test/expected.xml'),
actual = output;
expected = normalise(String(expected).trim());
actual = normalise(String(actual).trim());
if ( expected === actual ) {
done();
} else if (err) {
grunt.warn(err);
done(false);
} else {
grunt.warn('Output does not match expected pattern.');
grunt.log.writeln('Expected:\n' + expected + '\nActual:\n' + actual);
done(false);
}
}
});
});
grunt.registerTask('test', ['jshint', 'connect', 'qunit']);
grunt.registerTask('default', 'test');
};