UNPKG

2.06 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 (t) {
11 t.plan(2);
12 var ps = spawn(process.execPath, [path.join(__dirname, 'double_end', 'double.js')]);
13 ps.on('exit', function (code) {
14 t.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 }
33 catch (e) {
34 stackExpected = stripFullStack(e.stack).split('\n')[1];
35 stackExpected = stackExpected.replace('double_end.js', 'double_end/double.js');
36 stackExpected = stackExpected.trim();
37 atExpected = stackExpected.replace(/^at\s+/, 'at: ');
38 }
39
40 var stripped = stripFullStack(body.toString('utf8'));
41 t.equal(stripped, [
42 'TAP version 13',
43 '# double end',
44 'ok 1 should be strictly equal',
45 'not ok 2 .end() already called',
46 ' ---',
47 ' operator: fail',
48 ' ' + atExpected,
49 ' stack: |-',
50 ' Error: .end() already called',
51 ' [... stack stripped ...]',
52 ' ' + stackExpected,
53 ' [... stack stripped ...]',
54 ' ...',
55 '',
56 '1..2',
57 '# tests 2',
58 '# pass 1',
59 '# fail 1',
60 ].join('\n') + '\n\n');
61 }));
62});