-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathtest.js
98 lines (77 loc) · 1.76 KB
/
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import test from 'ava';
import Vinyl from 'vinyl';
import through2 from 'through2';
import gulpJasmine from '.';
const out = process.stdout.write.bind(process.stdout);
function jasmine(file, options) {
return new Promise((resolve, reject) => {
const stream = gulpJasmine(options);
let output = '';
process.stdout.write = str => {
out(str);
output += str;
};
stream.on('error', reject);
stream.on('jasmineDone', passed => {
resolve({output, passed});
});
stream.write(new Vinyl({
path: file,
contents: Buffer.from('')
}));
stream.end();
});
}
test('run unit test and pass', async t => {
const {output, passed} = await jasmine('fixture.js', {
timeout: 9000,
verbose: true
});
t.true(/should pass: passed/.test(output));
t.true(passed);
});
test('run unit test and fail silently', async t => {
const {output, passed} = await jasmine('fail-fixture.js', {
timeout: 9000,
verbose: true,
errorOnFail: false
});
t.true(/should fail: failed/.test(output));
t.false(passed);
});
test('run unit test and fail', async t => {
let errorThrown = 0;
try {
await jasmine('fail-fixture.js', {
timeout: 9000,
verbose: true
});
} catch (_) {
errorThrown++;
}
t.is(errorThrown, 1);
});
test.cb('run the test only once even if called in succession', t => {
const stream = gulpJasmine({
timeout: 9000,
verbose: true
});
let output = '';
const reader = through2.obj((file, encoding, callback) => {
callback();
}, callback => {
process.stdout.write = out;
t.is(output.match(/should pass: passed/g).length, 1);
callback();
t.end();
});
process.stdout.write = string => {
output += string;
};
stream.pipe(reader);
stream.write(new Vinyl({
path: 'fixture.js',
contents: Buffer.from('')
}));
stream.end();
});