/
plugin_exec_test.js
66 lines (56 loc) · 2.02 KB
/
plugin_exec_test.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
'use strict';
var grunt = require('grunt'), cp = require("child_process"), command, options;
function callGruntfile(filename, whenDoneCallback) {
var command, options;
command = "grunt --gruntfile "+filename+" --no-color";
options = {cwd: 'test/'};
cp.exec(command, options, whenDoneCallback);
}
function callNpmInstallAndGruntfile(filename, whenDoneCallback) {
var command, options;
command = "npm install";
options = {cwd: 'test/'};
cp.exec(command, {}, function(error, stdout, stderr) {
callGruntfile(filename, whenDoneCallback);
});
}
function contains(where, what) {
var index = where.toString().indexOf(what);
return index>-1;
}
function containsWarning(buffer, warning) {
return contains(buffer, 'Warning: Plugin failed: ' + warning);
}
exports.plugin_tester = {
setUp: function(done) {
// setup here if necessary
done();
},
pass: function(test) {
test.expect(3);
callGruntfile('gruntfile-pass.js', function (error, stdout, stderr) {
test.equal(error, null, "Command should not fail.");
test.equal(stderr, '', "Standard error stream should be empty.");
test.ok(contains(stdout, 'Plugin worked correctly.'), "It was supposed to pass.");
test.done();
});
},
fail_1: function(test) {
test.expect(3);
callGruntfile('gruntfile-fail-complete.js', function (error, stdout, stderr) {
test.equal(error.message, 'Command failed: ', "Command should have failed.");
test.equal(stderr, '', "Standard error stream should be empty.");
test.ok(containsWarning(stdout, 'complete failure'), "It was supposed to pass.");
test.done();
});
},
fail_2: function(test) {
test.expect(3);
callGruntfile('gruntfile-fail-partial.js', function (error, stdout, stderr) {
test.equal(error.message, 'Command failed: ', "Command should have failed.");
test.equal(stderr, '', "Standard error stream should be empty.");
test.ok(containsWarning(stdout, 'partial failure'), "It was supposed to pass.");
test.done();
});
}
};