Skip to content

Commit 5c40a46

Browse files
committed
[isolate] tests
1 parent 26fc3f7 commit 5c40a46

File tree

5 files changed

+211
-0
lines changed

5 files changed

+211
-0
lines changed

test/fixtures/isolate/failing-test.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var vows = require('../../../lib/vows'),
2+
assert = require('assert');
3+
4+
var obvious;
5+
vows.describe('failing').addBatch({
6+
'Obvious test': obvious = {
7+
topic: function() {
8+
this.callback(null, false);
9+
},
10+
'should work': function(result) {
11+
assert.ok(result);
12+
}
13+
// but it won't
14+
},
15+
'Obvious test #2': obvious,
16+
'Obvious test #3': obvious,
17+
'Obvious test #4': obvious
18+
}).export(module);

test/fixtures/isolate/log-test.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var vows = require('../../../lib/vows'),
2+
assert = require('assert');
3+
4+
var obvious;
5+
vows.describe('stderr').addBatch({
6+
'Obvious test': obvious = {
7+
topic: function() {
8+
this.callback(null, true);
9+
},
10+
'should work': function(result) {
11+
console.log('oh no!');
12+
assert.ok(result);
13+
}
14+
},
15+
'Obvious test #2': obvious,
16+
'Obvious test #3': obvious,
17+
'Obvious test #4': obvious
18+
}).export(module);

test/fixtures/isolate/passing-test.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var vows = require('../../../lib/vows'),
2+
assert = require('assert');
3+
4+
var obvious;
5+
vows.describe('passing').addBatch({
6+
'Obvious test': obvious = {
7+
topic: function() {
8+
this.callback(null, true);
9+
},
10+
'should work': function(result) {
11+
assert.ok(result);
12+
}
13+
},
14+
'Obvious test #2': obvious,
15+
'Obvious test #3': obvious,
16+
'Obvious test #4': obvious
17+
}).export(module);

test/fixtures/isolate/stderr-test.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var vows = require('../../../lib/vows'),
2+
assert = require('assert');
3+
4+
var obvious;
5+
vows.describe('stderr').addBatch({
6+
'Obvious test': obvious = {
7+
topic: function() {
8+
this.callback(null, true);
9+
},
10+
'should work': function(result) {
11+
console.error('oh no!');
12+
assert.ok(result);
13+
}
14+
},
15+
'Obvious test #2': obvious,
16+
'Obvious test #3': obvious,
17+
'Obvious test #4': obvious
18+
}).export(module);

test/isolate-test.js

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
var vows = require('../lib/vows'),
2+
assert = require('assert'),
3+
path = require('path'),
4+
exec = require('child_process').exec;
5+
6+
function generateTopic(args, file) {
7+
return function() {
8+
var cmd = './bin/vows' + ' -i ' + (args || '') +
9+
' ./test/fixtures/isolate/' + file,
10+
options = {cwd: path.resolve(__dirname + '/../')},
11+
callback = this.callback;
12+
13+
exec(cmd, options, function(err, stdout, stderr) {
14+
callback(null, {
15+
err: err,
16+
stdout: stdout,
17+
stderr: stderr
18+
});
19+
});
20+
}
21+
};
22+
23+
function assertExecOk(r) {
24+
assert.isNull(r.err);
25+
}
26+
27+
function assertExecNotOk(r) {
28+
assert.isNotNull(r.err);
29+
}
30+
31+
function parseResults(stdout) {
32+
return stdout.split(/\n/g).map(function(s) {
33+
if (!s) return;
34+
return JSON.parse(s);
35+
}).filter(function(s) {return s});
36+
}
37+
38+
function assertResultTypePresent(results, type) {
39+
assert.ok(results.some(function(result) {
40+
return result[0] == type;
41+
}));
42+
}
43+
44+
function assertResultsFinish(results, expected) {
45+
var finish = results[results.length - 1];
46+
assert.equal(finish[0], 'finish');
47+
48+
finish = finish[1];
49+
50+
Object.keys(expected).forEach(function(key) {
51+
assert.equal(finish[key], expected[key]);
52+
});
53+
}
54+
55+
vows.describe('vows/isolate').addBatch({
56+
'Running vows with -i flag for test/fixtures/isolate/': {
57+
'passing-test.js': {
58+
'with default reporter': {
59+
topic: generateTopic(null, 'passing-test.js'),
60+
'should be ok': assertExecOk
61+
},
62+
'with json reporter': {
63+
topic: generateTopic('--json', 'passing-test.js'),
64+
'should be ok': assertExecOk,
65+
'should have correct output': function(r) {
66+
var results = parseResults(r.stdout)
67+
68+
assertResultTypePresent(results, 'subject');
69+
assertResultTypePresent(results, 'end');
70+
71+
assertResultsFinish(results, {
72+
total: 4,
73+
honored: 4
74+
});
75+
}
76+
}
77+
},
78+
'failing-test.js': {
79+
'with json reporter': {
80+
topic: generateTopic('--json', 'failing-test.js'),
81+
'should be not ok': assertExecNotOk,
82+
'should have correct output though': function(r) {
83+
var results = parseResults(r.stdout);
84+
85+
assertResultsFinish(results, {
86+
total: 4,
87+
broken: 4
88+
});
89+
}
90+
}
91+
},
92+
'stderr-test.js': {
93+
'with json reporter': {
94+
topic: generateTopic('--json', 'stderr-test.js'),
95+
'should be ok': assertExecOk,
96+
'should have stderr': function(r) {
97+
assert.equal(r.stderr,
98+
['oh no!', 'oh no!', 'oh no!', 'oh no!', ''].join('\n'));
99+
},
100+
'should have correct output': function(r) {
101+
var results= parseResults(r.stdout);
102+
103+
assertResultsFinish(results, {
104+
total: 4,
105+
honored: 4
106+
});
107+
}
108+
}
109+
},
110+
'log-test.js': {
111+
'with json reporter': {
112+
topic: generateTopic('--json', 'log-test.js'),
113+
'should be ok': assertExecOk,
114+
'should have correct output': function(r) {
115+
var results= parseResults(r.stdout);
116+
117+
assertResultsFinish(results, {
118+
total: 4,
119+
honored: 4
120+
});
121+
}
122+
}
123+
},
124+
'all tests (*)': {
125+
'with json reporter': {
126+
topic: generateTopic('--json', '*'),
127+
'should be not ok': assertExecNotOk,
128+
'should have correct output': function(r) {
129+
var results= parseResults(r.stdout);
130+
131+
assertResultsFinish(results, {
132+
total: 16,
133+
broken: 4,
134+
honored: 12
135+
});
136+
}
137+
}
138+
}
139+
}
140+
}).export(module);

0 commit comments

Comments
 (0)