-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtask.js
57 lines (44 loc) · 1.88 KB
/
task.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
var path = require('path'),
temp = require('temp'),
process = require('child_process'),
nunit = require('./nunit.js');
module.exports = function(grunt) {
grunt.registerMultiTask('nunit', 'Runs the NUnit test runner.', function() {
var options = this.options({ nodots: !this.options().nunit3 });
var cleanup;
if (!options.result && options.teamcity) {
temp.track();
options.result = temp.path({ suffix: '.xml' });
cleanup = temp.cleanup;
}
console.log();
console.log('NUnit Task Runner');
console.log();
var assemblies = nunit.findTestAssemblies(this.filesSrc, options);
var command = nunit.buildCommand(assemblies, options);
console.log('Running tests in:');
console.log();
assemblies.forEach(function(file) { console.log(' ' + file); });
console.log();
console.log(command.path + ' ' + command.args.join(' '));
console.log();
var taskComplete = this.async();
var nunitProcess = process.spawn(command.path, command.args, { windowsVerbatimArguments: true });
var log = function(message) { console.log(message.toString('utf8')); };
nunitProcess.stdout.on('data', log);
nunitProcess.stderr.on('data', log);
nunitProcess.on('exit', function(code) {
if (options.teamcity) console.log(nunit.createTeamcityLog(options.result).join(''));
if (cleanup) cleanup();
if (code > 0) {
grunt.log.error('Tests failed.');
taskComplete(false);
}
taskComplete();
});
nunitProcess.on('error', function(e) {
grunt.log.error(e.code === 'ENOENT' ? 'Unable to find NUnit Console.exe located at ' + command.path : e.message);
taskComplete(false);
});
});
};