33const { test, beforeEach, afterEach } = require ( 'tap' )
44const { MockAgent, setGlobalDispatcher } = require ( '..' )
55const 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
611
712// Avoid colors in the output for inline snapshots.
813const pendingInterceptorsFormatter = new PendingInterceptorsFormatter ( { disableColors : true } )
@@ -40,7 +45,17 @@ test('1 pending interceptor', t => {
4045
4146 const err = t . throws ( ( ) => mockAgentWithOneInterceptor ( ) . assertNoPendingInterceptors ( { pendingInterceptorsFormatter } ) )
4247
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+ : `
44591 interceptor is pending:
4560
4661┌─────────┬────────┬───────────────────────┬──────┬─────────────┬────────────┬─────────────┬───────────┐
@@ -61,7 +76,18 @@ test('2 pending interceptors', t => {
6176 . reply ( 204 , 'OK' )
6277 const err = t . throws ( ( ) => withTwoInterceptors . assertNoPendingInterceptors ( { pendingInterceptorsFormatter } ) )
6378
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+ : `
65912 interceptors are pending:
6692
6793┌─────────┬────────┬──────────────────────────┬──────────────┬─────────────┬────────────┬─────────────┬───────────┐
@@ -123,7 +149,20 @@ test('Variations of persist(), times(), and pending status', async t => {
123149
124150 const err = t . throws ( ( ) => agent . assertNoPendingInterceptors ( { pendingInterceptorsFormatter } ) )
125151
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+ : `
1271664 interceptors are pending:
128167
129168┌─────────┬────────┬──────────────────────────┬──────────────────────┬─────────────┬────────────┬─────────────┬───────────┐
@@ -172,7 +211,17 @@ test('defaults to rendering output with terminal color when process.env.CI is un
172211
173212 const err = t . throws (
174213 ( ) => 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+ : `
1762251 interceptor is pending:
177226
178227┌─────────┬────────┬───────────────────────┬──────┬─────────────┬────────────┬─────────────┬───────────┐
0 commit comments