Skip to content

Commit 6a30f74

Browse files
authored
test: remove obsolete nodeMajor/nodeMinor util exports (#4976)
1 parent ad6b0c6 commit 6a30f74

2 files changed

Lines changed: 4 additions & 57 deletions

File tree

lib/core/util.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ const { InvalidArgumentError, ConnectTimeoutError } = require('./errors')
1212
const { headerNameLowerCasedRecord } = require('./constants')
1313
const { tree } = require('./tree')
1414

15-
const [nodeMajor, nodeMinor] = process.versions.node.split('.', 2).map(v => Number(v))
16-
1715
class BodyAsyncIterable {
1816
constructor (body) {
1917
this[kBody] = body
@@ -989,8 +987,6 @@ module.exports = {
989987
normalizedMethodRecords,
990988
isValidPort,
991989
isHttpOrHttpsPrefixed,
992-
nodeMajor,
993-
nodeMinor,
994990
safeHTTPMethods: Object.freeze(['GET', 'HEAD', 'OPTIONS', 'TRACE']),
995991
wrapRequestBody,
996992
setupConnectTimeout,

test/mock-interceptor-unused-assertions.js

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
const { test, beforeEach, afterEach } = require('node:test')
44
const { MockAgent, setGlobalDispatcher } = require('..')
55
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 || (util.nodeMajor === 20 && util.nodeMinor >= 11)
116

127
// `console.table` treats emoji as two character widths for cell width determination
138
const 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, `
5650
1 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, `
8973
2 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, `
165138
4 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, `
230190
1 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

Comments
 (0)