1 | 'use strict';
|
2 |
|
3 | var grunt = require('grunt');
|
4 | var sinon = require('sinon');
|
5 | var path = require('path');
|
6 |
|
7 | var child_process = require('child_process');
|
8 |
|
9 | function runGruntTask(taskName, callback) {
|
10 | var task = grunt.task._taskPlusArgs(taskName);
|
11 | task.task.fn.apply({
|
12 | nameArgs: task.nameArgs,
|
13 | name: task.task.name,
|
14 | args: task.args,
|
15 | flags: task.flags,
|
16 | async: function() { return callback; }
|
17 | }, task.args);
|
18 | }
|
19 |
|
20 | function stubChildProcess() {
|
21 | return {
|
22 | stdin: {
|
23 | end: sinon.stub()
|
24 | },
|
25 | on: sinon.stub()
|
26 | };
|
27 | }
|
28 |
|
29 | var child_process_spawn = child_process.spawn;
|
30 |
|
31 | exports.coveralls = {
|
32 | setUp: function (callback) {
|
33 | child_process.spawn = sinon.stub();
|
34 | callback();
|
35 | },
|
36 |
|
37 | tearDown: function (callback) {
|
38 | child_process.spawn = child_process_spawn;
|
39 | callback();
|
40 | },
|
41 |
|
42 | submits_file_to_coveralls: function (test) {
|
43 | var procStub = stubChildProcess();
|
44 | var inputStub = procStub.stdin.end;
|
45 | child_process.spawn.returns(procStub);
|
46 |
|
47 | runGruntTask('coveralls:basic_test', function (result) {
|
48 | test.ok(result, 'Should be successful');
|
49 |
|
50 | test.ok(child_process.spawn.calledWith('node', [path.resolve('./node_modules/.bin/coveralls')]));
|
51 | test.ok(inputStub.calledOnce);
|
52 | test.ok(inputStub.calledWith('lcov.info content'), 'Should send lcov data');
|
53 | test.done();
|
54 | });
|
55 |
|
56 | procStub.on.withArgs('exit').yield(0);
|
57 | },
|
58 |
|
59 | submits_nothing_if_the_file_is_missing: function (test) {
|
60 | runGruntTask('coveralls:missing_file_test', function (result) {
|
61 | test.ok(!result, 'Should fail');
|
62 |
|
63 | test.ok(!child_process.spawn.called);
|
64 | test.done();
|
65 | });
|
66 | },
|
67 |
|
68 | submits_multiple_files: function (test) {
|
69 | var procStub = stubChildProcess();
|
70 | var inputStub = procStub.stdin.end;
|
71 | child_process.spawn.returns(procStub);
|
72 |
|
73 | runGruntTask('coveralls:multiple_files_test', function (result) {
|
74 | test.ok(result, 'Should be successful');
|
75 |
|
76 | test.ok(inputStub.calledTwice);
|
77 | test.ok(inputStub.calledWith('lcov.info content'), 'Should send first file data');
|
78 | test.ok(inputStub.calledWith('lcov2.info content'), 'Should send second file data');
|
79 | test.done();
|
80 | });
|
81 |
|
82 | procStub.on.withArgs('exit').yield(0);
|
83 | },
|
84 |
|
85 | submits_present_files_only_if_some_are_missing: function (test) {
|
86 | var procStub = stubChildProcess();
|
87 | var inputStub = procStub.stdin.end;
|
88 | child_process.spawn.returns(procStub);
|
89 |
|
90 | runGruntTask('coveralls:some_missing_files_test', function (result) {
|
91 | test.ok(result, 'Should be successful');
|
92 |
|
93 | test.ok(inputStub.calledOnce);
|
94 | test.ok(inputStub.calledWith('lcov.info content'), 'Should send first file data');
|
95 | test.done();
|
96 | });
|
97 |
|
98 | procStub.on.withArgs('exit').yield(0);
|
99 | },
|
100 |
|
101 | fails_if_multiple_files_listed_and_all_files_are_missing: function (test) {
|
102 | runGruntTask('coveralls:all_missing_files_test', function (result) {
|
103 | test.ok(!result, 'Should fail');
|
104 |
|
105 | test.ok(!child_process.spawn.called);
|
106 | test.done();
|
107 | });
|
108 | },
|
109 |
|
110 | fails_if_any_files_fail_to_upload: function (test) {
|
111 | var procStub = stubChildProcess();
|
112 | child_process.spawn.returns(procStub);
|
113 |
|
114 | runGruntTask('coveralls:basic_test', function (result) {
|
115 | test.ok(!result, 'Should fail');
|
116 | test.done();
|
117 | });
|
118 |
|
119 |
|
120 | procStub.on.withArgs('exit').yield(1);
|
121 | }
|
122 | };
|