1 | 'use strict';
|
2 |
|
3 | var tap = require('tap');
|
4 | var path = require('path');
|
5 | var spawn = require('child_process').spawn;
|
6 | var concat = require('concat-stream');
|
7 |
|
8 | var stripFullStack = require('./common').stripFullStack;
|
9 |
|
10 | tap.test('callback returning rejected promise should cause that test (and only that test) to fail', function (tt) {
|
11 | tt.plan(1);
|
12 |
|
13 | var ps = spawn(process.execPath, [path.join(__dirname, 'promises', 'fail.js')]);
|
14 |
|
15 | ps.stdout.pipe(concat(function (rows) {
|
16 | var rowsString = rows.toString('utf8');
|
17 |
|
18 | if ((/^skip\n$/).test(rowsString)) {
|
19 | tt.pass('the test file indicated it should be skipped');
|
20 | return;
|
21 | }
|
22 |
|
23 | var strippedString = stripFullStack(rowsString).filter(function (line) {
|
24 | return !(/^(\s+)at(\s+)(?:Test\.)?<anonymous>(?:$|\s)/).test(line);
|
25 | }).join('\n');
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | strippedString = strippedString
|
32 | .replace(/.+at (?:Test\.)?<anonymous>\n.+\[\.\.\. stack stripped \.\.\.\]\n/g, '')
|
33 | .replace(/(?:(.+)\[\.\.\. stack stripped \.\.\.\]\n)+/g, '$1[... stack stripped ...]\n');
|
34 |
|
35 | tt.same(strippedString, [
|
36 | 'TAP version 13',
|
37 | '# promise',
|
38 | 'not ok 1 Error: rejection message',
|
39 | ' ---',
|
40 | ' operator: error',
|
41 | ' stack: |-',
|
42 | ' Error: rejection message',
|
43 | ' at $TEST/promises/fail.js:$LINE:$COL',
|
44 | ' [... stack stripped ...]',
|
45 | ' ...',
|
46 | '# after',
|
47 | 'ok 2 should be truthy',
|
48 | '',
|
49 | '1..2',
|
50 | '# tests 2',
|
51 | '# pass 1',
|
52 | '# fail 1',
|
53 | '',
|
54 | ''
|
55 | ].join('\n'));
|
56 | }));
|
57 | });
|
58 |
|
59 | tap.test('subtest callback returning rejected promise should cause that subtest (and only that subtest) to fail', function (tt) {
|
60 | tt.plan(1);
|
61 |
|
62 | var ps = spawn(process.execPath, [path.join(__dirname, 'promises', 'subTests.js')]);
|
63 |
|
64 | ps.stdout.pipe(concat(function (rows) {
|
65 | var rowsString = rows.toString('utf8');
|
66 |
|
67 | if ((/^skip\n$/).test(rowsString)) {
|
68 | tt.pass('the test file indicated it should be skipped');
|
69 | return;
|
70 | }
|
71 |
|
72 | var strippedString = stripFullStack(rowsString).filter(function (line) {
|
73 | return !(/^(\s+)at(\s+)(?:Test\.)?<anonymous>(?:$|\s)/).test(line);
|
74 | }).join('\n');
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | strippedString = strippedString
|
81 | .replace(/.+at (?:Test\.)?<anonymous>\n.+\[\.\.\. stack stripped \.\.\.\]\n/, '')
|
82 | .replace(/(?:(.+)\[\.\.\. stack stripped \.\.\.\]\n)+/g, '$1[... stack stripped ...]\n');
|
83 |
|
84 | tt.same(stripFullStack(strippedString), [
|
85 | 'TAP version 13',
|
86 | '# promise',
|
87 | '# sub test that should fail',
|
88 | 'not ok 1 Error: rejection message',
|
89 | ' ---',
|
90 | ' operator: error',
|
91 | ' stack: |-',
|
92 | ' Error: rejection message',
|
93 | ' at $TEST/promises/subTests.js:$LINE:$COL',
|
94 | ' [... stack stripped ...]',
|
95 | ' ...',
|
96 | '# sub test that should pass',
|
97 | 'ok 2 should be truthy',
|
98 | '',
|
99 | '1..2',
|
100 | '# tests 2',
|
101 | '# pass 1',
|
102 | '# fail 1',
|
103 | '',
|
104 | ''
|
105 | ]);
|
106 | }));
|
107 | });
|