1 | 'use strict';
|
2 |
|
3 | var tape = require('../');
|
4 | var tap = require('tap');
|
5 | var concat = require('concat-stream');
|
6 |
|
7 | var stripFullStack = require('./common').stripFullStack;
|
8 |
|
9 | tap.test('timeoutAfter test', function (tt) {
|
10 | tt.plan(1);
|
11 |
|
12 | var test = tape.createHarness();
|
13 | var tc = function (rows) {
|
14 | tt.same(stripFullStack(rows.toString('utf8')), [
|
15 | 'TAP version 13',
|
16 | '# timeoutAfter',
|
17 | 'not ok 1 timeoutAfter timed out after 1ms',
|
18 | ' ---',
|
19 | ' operator: fail',
|
20 | ' stack: |-',
|
21 | ' Error: timeoutAfter timed out after 1ms',
|
22 | ' [... stack stripped ...]',
|
23 | ' ...',
|
24 | '',
|
25 | '1..1',
|
26 | '# tests 1',
|
27 | '# pass 0',
|
28 | '# fail 1',
|
29 | ''
|
30 | ]);
|
31 | };
|
32 |
|
33 | test.createStream().pipe(concat(tc));
|
34 |
|
35 | test('timeoutAfter', function (t) {
|
36 | t.plan(1);
|
37 | t.timeoutAfter(1);
|
38 | });
|
39 | });
|
40 |
|
41 | tap.test('timeoutAfter with Promises', { skip: typeof Promise === 'undefined' }, function (tt) {
|
42 | tt.plan(1);
|
43 |
|
44 | var test = tape.createHarness();
|
45 | var tc = function (rows) {
|
46 | tt.same(stripFullStack(rows.toString('utf8')), [
|
47 | 'TAP version 13',
|
48 | '# timeoutAfter with promises',
|
49 | '# fulfilled promise',
|
50 | 'not ok 1 fulfilled promise timed out after 1ms',
|
51 | ' ---',
|
52 | ' operator: fail',
|
53 | ' stack: |-',
|
54 | ' Error: fulfilled promise timed out after 1ms',
|
55 | ' [... stack stripped ...]',
|
56 | ' ...',
|
57 | '# rejected promise',
|
58 | 'not ok 2 rejected promise timed out after 1ms',
|
59 | ' ---',
|
60 | ' operator: fail',
|
61 | ' stack: |-',
|
62 | ' Error: rejected promise timed out after 1ms',
|
63 | ' [... stack stripped ...]',
|
64 | ' ...',
|
65 | '',
|
66 | '1..2',
|
67 | '# tests 2',
|
68 | '# pass 0',
|
69 | '# fail 2',
|
70 | ''
|
71 | ]);
|
72 | };
|
73 |
|
74 | test.createStream().pipe(concat(tc));
|
75 |
|
76 | test('timeoutAfter with promises', function (t) {
|
77 | t.plan(2);
|
78 |
|
79 | t.test('fulfilled promise', function (st) {
|
80 | st.plan(1);
|
81 | st.timeoutAfter(1);
|
82 |
|
83 | return new Promise(function (resolve) {
|
84 | setTimeout(function () {
|
85 | resolve();
|
86 | }, 10);
|
87 | });
|
88 | });
|
89 |
|
90 | t.test('rejected promise', function (st) {
|
91 | st.plan(1);
|
92 | st.timeoutAfter(1);
|
93 |
|
94 | return new Promise(function (reject) {
|
95 | setTimeout(function () {
|
96 | reject();
|
97 | }, 10);
|
98 | });
|
99 | });
|
100 | });
|
101 | });
|