Skip to content

Commit 59fd5f4

Browse files
authored
chore: use testcontext for mock tests (#4582)
1 parent b902551 commit 59fd5f4

File tree

10 files changed

+762
-933
lines changed

10 files changed

+762
-933
lines changed

test/mock-agent.js

Lines changed: 404 additions & 550 deletions
Large diffs are not rendered by default.

test/mock-call-history-log.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
'use strict'
22

3-
const { tspl } = require('@matteo.collina/tspl')
43
const { test, describe } = require('node:test')
54
const { MockCallHistoryLog } = require('../lib/mock/mock-call-history')
65
const { InvalidArgumentError } = require('../lib/core/errors')
76

87
describe('MockCallHistoryLog - constructor', () => {
98
function assertConsistent (t, mockCallHistoryLog) {
10-
t.strictEqual(mockCallHistoryLog.body, null)
11-
t.strictEqual(mockCallHistoryLog.headers, undefined)
12-
t.deepStrictEqual(mockCallHistoryLog.searchParams, { query: 'value' })
13-
t.strictEqual(mockCallHistoryLog.method, 'PUT')
14-
t.strictEqual(mockCallHistoryLog.origin, 'https://localhost:4000')
15-
t.strictEqual(mockCallHistoryLog.path, '/endpoint')
16-
t.strictEqual(mockCallHistoryLog.hash, '#here')
17-
t.strictEqual(mockCallHistoryLog.protocol, 'https:')
18-
t.strictEqual(mockCallHistoryLog.host, 'localhost:4000')
19-
t.strictEqual(mockCallHistoryLog.port, '4000')
9+
t.assert.strictEqual(mockCallHistoryLog.body, null)
10+
t.assert.strictEqual(mockCallHistoryLog.headers, undefined)
11+
t.assert.deepStrictEqual(mockCallHistoryLog.searchParams, { query: 'value' })
12+
t.assert.strictEqual(mockCallHistoryLog.method, 'PUT')
13+
t.assert.strictEqual(mockCallHistoryLog.origin, 'https://localhost:4000')
14+
t.assert.strictEqual(mockCallHistoryLog.path, '/endpoint')
15+
t.assert.strictEqual(mockCallHistoryLog.hash, '#here')
16+
t.assert.strictEqual(mockCallHistoryLog.protocol, 'https:')
17+
t.assert.strictEqual(mockCallHistoryLog.host, 'localhost:4000')
18+
t.assert.strictEqual(mockCallHistoryLog.port, '4000')
2019
}
2120

2221
test('should populate class properties with query in path', t => {
23-
t = tspl(t, { plan: 10 })
22+
t.plan(10)
2423

2524
const mockCallHistoryLog = new MockCallHistoryLog({
2625
body: null,
@@ -34,7 +33,7 @@ describe('MockCallHistoryLog - constructor', () => {
3433
})
3534

3635
test('should populate class properties with query in argument', t => {
37-
t = tspl(t, { plan: 10 })
36+
t.plan(10)
3837

3938
const mockCallHistoryLog = new MockCallHistoryLog({
4039
body: null,
@@ -49,15 +48,15 @@ describe('MockCallHistoryLog - constructor', () => {
4948
})
5049

5150
test('should throw when url computing failed', t => {
52-
t = tspl(t, { plan: 1 })
51+
t.plan(1)
5352

54-
t.throws(() => new MockCallHistoryLog({}), new InvalidArgumentError('An error occurred when computing MockCallHistoryLog.url'))
53+
t.assert.throws(() => new MockCallHistoryLog({}), new InvalidArgumentError('An error occurred when computing MockCallHistoryLog.url'))
5554
})
5655
})
5756

5857
describe('MockCallHistoryLog - toMap', () => {
5958
test('should return a Map of eleven element', t => {
60-
t = tspl(t, { plan: 1 })
59+
t.plan(1)
6160

6261
const mockCallHistoryLog = new MockCallHistoryLog({
6362
body: '"{}"',
@@ -67,13 +66,13 @@ describe('MockCallHistoryLog - toMap', () => {
6766
path: '/endpoint?query=value#here'
6867
})
6968

70-
t.strictEqual(mockCallHistoryLog.toMap().size, 11)
69+
t.assert.strictEqual(mockCallHistoryLog.toMap().size, 11)
7170
})
7271
})
7372

7473
describe('MockCallHistoryLog - toString', () => {
7574
test('should return a string with all property', t => {
76-
t = tspl(t, { plan: 1 })
75+
t.plan(1)
7776

7877
const mockCallHistoryLog = new MockCallHistoryLog({
7978
body: '"{ "data": "hello" }"',
@@ -83,11 +82,11 @@ describe('MockCallHistoryLog - toString', () => {
8382
path: '/endpoint?query=value#here'
8483
})
8584

86-
t.strictEqual(mockCallHistoryLog.toString(), 'protocol->https:|host->localhost:4000|port->4000|origin->https://localhost:4000|path->/endpoint|hash->#here|searchParams->{"query":"value"}|fullUrl->https://localhost:4000/endpoint?query=value#here|method->PUT|body->"{ "data": "hello" }"|headers->{"content-type":"application/json"}')
85+
t.assert.strictEqual(mockCallHistoryLog.toString(), 'protocol->https:|host->localhost:4000|port->4000|origin->https://localhost:4000|path->/endpoint|hash->#here|searchParams->{"query":"value"}|fullUrl->https://localhost:4000/endpoint?query=value#here|method->PUT|body->"{ "data": "hello" }"|headers->{"content-type":"application/json"}')
8786
})
8887

8988
test('should return a string when headers is an Array of string Array', t => {
90-
t = tspl(t, { plan: 1 })
89+
t.plan(1)
9190

9291
const mockCallHistoryLog = new MockCallHistoryLog({
9392
body: '"{ "data": "hello" }"',
@@ -97,6 +96,6 @@ describe('MockCallHistoryLog - toString', () => {
9796
path: '/endpoint?query=value#here'
9897
})
9998

100-
t.strictEqual(mockCallHistoryLog.toString(), 'protocol->https:|host->localhost:4000|port->4000|origin->https://localhost:4000|path->/endpoint|hash->#here|searchParams->{"query":"value"}|fullUrl->https://localhost:4000/endpoint?query=value#here|method->PUT|body->"{ "data": "hello" }"|headers->["content-type",["application/json","application/xml"]]')
99+
t.assert.strictEqual(mockCallHistoryLog.toString(), 'protocol->https:|host->localhost:4000|port->4000|origin->https://localhost:4000|path->/endpoint|hash->#here|searchParams->{"query":"value"}|fullUrl->https://localhost:4000/endpoint?query=value#here|method->PUT|body->"{ "data": "hello" }"|headers->["content-type",["application/json","application/xml"]]')
101100
})
102101
})

0 commit comments

Comments
 (0)