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 | return tt.pass('the test file indicated it should be skipped');
|
20 | }
|
21 |
|
22 | var strippedString = stripFullStack(rowsString);
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | strippedString = strippedString.replace(/.+at <anonymous>\n.+\[\.\.\. stack stripped \.\.\.\]\n/, '');
|
29 |
|
30 | tt.same(strippedString, [
|
31 | 'TAP version 13',
|
32 | '# promise',
|
33 | 'not ok 1 Error: rejection message',
|
34 | ' ---',
|
35 | ' operator: fail',
|
36 | ' stack: |-',
|
37 | ' Error: Error: rejection message',
|
38 | ' [... stack stripped ...]',
|
39 | ' ...',
|
40 | '# after',
|
41 | 'ok 2 should be truthy',
|
42 | '',
|
43 | '1..2',
|
44 | '# tests 2',
|
45 | '# pass 1',
|
46 | '# fail 1',
|
47 | '',
|
48 | ''
|
49 | ].join('\n'));
|
50 | }));
|
51 | });
|
52 |
|
53 | tap.test('subtest callback returning rejected promise should cause that subtest (and only that subtest) to fail', function (tt) {
|
54 | tt.plan(1);
|
55 |
|
56 | var ps = spawn(process.execPath, [path.join(__dirname, 'promises', 'subTests.js')]);
|
57 |
|
58 | ps.stdout.pipe(concat(function (rows) {
|
59 | var rowsString = rows.toString('utf8');
|
60 |
|
61 | if (/^skip\n$/.test(rowsString)) {
|
62 | return tt.pass('the test file indicated it should be skipped');
|
63 | }
|
64 |
|
65 | var strippedString = stripFullStack(rowsString);
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | strippedString = strippedString.replace(/.+at <anonymous>\n.+\[\.\.\. stack stripped \.\.\.\]\n/, '');
|
72 |
|
73 | tt.same(strippedString, [
|
74 | 'TAP version 13',
|
75 | '# promise',
|
76 | '# sub test that should fail',
|
77 | 'not ok 1 Error: rejection message',
|
78 | ' ---',
|
79 | ' operator: fail',
|
80 | ' stack: |-',
|
81 | ' Error: Error: rejection message',
|
82 | ' [... stack stripped ...]',
|
83 | ' ...',
|
84 | '# sub test that should pass',
|
85 | 'ok 2 should be truthy',
|
86 | '',
|
87 | '1..2',
|
88 | '# tests 2',
|
89 | '# pass 1',
|
90 | '# fail 1',
|
91 | '',
|
92 | ''
|
93 | ].join('\n'));
|
94 | }));
|
95 | });
|