3
3
const { test, beforeEach, afterEach } = require ( 'tap' )
4
4
const { MockAgent, setGlobalDispatcher } = require ( '..' )
5
5
const PendingInterceptorsFormatter = require ( '../lib/mock/pending-interceptors-formatter' )
6
+ const util = require ( '../lib/core/util' )
7
+
8
+ // Since Node.js v21 `console.table` rows are aligned to the left
9
+ // https://github.com/nodejs/node/pull/50135
10
+ const tableRowsAlignedToLeft = util . nodeMajor >= 21
6
11
7
12
// Avoid colors in the output for inline snapshots.
8
13
const pendingInterceptorsFormatter = new PendingInterceptorsFormatter ( { disableColors : true } )
@@ -40,7 +45,17 @@ test('1 pending interceptor', t => {
40
45
41
46
const err = t . throws ( ( ) => mockAgentWithOneInterceptor ( ) . assertNoPendingInterceptors ( { pendingInterceptorsFormatter } ) )
42
47
43
- t . same ( err . message , `
48
+ t . same ( err . message , tableRowsAlignedToLeft
49
+ ? `
50
+ 1 interceptor is pending:
51
+
52
+ ┌─────────┬────────┬───────────────────────┬──────┬─────────────┬────────────┬─────────────┬───────────┐
53
+ │ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │
54
+ ├─────────┼────────┼───────────────────────┼──────┼─────────────┼────────────┼─────────────┼───────────┤
55
+ │ 0 │ 'GET' │ 'https://example.com' │ '/' │ 200 │ '❌' │ 0 │ 1 │
56
+ └─────────┴────────┴───────────────────────┴──────┴─────────────┴────────────┴─────────────┴───────────┘
57
+ ` . trim ( )
58
+ : `
44
59
1 interceptor is pending:
45
60
46
61
┌─────────┬────────┬───────────────────────┬──────┬─────────────┬────────────┬─────────────┬───────────┐
@@ -61,7 +76,18 @@ test('2 pending interceptors', t => {
61
76
. reply ( 204 , 'OK' )
62
77
const err = t . throws ( ( ) => withTwoInterceptors . assertNoPendingInterceptors ( { pendingInterceptorsFormatter } ) )
63
78
64
- t . same ( err . message , `
79
+ t . same ( err . message , tableRowsAlignedToLeft
80
+ ? `
81
+ 2 interceptors are pending:
82
+
83
+ ┌─────────┬────────┬──────────────────────────┬──────────────┬─────────────┬────────────┬─────────────┬───────────┐
84
+ │ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │
85
+ ├─────────┼────────┼──────────────────────────┼──────────────┼─────────────┼────────────┼─────────────┼───────────┤
86
+ │ 0 │ 'GET' │ 'https://example.com' │ '/' │ 200 │ '❌' │ 0 │ 1 │
87
+ │ 1 │ 'GET' │ 'https://localhost:9999' │ '/some/path' │ 204 │ '❌' │ 0 │ 1 │
88
+ └─────────┴────────┴──────────────────────────┴──────────────┴─────────────┴────────────┴─────────────┴───────────┘
89
+ ` . trim ( )
90
+ : `
65
91
2 interceptors are pending:
66
92
67
93
┌─────────┬────────┬──────────────────────────┬──────────────┬─────────────┬────────────┬─────────────┬───────────┐
@@ -123,7 +149,20 @@ test('Variations of persist(), times(), and pending status', async t => {
123
149
124
150
const err = t . throws ( ( ) => agent . assertNoPendingInterceptors ( { pendingInterceptorsFormatter } ) )
125
151
126
- t . same ( err . message , `
152
+ t . same ( err . message , tableRowsAlignedToLeft
153
+ ? `
154
+ 4 interceptors are pending:
155
+
156
+ ┌─────────┬────────┬──────────────────────────┬──────────────────────┬─────────────┬────────────┬─────────────┬───────────┐
157
+ │ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │
158
+ ├─────────┼────────┼──────────────────────────┼──────────────────────┼─────────────┼────────────┼─────────────┼───────────┤
159
+ │ 0 │ 'GET' │ 'https://example.com' │ '/' │ 200 │ '❌' │ 0 │ 1 │
160
+ │ 1 │ 'GET' │ 'https://localhost:9999' │ '/persistent/unused' │ 200 │ '✅' │ 0 │ Infinity │
161
+ │ 2 │ 'GET' │ 'https://localhost:9999' │ '/times/partial' │ 200 │ '❌' │ 1 │ 4 │
162
+ │ 3 │ 'GET' │ 'https://localhost:9999' │ '/times/unused' │ 200 │ '❌' │ 0 │ 2 │
163
+ └─────────┴────────┴──────────────────────────┴──────────────────────┴─────────────┴────────────┴─────────────┴───────────┘
164
+ ` . trim ( )
165
+ : `
127
166
4 interceptors are pending:
128
167
129
168
┌─────────┬────────┬──────────────────────────┬──────────────────────┬─────────────┬────────────┬─────────────┬───────────┐
@@ -172,7 +211,17 @@ test('defaults to rendering output with terminal color when process.env.CI is un
172
211
173
212
const err = t . throws (
174
213
( ) => mockAgentWithOneInterceptor ( ) . assertNoPendingInterceptors ( ) )
175
- t . same ( err . message , `
214
+ t . same ( err . message , tableRowsAlignedToLeft
215
+ ? `
216
+ 1 interceptor is pending:
217
+
218
+ ┌─────────┬────────┬───────────────────────┬──────┬─────────────┬────────────┬─────────────┬───────────┐
219
+ │ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │
220
+ ├─────────┼────────┼───────────────────────┼──────┼─────────────┼────────────┼─────────────┼───────────┤
221
+ │ 0 │ \u001b[32m'GET'\u001b[39m │ \u001b[32m'https://example.com'\u001b[39m │ \u001b[32m'/'\u001b[39m │ \u001b[33m200\u001b[39m │ \u001b[32m'❌'\u001b[39m │ \u001b[33m0\u001b[39m │ \u001b[33m1\u001b[39m │
222
+ └─────────┴────────┴───────────────────────┴──────┴─────────────┴────────────┴─────────────┴───────────┘
223
+ ` . trim ( )
224
+ : `
176
225
1 interceptor is pending:
177
226
178
227
┌─────────┬────────┬───────────────────────┬──────┬─────────────┬────────────┬─────────────┬───────────┐
0 commit comments