UNPKG

2.05 kBJavaScriptView Raw
1'use strict';
2
3var test = require('tap').test;
4var path = require('path');
5var concat = require('concat-stream');
6var spawn = require('child_process').spawn;
7
8var stripFullStack = require('./common').stripFullStack;
9
10test(function (tt) {
11 tt.plan(2);
12 var ps = spawn(process.execPath, [path.join(__dirname, 'double_end', 'double.js')]);
13 ps.on('exit', function (code) {
14 tt.equal(code, 1);
15 });
16 ps.stdout.pipe(concat(function (body) {
17 // The implementation of node's timer library has changed over time. We
18 // need to reverse engineer the error we expect to see.
19
20 // This code is unfortunately by necessity highly coupled to node
21 // versions, and may require tweaking with future versions of the timers
22 // library.
23 function doEnd() { throw new Error(); }
24 var to = setTimeout(doEnd, 5000);
25 clearTimeout(to);
26 to._onTimeout = doEnd;
27
28 var stackExpected;
29 var atExpected;
30 try {
31 to._onTimeout();
32 } catch (e) {
33 stackExpected = stripFullStack(e.stack)[1];
34 stackExpected = stackExpected.replace('double_end.js', 'double_end/double.js');
35 stackExpected = stackExpected.trim();
36 atExpected = stackExpected.replace(/^at\s+/, 'at: ');
37 }
38
39 var stripped = stripFullStack(body.toString('utf8'));
40 tt.same(stripped, [
41 'TAP version 13',
42 '# double end',
43 'ok 1 should be strictly equal',
44 'not ok 2 .end() already called',
45 ' ---',
46 ' operator: fail',
47 ' ' + atExpected,
48 ' stack: |-',
49 ' Error: .end() already called',
50 ' [... stack stripped ...]',
51 ' ' + stackExpected,
52 ' [... stack stripped ...]',
53 ' ...',
54 '',
55 '1..2',
56 '# tests 2',
57 '# pass 1',
58 '# fail 1',
59 '',
60 ''
61 ]);
62 }));
63});