-
-
Notifications
You must be signed in to change notification settings - Fork 305
/
double_end.js
64 lines (58 loc) · 2.01 KB
/
double_end.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
'use strict';
var test = require('tap').test;
var path = require('path');
var concat = require('concat-stream');
var spawn = require('child_process').spawn;
var stripFullStack = require('./common').stripFullStack;
test(function (tt) {
tt.plan(2);
var ps = spawn(process.execPath, [path.join(__dirname, 'double_end', 'double.js')]);
ps.on('exit', function (code) {
tt.equal(code, 1);
});
ps.stdout.pipe(concat(function (body) {
// The implementation of node's timer library has changed over time. We
// need to reverse engineer the error we expect to see.
// This code is unfortunately by necessity highly coupled to node
// versions, and may require tweaking with future versions of the timers
// library.
function doEnd() { throw new Error(); }
var to = setTimeout(doEnd, 5000);
clearTimeout(to);
to._onTimeout = doEnd;
var stackExpected;
var atExpected;
try {
to._onTimeout();
}
catch (e) {
stackExpected = stripFullStack(e.stack)[1];
stackExpected = stackExpected.replace('double_end.js', 'double_end/double.js');
stackExpected = stackExpected.trim();
atExpected = stackExpected.replace(/^at\s+/, 'at: ');
}
var stripped = stripFullStack(body.toString('utf8'));
tt.same(stripped, [
'TAP version 13',
'# double end',
'ok 1 should be strictly equal',
'not ok 2 .end() already called',
' ---',
' operator: fail',
' ' + atExpected,
' stack: |-',
' Error: .end() already called',
' [... stack stripped ...]',
' ' + stackExpected,
' [... stack stripped ...]',
' ...',
'',
'1..2',
'# tests 2',
'# pass 1',
'# fail 1',
'',
''
]);
}));
});