Skip to content
This repository was archived by the owner on Jul 9, 2024. It is now read-only.

Commit 4d4968d

Browse files
committed
refactor: migrate to Node.js test runner
Closes #592
1 parent 534fdd6 commit 4d4968d

15 files changed

+4373
-8876
lines changed

.husky/pre-commit

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
npx lint-staged && npm test && npx tsc
4+
npx lint-staged
5+
npm test
6+
npx tsc

agps/cacheKey.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { cacheKey } from './cacheKey.js'
2+
import { describe, it } from 'node:test'
3+
import assert from 'node:assert/strict'
24

3-
describe('cacheKey', () => {
4-
it('should create a cache key', () =>
5-
expect(
5+
void describe('cacheKey', () => {
6+
void it('should create a cache key', () =>
7+
assert.equal(
68
cacheKey({
79
binHours: 1,
810
request: {
@@ -13,7 +15,6 @@ describe('cacheKey', () => {
1315
types: [1, 2, 3, 4, 6, 7, 8, 9],
1416
},
1517
}),
16-
).toEqual(
1718
`242-1-21626624-30401-1_2_3_4_6_7_8_9-${new Date()
1819
.toISOString()
1920
.slice(0, 13)

feature-runner/steps/device/encodePropertyBag.spec.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { encodePropertyBag } from './encodePropertyBag.js'
2+
import { describe, it, test } from 'node:test'
3+
import assert from 'node:assert/strict'
4+
void describe('encodePropertyBag', () => {
5+
for (const bag of [undefined, {}]) {
6+
void it(`should return an empty string for ${JSON.stringify(bag)}`, () =>
7+
assert.equal(encodePropertyBag(bag as any), ''))
8+
}
29

3-
describe('encodePropertyBag', () => {
4-
it.each([undefined, {}])('should return an empty string for %j', (bag) =>
5-
expect(encodePropertyBag(bag as any)).toEqual(''),
6-
)
7-
it('should encode a single nulled property', () =>
8-
expect(encodePropertyBag({ batch: null })).toEqual('batch'))
10+
void it('should encode a single nulled property', () =>
11+
assert.equal(encodePropertyBag({ batch: null }), 'batch'))
912

10-
describe('it should encode properties', () => {
11-
it.each([
13+
void describe('it should encode properties', () => {
14+
for (const [props, expected] of [
1215
// Sample from https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-support#receiving-cloud-to-device-messages
1316
// Note: "?" is not included.
1417
[
@@ -26,12 +29,13 @@ describe('encodePropertyBag', () => {
2629
},
2730
'%24.ct=application%2Fjson&%24.ce=utf-8',
2831
],
29-
])('%j => %s', (props, expected) =>
30-
expect(encodePropertyBag(props)).toEqual(expected),
31-
)
32+
]) {
33+
void test(`${JSON.stringify(props)} => ${expected}`, () =>
34+
assert.equal(encodePropertyBag(props as any), expected))
35+
}
3236
})
33-
describe('it should sort $ properties to the end', () => {
34-
it.each([
37+
void describe('it should sort $ properties to the end', () => {
38+
for (const [props, expected] of [
3539
[
3640
{
3741
'$.ct': 'application/json',
@@ -49,8 +53,9 @@ describe('encodePropertyBag', () => {
4953
},
5054
'prop1&prop3=a%20string&%24.ct=application%2Fjson&%24.ce=utf-8',
5155
],
52-
])('%j => %s', (props, expected) =>
53-
expect(encodePropertyBag(props)).toEqual(expected),
54-
)
56+
]) {
57+
void test(`${JSON.stringify(props)} => ${expected}`, () =>
58+
assert.equal(encodePropertyBag(props as any), expected))
59+
}
5560
})
5661
})
Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
import { matchDeviceBoundTopic } from './matchDeviceBoundTopic.js'
2+
import { describe, it } from 'node:test'
3+
import assert from 'node:assert/strict'
24

3-
describe('matchTopic', () => {
4-
it('should match a simple topic', () =>
5-
expect(
5+
void describe('matchTopic', () => {
6+
void it('should match a simple topic', () =>
7+
assert.equal(
68
matchDeviceBoundTopic(
79
'devices/49dd7d86-e547-4a4d-8f0f-f4b09591838c/messages/devicebound',
810
'devices/49dd7d86-e547-4a4d-8f0f-f4b09591838c/messages/devicebound',
911
),
10-
).toEqual(true))
11-
it('should match topic with a property bag', () =>
12-
expect(
12+
true,
13+
))
14+
void it('should match topic with a property bag', () =>
15+
assert.equal(
1316
matchDeviceBoundTopic(
1417
'devices/49dd7d86-e547-4a4d-8f0f-f4b09591838c/messages/devicebound/pgps=result',
1518
'devices/49dd7d86-e547-4a4d-8f0f-f4b09591838c/messages/devicebound/%24.to=%2Fdevices%2F49dd7d86-e547-4a4d-8f0f-f4b09591838c%2Fmessages%2Fdevicebound&pgps=result&%24.ct=application%2Fjson&%24.ce=utf-8',
1619
),
17-
).toEqual(true))
18-
it('should not match topic with a property bag thats not contained', () =>
19-
expect(
20+
true,
21+
))
22+
void it('should not match topic with a property bag thats not contained', () =>
23+
assert.equal(
2024
matchDeviceBoundTopic(
2125
'devices/49dd7d86-e547-4a4d-8f0f-f4b09591838c/messages/devicebound/agps=result',
2226
'devices/49dd7d86-e547-4a4d-8f0f-f4b09591838c/messages/devicebound/%24.to=%2Fdevices%2F49dd7d86-e547-4a4d-8f0f-f4b09591838c%2Fmessages%2Fdevicebound&pgps=result&%24.ct=application%2Fjson&%24.ce=utf-8',
2327
),
24-
).toEqual(false))
25-
it('should match a topic regardless of property bag', () =>
26-
expect(
28+
false,
29+
))
30+
void it('should match a topic regardless of property bag', () =>
31+
assert.equal(
2732
matchDeviceBoundTopic(
2833
'devices/49dd7d86-e547-4a4d-8f0f-f4b09591838c/messages/devicebound',
2934
'devices/49dd7d86-e547-4a4d-8f0f-f4b09591838c/messages/devicebound/%24.to=%2Fdevices%2F49dd7d86-e547-4a4d-8f0f-f4b09591838c%2Fmessages%2Fdevicebound&pgps=result&%24.ct=application%2Fjson&%24.ce=utf-8',
3035
),
31-
).toEqual(true))
36+
true,
37+
))
3238
})

lib/batchToDoc.spec.ts

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { batchToDoc } from './batchToDoc.js'
2+
import { describe, it } from 'node:test'
3+
import assert from 'node:assert/strict'
24

3-
describe('batchToDoc', () => {
4-
it('should convert a batch document to multiple updates', () => {
5-
expect(
5+
void describe('batchToDoc', () => {
6+
void it('should convert a batch document to multiple updates', () => {
7+
assert.deepEqual(
68
batchToDoc({
79
gnss: [
810
{
@@ -29,33 +31,34 @@ describe('batchToDoc', () => {
2931
},
3032
],
3133
}),
32-
).toEqual([
33-
{
34-
gnss: {
35-
v: {
36-
lng: 8.669555,
37-
lat: 50.109177,
38-
acc: 28.032738,
39-
alt: 204.623276,
40-
spd: 0.698944,
41-
hdg: 0,
34+
[
35+
{
36+
gnss: {
37+
v: {
38+
lng: 8.669555,
39+
lat: 50.109177,
40+
acc: 28.032738,
41+
alt: 204.623276,
42+
spd: 0.698944,
43+
hdg: 0,
44+
},
45+
ts: 1567094051000,
4246
},
43-
ts: 1567094051000,
4447
},
45-
},
46-
{
47-
gnss: {
48-
v: {
49-
lng: 10.424793,
50-
lat: 63.422975,
51-
acc: 12.276645,
52-
alt: 137.319351,
53-
spd: 6.308265,
54-
hdg: 77.472923,
48+
{
49+
gnss: {
50+
v: {
51+
lng: 10.424793,
52+
lat: 63.422975,
53+
acc: 12.276645,
54+
alt: 137.319351,
55+
spd: 6.308265,
56+
hdg: 77.472923,
57+
},
58+
ts: 1567165503000,
5559
},
56-
ts: 1567165503000,
5760
},
58-
},
59-
])
61+
],
62+
)
6063
})
6164
})

lib/lowerCaseRecord.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { lowerCaseRecord } from './lowerCaseRecord.js'
2+
import { describe, it } from 'node:test'
3+
import assert from 'node:assert/strict'
24

3-
describe('lowerCaseRecord', () => {
4-
it('should lower-case all keys', () =>
5-
expect(
5+
void describe('lowerCaseRecord', () => {
6+
void it('should lower-case all keys', () =>
7+
assert.deepEqual(
68
lowerCaseRecord({
79
Foo: 'Bar', // will be overwritten by the next key
810
foo: 'bar',
911
}),
10-
).toMatchObject({ foo: 'bar' }))
12+
{ foo: 'bar' },
13+
))
1114
})

lib/parseConnectionString.spec.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { parseConnectionString } from './parseConnectionString.js'
2-
3-
describe('parseConnectionString', () => {
4-
it('should parse a connection string', () => {
5-
expect(
2+
import { describe, it } from 'node:test'
3+
import assert from 'node:assert/strict'
4+
void describe('parseConnectionString', () => {
5+
void it('should parse a connection string', () => {
6+
assert.deepEqual(
67
parseConnectionString(
78
'AccountEndpoint=https://xxxx.documents.azure.com:443/;AccountKey=oKHTAxxx92GKkq3CDzeCd1WYnVslfIUaQqOa7Xw==;',
89
),
9-
).toEqual({
10-
AccountEndpoint: 'https://xxxx.documents.azure.com:443/',
11-
AccountKey: 'oKHTAxxx92GKkq3CDzeCd1WYnVslfIUaQqOa7Xw==',
12-
})
10+
{
11+
AccountEndpoint: 'https://xxxx.documents.azure.com:443/',
12+
AccountKey: 'oKHTAxxx92GKkq3CDzeCd1WYnVslfIUaQqOa7Xw==',
13+
},
14+
)
1315
})
1416
})

mock-http-api/sortQueryString.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { sortQueryString } from './sortQueryString.js'
2-
3-
describe('sortQueryString', () => {
4-
it('should sort the query part of a mock URL', () =>
5-
expect(
2+
import { describe, it } from 'node:test'
3+
import assert from 'node:assert'
4+
void describe('sortQueryString', () => {
5+
void it('should sort the query part of a mock URL', () =>
6+
assert.equal(
67
sortQueryString(
78
'api.nrfcloud.com/v1/location/agps?eci=73393515&tac=132&requestType=custom&mcc=397&mnc=73&customTypes=2',
89
),
9-
).toEqual(
1010
'api.nrfcloud.com/v1/location/agps?customTypes=2&eci=73393515&mcc=397&mnc=73&requestType=custom&tac=132',
1111
))
1212
})
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { splitMockResponse } from './splitMockResponse.js'
2-
3-
describe('split mock response', () => {
4-
it('should parse headers and body', () =>
5-
expect(
2+
import { describe, it } from 'node:test'
3+
import assert from 'node:assert'
4+
void describe('split mock response', () => {
5+
void it('should parse headers and body', () =>
6+
assert.deepEqual(
67
splitMockResponse(`Content-Type: application/octet-stream
78
89
(binary A-GNSS data) other types`),
9-
).toMatchObject({
10-
headers: {
11-
'Content-Type': 'application/octet-stream',
10+
{
11+
headers: {
12+
'Content-Type': 'application/octet-stream',
13+
},
14+
body: '(binary A-GNSS data) other types',
1215
},
13-
body: '(binary A-GNSS data) other types',
14-
}))
16+
))
1517
})

pack/flattenDependencies.spec.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { flattenDependencies } from './flattenDependencies.js'
2-
3-
describe('flattenDependencies', () => {
4-
it('should flatten dependencies', () =>
5-
expect(
2+
import { describe, it } from 'node:test'
3+
import assert from 'node:assert'
4+
void describe('flattenDependencies', () => {
5+
void it('should flatten dependencies', () =>
6+
assert.deepEqual(
67
flattenDependencies({
78
'/mock-http-api/mock-http-api.js': {
89
'/lib/log.js': {},
@@ -13,11 +14,12 @@ describe('flattenDependencies', () => {
1314
'/lib/fromEnv.js': {},
1415
},
1516
}),
16-
).toEqual([
17-
'/lib/fromEnv.js',
18-
'/lib/http.js',
19-
'/lib/log.js',
20-
'/lib/request.js',
21-
'/mock-http-api/mock-http-api.js',
22-
]))
17+
[
18+
'/lib/fromEnv.js',
19+
'/lib/http.js',
20+
'/lib/log.js',
21+
'/lib/request.js',
22+
'/mock-http-api/mock-http-api.js',
23+
],
24+
))
2325
})

0 commit comments

Comments
 (0)