33const { test, beforeEach, afterEach } = require ( 'node:test' )
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 || ( util . nodeMajor === 20 && util . nodeMinor >= 11 )
116
127// `console.table` treats emoji as two character widths for cell width determination
138const Y = process . versions . icu ? '✅' : 'Y '
@@ -51,24 +46,14 @@ test('1 pending interceptor', t => {
5146 mockAgentWithOneInterceptor ( ) . assertNoPendingInterceptors ( { pendingInterceptorsFormatter } )
5247 t . assert . fail ( 'Should have thrown' )
5348 } catch ( err ) {
54- t . assert . deepStrictEqual ( err . message , tableRowsAlignedToLeft
55- ? `
49+ t . assert . deepStrictEqual ( err . message , `
56501 interceptor is pending:
5751
5852┌─────────┬────────┬───────────────────────┬──────┬─────────────┬────────────┬─────────────┬───────────┐
5953│ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │
6054├─────────┼────────┼───────────────────────┼──────┼─────────────┼────────────┼─────────────┼───────────┤
6155│ 0 │ 'GET' │ 'https://example.com' │ '/' │ 200 │ '${ N } ' │ 0 │ 1 │
6256└─────────┴────────┴───────────────────────┴──────┴─────────────┴────────────┴─────────────┴───────────┘
63- ` . trim ( )
64- : `
65- 1 interceptor is pending:
66-
67- ┌─────────┬────────┬───────────────────────┬──────┬─────────────┬────────────┬─────────────┬───────────┐
68- │ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │
69- ├─────────┼────────┼───────────────────────┼──────┼─────────────┼────────────┼─────────────┼───────────┤
70- │ 0 │ 'GET' │ 'https://example.com' │ '/' │ 200 │ '${ N } ' │ 0 │ 1 │
71- └─────────┴────────┴───────────────────────┴──────┴─────────────┴────────────┴─────────────┴───────────┘
7257` . trim ( ) )
7358 }
7459} )
@@ -84,8 +69,7 @@ test('2 pending interceptors', t => {
8469 try {
8570 withTwoInterceptors . assertNoPendingInterceptors ( { pendingInterceptorsFormatter } )
8671 } catch ( err ) {
87- t . assert . deepStrictEqual ( err . message , tableRowsAlignedToLeft
88- ? `
72+ t . assert . deepStrictEqual ( err . message , `
89732 interceptors are pending:
9074
9175┌─────────┬────────┬──────────────────────────┬──────────────┬─────────────┬────────────┬─────────────┬───────────┐
@@ -94,16 +78,6 @@ test('2 pending interceptors', t => {
9478│ 0 │ 'GET' │ 'https://example.com' │ '/' │ 200 │ '${ N } ' │ 0 │ 1 │
9579│ 1 │ 'GET' │ 'https://localhost:9999' │ '/some/path' │ 204 │ '${ N } ' │ 0 │ 1 │
9680└─────────┴────────┴──────────────────────────┴──────────────┴─────────────┴────────────┴─────────────┴───────────┘
97- ` . trim ( )
98- : `
99- 2 interceptors are pending:
100-
101- ┌─────────┬────────┬──────────────────────────┬──────────────┬─────────────┬────────────┬─────────────┬───────────┐
102- │ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │
103- ├─────────┼────────┼──────────────────────────┼──────────────┼─────────────┼────────────┼─────────────┼───────────┤
104- │ 0 │ 'GET' │ 'https://example.com' │ '/' │ 200 │ '${ N } ' │ 0 │ 1 │
105- │ 1 │ 'GET' │ 'https://localhost:9999' │ '/some/path' │ 204 │ '${ N } ' │ 0 │ 1 │
106- └─────────┴────────┴──────────────────────────┴──────────────┴─────────────┴────────────┴─────────────┴───────────┘
10781` . trim ( ) )
10882 }
10983} )
@@ -160,8 +134,7 @@ test('Variations of persist(), times(), and pending status', async t => {
160134 agent . assertNoPendingInterceptors ( { pendingInterceptorsFormatter } )
161135 t . assert . fail ( 'Should have thrown' )
162136 } catch ( err ) {
163- t . assert . deepStrictEqual ( err . message , tableRowsAlignedToLeft
164- ? `
137+ t . assert . deepStrictEqual ( err . message , `
1651384 interceptors are pending:
166139
167140┌─────────┬────────┬──────────────────────────┬──────────────────────┬─────────────┬────────────┬─────────────┬───────────┐
@@ -172,18 +145,6 @@ test('Variations of persist(), times(), and pending status', async t => {
172145│ 2 │ 'GET' │ 'https://localhost:9999' │ '/times/partial' │ 200 │ '${ N } ' │ 1 │ 4 │
173146│ 3 │ 'GET' │ 'https://localhost:9999' │ '/times/unused' │ 200 │ '${ N } ' │ 0 │ 2 │
174147└─────────┴────────┴──────────────────────────┴──────────────────────┴─────────────┴────────────┴─────────────┴───────────┘
175- ` . trim ( )
176- : `
177- 4 interceptors are pending:
178-
179- ┌─────────┬────────┬──────────────────────────┬──────────────────────┬─────────────┬────────────┬─────────────┬───────────┐
180- │ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │
181- ├─────────┼────────┼──────────────────────────┼──────────────────────┼─────────────┼────────────┼─────────────┼───────────┤
182- │ 0 │ 'GET' │ 'https://example.com' │ '/' │ 200 │ '${ N } ' │ 0 │ 1 │
183- │ 1 │ 'GET' │ 'https://localhost:9999' │ '/persistent/unused' │ 200 │ '${ Y } ' │ 0 │ Infinity │
184- │ 2 │ 'GET' │ 'https://localhost:9999' │ '/times/partial' │ 200 │ '${ N } ' │ 1 │ 4 │
185- │ 3 │ 'GET' │ 'https://localhost:9999' │ '/times/unused' │ 200 │ '${ N } ' │ 0 │ 2 │
186- └─────────┴────────┴──────────────────────────┴──────────────────────┴─────────────┴────────────┴─────────────┴───────────┘
187148` . trim ( ) )
188149 }
189150} )
@@ -225,24 +186,14 @@ test('defaults to rendering output with terminal color when process.env.CI is un
225186 mockAgentWithOneInterceptor ( ) . assertNoPendingInterceptors ( )
226187 t . assert . fail ( 'Should have thrown' )
227188 } catch ( err ) {
228- t . assert . deepStrictEqual ( err . message , tableRowsAlignedToLeft
229- ? `
189+ t . assert . deepStrictEqual ( err . message , `
2301901 interceptor is pending:
231191
232192┌─────────┬────────┬───────────────────────┬──────┬─────────────┬────────────┬─────────────┬───────────┐
233193│ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │
234194├─────────┼────────┼───────────────────────┼──────┼─────────────┼────────────┼─────────────┼───────────┤
235195│ 0 │ \u001b[32m'GET'\u001b[39m │ \u001b[32m'https://example.com'\u001b[39m │ \u001b[32m'/'\u001b[39m │ \u001b[33m200\u001b[39m │ \u001b[32m'${ N } '\u001b[39m │ \u001b[33m0\u001b[39m │ \u001b[33m1\u001b[39m │
236196└─────────┴────────┴───────────────────────┴──────┴─────────────┴────────────┴─────────────┴───────────┘
237- ` . trim ( )
238- : `
239- 1 interceptor is pending:
240-
241- ┌─────────┬────────┬───────────────────────┬──────┬─────────────┬────────────┬─────────────┬───────────┐
242- │ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │
243- ├─────────┼────────┼───────────────────────┼──────┼─────────────┼────────────┼─────────────┼───────────┤
244- │ 0 │ \u001b[32m'GET'\u001b[39m │ \u001b[32m'https://example.com'\u001b[39m │ \u001b[32m'/'\u001b[39m │ \u001b[33m200\u001b[39m │ \u001b[32m'${ N } '\u001b[39m │ \u001b[33m0\u001b[39m │ \u001b[33m1\u001b[39m │
245- └─────────┴────────┴───────────────────────┴──────┴─────────────┴────────────┴─────────────┴───────────┘
246197` . trim ( ) )
247198
248199 // Re-set the CI env var if it were set.
0 commit comments