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

Commit

Permalink
test: replaces jest with Node.js test runner (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenakh97 authored Nov 14, 2023
1 parent 8c8785b commit a917a93
Show file tree
Hide file tree
Showing 7 changed files with 7,376 additions and 13,092 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ jobs:
- name: Check if source code is properly formatted
run: npx prettier -c ./

- name: Run Unit Tests
run: npm test

- name: Run tests
env:
IOT_HUB_NAME: ${{ needs.test-resources.outputs.app-name }}IotHub
Expand Down
32 changes: 19 additions & 13 deletions feature-runner/steps/device/matchDeviceBoundTopic.spec.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
import assert from 'node:assert'
import { describe, test as it } from 'node:test'
import { matchDeviceBoundTopic } from './matchDeviceBoundTopic'

describe('matchTopic', () => {
it('should match a simple topic', () =>
expect(
void describe('matchTopic', () => {
void it('should match a simple topic', () =>
assert.equal(
matchDeviceBoundTopic(
'devices/49dd7d86-e547-4a4d-8f0f-f4b09591838c/messages/devicebound',
'devices/49dd7d86-e547-4a4d-8f0f-f4b09591838c/messages/devicebound',
),
).toEqual(true))
it('should match topic with a property bag', () =>
expect(
true,
))
void it('should match topic with a property bag', () =>
assert.equal(
matchDeviceBoundTopic(
'devices/49dd7d86-e547-4a4d-8f0f-f4b09591838c/messages/devicebound/pgps=result',
'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',
),
).toEqual(true))
it('should not match topic with a property bag thats not contained', () =>
expect(
true,
))
void it('should not match topic with a property bag thats not contained', () =>
assert.equal(
matchDeviceBoundTopic(
'devices/49dd7d86-e547-4a4d-8f0f-f4b09591838c/messages/devicebound/agps=result',
'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',
),
).toEqual(false))
it('should match a topic regardless of property bag', () =>
expect(
false,
))
void it('should match a topic regardless of property bag', () =>
assert.equal(
matchDeviceBoundTopic(
'devices/49dd7d86-e547-4a4d-8f0f-f4b09591838c/messages/devicebound',
'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',
),
).toEqual(true))
true,
))
})
11 changes: 7 additions & 4 deletions lib/lowerCaseRecord.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import assert from 'node:assert'
import { describe, test as it } from 'node:test'
import { lowerCaseRecord } from './lowerCaseRecord'

describe('lowerCaseRecord', () => {
it('should lower-case all keys', () =>
expect(
void describe('lowerCaseRecord', () => {
void it('should lower-case all keys', () =>
assert.deepStrictEqual(
lowerCaseRecord({
Foo: 'Bar', // will be overwritten by the next key
foo: 'bar',
}),
).toMatchObject({ foo: 'bar' }))
{ foo: 'bar' },
))
})
9 changes: 5 additions & 4 deletions mock-http-api/sortQueryString.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import assert from 'node:assert'
import { describe, test as it } from 'node:test'
import { sortQueryString } from './sortQueryString'

describe('sortQueryString', () => {
it('should sort the query part of a mock URL', () =>
expect(
void describe('sortQueryString', () => {
void it('should sort the query part of a mock URL', () =>
assert.deepStrictEqual(
sortQueryString(
'api.nrfcloud.com/v1/location/agps?eci=73393515&tac=132&requestType=custom&mcc=397&mnc=73&customTypes=2',
),
).toEqual(
'api.nrfcloud.com/v1/location/agps?customTypes=2&eci=73393515&mcc=397&mnc=73&requestType=custom&tac=132',
))
})
19 changes: 11 additions & 8 deletions mock-http-api/splitMockResponse.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import assert from 'node:assert'
import { describe, test as it } from 'node:test'
import { splitMockResponse } from './splitMockResponse'

describe('split mock response', () => {
it('should parse headers and body', () =>
expect(
void describe('split mock response', () => {
void it('should parse headers and body', () =>
assert.deepStrictEqual(
splitMockResponse(`Content-Type: application/octet-stream
(binary A-GPS data) other types`),
).toMatchObject({
headers: {
'Content-Type': 'application/octet-stream',
{
headers: {
'Content-Type': 'application/octet-stream',
},
body: '(binary A-GPS data) other types',
},
body: '(binary A-GPS data) other types',
}))
))
})
Loading

0 comments on commit a917a93

Please sign in to comment.