From 36d44980b16693bcdb6f686f8030aa17382e9b9a Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 22 Nov 2024 09:16:34 +0100 Subject: [PATCH 1/5] chore: add test-result action --- .github/workflows/mqttjs-test.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/mqttjs-test.yml b/.github/workflows/mqttjs-test.yml index e735065bf..dabcb399c 100644 --- a/.github/workflows/mqttjs-test.yml +++ b/.github/workflows/mqttjs-test.yml @@ -54,4 +54,15 @@ jobs: name: codecov-mqttjs token: ${{ secrets.CODECOV_TOKEN }} verbose: true + + - name: Upload test results to Codecov + if: ${{ !cancelled() }} + uses: codecov/test-results-action@v1 + with: + directory: ./coverage/ + fail_ci_if_error: false + flags: unittests + name: codecov-mqttjs + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true From 74b5dae16753a283ba481c4fa7f96f668c3f887d Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 22 Nov 2024 09:19:27 +0100 Subject: [PATCH 2/5] chore: add coment --- .github/workflows/mqttjs-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/mqttjs-test.yml b/.github/workflows/mqttjs-test.yml index dabcb399c..d431c6e70 100644 --- a/.github/workflows/mqttjs-test.yml +++ b/.github/workflows/mqttjs-test.yml @@ -45,6 +45,7 @@ jobs: DEBUG: "${{ runner.debug == '1' && 'mqttjs:*' || '' }}" # upload coverage to Codecov + # https://app.codecov.io/gh/mqttjs/MQTT.js - name: Upload coverage to Codecov uses: codecov/codecov-action@v5 with: From 80f664c25de52289e41994ea3431cc8eb8a425cf Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 22 Nov 2024 10:04:43 +0100 Subject: [PATCH 3/5] chore: use nodejs test runner options --- .github/workflows/mqttjs-test.yml | 8 ++--- .gitignore | 1 + nyc.config.js | 2 +- package.json | 4 +-- test/runTests.ts | 57 ------------------------------- 5 files changed, 8 insertions(+), 64 deletions(-) delete mode 100644 test/runTests.ts diff --git a/.github/workflows/mqttjs-test.yml b/.github/workflows/mqttjs-test.yml index d431c6e70..c17b610d5 100644 --- a/.github/workflows/mqttjs-test.yml +++ b/.github/workflows/mqttjs-test.yml @@ -50,7 +50,7 @@ jobs: uses: codecov/codecov-action@v5 with: directory: ./coverage/ - fail_ci_if_error: false + fail_ci_if_error: true flags: unittests name: codecov-mqttjs token: ${{ secrets.CODECOV_TOKEN }} @@ -60,10 +60,10 @@ jobs: if: ${{ !cancelled() }} uses: codecov/test-results-action@v1 with: - directory: ./coverage/ + files: ./junit.xml fail_ci_if_error: false - flags: unittests - name: codecov-mqttjs + flags: unittests-results + name: codecov-mqttjs-test-results token: ${{ secrets.CODECOV_TOKEN }} verbose: true diff --git a/.gitignore b/.gitignore index 13052c8f8..8e250b58e 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ test/typescript/*.map **/typings/** .vscode/ .npmrc +junit.xml /build/ diff --git a/nyc.config.js b/nyc.config.js index 5699f9095..fbe162187 100644 --- a/nyc.config.js +++ b/nyc.config.js @@ -11,7 +11,7 @@ module.exports = { ], reporter: [ 'text', - 'lcov', + 'lcov' ], branches: 80, functions: 89, diff --git a/package.json b/package.json index de1cf843f..2d26a749b 100644 --- a/package.json +++ b/package.json @@ -63,9 +63,9 @@ "build:browser": "node esbuild.js", "build": "npm run build:ts && npm run build:browser", "prepare": "npm run build", - "unit-test:node": "node_modules/.bin/nyc node -r esbuild-register test/runTests.ts", + "unit-test:node": "node -r esbuild-register --test-concurrency 4 --test-reporter=junit --test-reporter-destination=junit.xml --test-reporter=spec --test-reporter-destination=stdout --test test/*.ts ", "unit-test:browser": "wtr", - "test:node": "npm run unit-test:node", + "test:node": "node_modules/.bin/nyc npm run unit-test:node", "test:browser": "npm run build && npm run unit-test:browser", "test": "npm run test:node", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md", diff --git a/test/runTests.ts b/test/runTests.ts deleted file mode 100644 index 57c5663b6..000000000 --- a/test/runTests.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { readdirSync } from 'node:fs' -import { run } from 'node:test' -import process from 'node:process' -import { spec as Spec } from 'node:test/reporters' -import { basename } from 'node:path' -import { cpus } from 'node:os' - -const spec = new Spec() - -let exitCode = 0 - -const files = readdirSync(__dirname) - .filter((f) => f.endsWith('.ts') && f !== basename(__filename)) - .map((f) => `${__dirname}/${f}`) - -const start = Date.now() - -const testStream = run({ - files, - timeout: 60 * 1000, - concurrency: cpus().length, -}) - -testStream.compose(spec).pipe(process.stdout) - -const summary: string[] = [] - -testStream.on('test:fail', (data) => { - exitCode = 1 - const error = data.details.error - - summary.push( - `${data.file} - "${data.name}" (${Math.round( - data.details.duration_ms, - )}ms)\n${error.toString()} `, - ) -}) - -testStream.on('test:stderr', (data) => { - summary.push(`${data.file} - Error:\n${data.message} `) -}) - -testStream.once('end', () => { - const duration = Date.now() - start - // print duration in blue - console.log( - '\x1b[34m%s\x1b[0m', - `\nℹ Duration: ${duration / 1000}s\n`, - '\x1b[0m', - ) - if (summary.length > 0) { - console.error('\x1b[31m%s\x1b', '\n✖ failing tests:\n') - console.error(summary.join('\n')) - console.error('\n------', '\x1b[0m\n') - } - process.exit(exitCode) -}) From a6bbd9067cdd65698fdd5fec5ca6e3060bfe8c39 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 22 Nov 2024 10:10:49 +0100 Subject: [PATCH 4/5] fix: move nodejs tests to `node` folder --- package.json | 2 +- test/{ => node}/abstract_client.ts | 10 +++++----- test/{ => node}/abstract_store.ts | 2 +- test/{ => node}/certs/server-cert.pem | 0 test/{ => node}/certs/server-key.pem | 0 test/{ => node}/client.ts | 4 ++-- test/{ => node}/client_mqtt5.ts | 2 +- test/{ => node}/helpers/TeardownHelper.ts | 0 test/{ => node}/helpers/leaked.ts | 0 test/{ => node}/helpers/port_list.ts | 0 test/{ => node}/helpers/private-csr.pem | 0 test/{ => node}/helpers/private-key.pem | 0 test/{ => node}/helpers/public-cert.pem | 0 test/{ => node}/helpers/public-key.pem | 0 test/{ => node}/helpers/server.ts | 0 test/{ => node}/helpers/server_process.ts | 0 test/{ => node}/helpers/tls-cert.pem | 0 test/{ => node}/helpers/tls-key.pem | 0 test/{ => node}/helpers/wrong-cert.pem | 0 test/{ => node}/helpers/wrong-csr.pem | 0 test/{ => node}/helpers/wrong-key.pem | 0 test/{ => node}/keepaliveManager.ts | 2 +- test/{ => node}/message-id-provider.ts | 2 +- test/{ => node}/mqtt.ts | 2 +- test/{ => node}/mqtt_store.ts | 2 +- test/{ => node}/secure_client.ts | 2 +- test/{ => node}/server.ts | 0 test/{ => node}/server_helpers_for_client_tests.ts | 0 test/{ => node}/store.ts | 2 +- test/{ => node}/unique_message_id_provider_client.ts | 2 +- test/{ => node}/util.ts | 0 test/{ => node}/websocket_client.ts | 2 +- 32 files changed, 18 insertions(+), 18 deletions(-) rename test/{ => node}/abstract_client.ts (99%) rename test/{ => node}/abstract_store.ts (98%) rename test/{ => node}/certs/server-cert.pem (100%) rename test/{ => node}/certs/server-key.pem (100%) rename test/{ => node}/client.ts (99%) rename test/{ => node}/client_mqtt5.ts (99%) rename test/{ => node}/helpers/TeardownHelper.ts (100%) rename test/{ => node}/helpers/leaked.ts (100%) rename test/{ => node}/helpers/port_list.ts (100%) rename test/{ => node}/helpers/private-csr.pem (100%) rename test/{ => node}/helpers/private-key.pem (100%) rename test/{ => node}/helpers/public-cert.pem (100%) rename test/{ => node}/helpers/public-key.pem (100%) rename test/{ => node}/helpers/server.ts (100%) rename test/{ => node}/helpers/server_process.ts (100%) rename test/{ => node}/helpers/tls-cert.pem (100%) rename test/{ => node}/helpers/tls-key.pem (100%) rename test/{ => node}/helpers/wrong-cert.pem (100%) rename test/{ => node}/helpers/wrong-csr.pem (100%) rename test/{ => node}/helpers/wrong-key.pem (100%) rename test/{ => node}/keepaliveManager.ts (97%) rename test/{ => node}/message-id-provider.ts (99%) rename test/{ => node}/mqtt.ts (99%) rename test/{ => node}/mqtt_store.ts (88%) rename test/{ => node}/secure_client.ts (99%) rename test/{ => node}/server.ts (100%) rename test/{ => node}/server_helpers_for_client_tests.ts (100%) rename test/{ => node}/store.ts (82%) rename test/{ => node}/unique_message_id_provider_client.ts (91%) rename test/{ => node}/util.ts (100%) rename test/{ => node}/websocket_client.ts (99%) diff --git a/package.json b/package.json index 2d26a749b..855a210b2 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "build:browser": "node esbuild.js", "build": "npm run build:ts && npm run build:browser", "prepare": "npm run build", - "unit-test:node": "node -r esbuild-register --test-concurrency 4 --test-reporter=junit --test-reporter-destination=junit.xml --test-reporter=spec --test-reporter-destination=stdout --test test/*.ts ", + "unit-test:node": "node -r esbuild-register --test-concurrency 4 --test-reporter=junit --test-reporter-destination=junit.xml --test-reporter=spec --test-reporter-destination=stdout --test test/node/*.ts ", "unit-test:browser": "wtr", "test:node": "node_modules/.bin/nyc npm run unit-test:node", "test:browser": "npm run build && npm run unit-test:browser", diff --git a/test/abstract_client.ts b/test/node/abstract_client.ts similarity index 99% rename from test/abstract_client.ts rename to test/node/abstract_client.ts index df468b69c..3aaadf725 100644 --- a/test/abstract_client.ts +++ b/test/node/abstract_client.ts @@ -5,19 +5,19 @@ import { assert } from 'chai' import sinon from 'sinon' import fs from 'fs' import levelStore from 'mqtt-level-store' -import Store from '../src/lib/store' +import Store from '../../src/lib/store' import serverBuilderFn from './server_helpers_for_client_tests' -import handlePubrel from '../src/lib/handlers/pubrel' +import handlePubrel from '../../src/lib/handlers/pubrel' import TeardownHelper from './helpers/TeardownHelper' -import handle from '../src/lib/handlers/index' -import handlePublish from '../src/lib/handlers/publish' +import handle from '../../src/lib/handlers/index' +import handlePublish from '../../src/lib/handlers/publish' import mqtt, { IClientOptions, IClientPublishOptions, IClientSubscribeOptions, ISubscriptionMap, ISubscriptionRequest, -} from '../src' +} from '../../src' import { IPublishPacket, IPubrelPacket, ISubackPacket, QoS } from 'mqtt-packet' import { DoneCallback, ErrorWithReasonCode } from 'src/lib/shared' import { fail } from 'assert' diff --git a/test/abstract_store.ts b/test/node/abstract_store.ts similarity index 98% rename from test/abstract_store.ts rename to test/node/abstract_store.ts index dc3ab81da..442ba6501 100644 --- a/test/abstract_store.ts +++ b/test/node/abstract_store.ts @@ -1,5 +1,5 @@ import { IPublishPacket, IPubrelPacket } from 'mqtt-packet' -import { IStore } from '../src' +import { IStore } from '../../src' import 'should' import { it, beforeEach, afterEach } from 'node:test' diff --git a/test/certs/server-cert.pem b/test/node/certs/server-cert.pem similarity index 100% rename from test/certs/server-cert.pem rename to test/node/certs/server-cert.pem diff --git a/test/certs/server-key.pem b/test/node/certs/server-key.pem similarity index 100% rename from test/certs/server-key.pem rename to test/node/certs/server-key.pem diff --git a/test/client.ts b/test/node/client.ts similarity index 99% rename from test/client.ts rename to test/node/client.ts index 88ca6f016..6c416c03e 100644 --- a/test/client.ts +++ b/test/node/client.ts @@ -1,5 +1,5 @@ import { useFakeTimers } from 'sinon' -import mqtt from '../src' +import mqtt from '../../src' import { assert } from 'chai' import { fork } from 'child_process' import path from 'path' @@ -18,7 +18,7 @@ import { IClientOptions } from 'src/lib/client' import { describe, it, after } from 'node:test' // eslint-disable-next-line @typescript-eslint/no-var-requires -const pkgJson = require('../package.json') +const pkgJson = require('../../package.json') const debug = _debug('mqttjs:client-test') diff --git a/test/client_mqtt5.ts b/test/node/client_mqtt5.ts similarity index 99% rename from test/client_mqtt5.ts rename to test/node/client_mqtt5.ts index b22340326..beda95a93 100644 --- a/test/client_mqtt5.ts +++ b/test/node/client_mqtt5.ts @@ -3,7 +3,7 @@ import abstractClientTests from './abstract_client' import { MqttServer } from './server' import serverBuilder from './server_helpers_for_client_tests' import getPorts from './helpers/port_list' -import mqtt, { ErrorWithReasonCode } from '../src' +import mqtt, { ErrorWithReasonCode } from '../../src' import { after, describe, it } from 'node:test' const ports = getPorts(1) diff --git a/test/helpers/TeardownHelper.ts b/test/node/helpers/TeardownHelper.ts similarity index 100% rename from test/helpers/TeardownHelper.ts rename to test/node/helpers/TeardownHelper.ts diff --git a/test/helpers/leaked.ts b/test/node/helpers/leaked.ts similarity index 100% rename from test/helpers/leaked.ts rename to test/node/helpers/leaked.ts diff --git a/test/helpers/port_list.ts b/test/node/helpers/port_list.ts similarity index 100% rename from test/helpers/port_list.ts rename to test/node/helpers/port_list.ts diff --git a/test/helpers/private-csr.pem b/test/node/helpers/private-csr.pem similarity index 100% rename from test/helpers/private-csr.pem rename to test/node/helpers/private-csr.pem diff --git a/test/helpers/private-key.pem b/test/node/helpers/private-key.pem similarity index 100% rename from test/helpers/private-key.pem rename to test/node/helpers/private-key.pem diff --git a/test/helpers/public-cert.pem b/test/node/helpers/public-cert.pem similarity index 100% rename from test/helpers/public-cert.pem rename to test/node/helpers/public-cert.pem diff --git a/test/helpers/public-key.pem b/test/node/helpers/public-key.pem similarity index 100% rename from test/helpers/public-key.pem rename to test/node/helpers/public-key.pem diff --git a/test/helpers/server.ts b/test/node/helpers/server.ts similarity index 100% rename from test/helpers/server.ts rename to test/node/helpers/server.ts diff --git a/test/helpers/server_process.ts b/test/node/helpers/server_process.ts similarity index 100% rename from test/helpers/server_process.ts rename to test/node/helpers/server_process.ts diff --git a/test/helpers/tls-cert.pem b/test/node/helpers/tls-cert.pem similarity index 100% rename from test/helpers/tls-cert.pem rename to test/node/helpers/tls-cert.pem diff --git a/test/helpers/tls-key.pem b/test/node/helpers/tls-key.pem similarity index 100% rename from test/helpers/tls-key.pem rename to test/node/helpers/tls-key.pem diff --git a/test/helpers/wrong-cert.pem b/test/node/helpers/wrong-cert.pem similarity index 100% rename from test/helpers/wrong-cert.pem rename to test/node/helpers/wrong-cert.pem diff --git a/test/helpers/wrong-csr.pem b/test/node/helpers/wrong-csr.pem similarity index 100% rename from test/helpers/wrong-csr.pem rename to test/node/helpers/wrong-csr.pem diff --git a/test/helpers/wrong-key.pem b/test/node/helpers/wrong-key.pem similarity index 100% rename from test/helpers/wrong-key.pem rename to test/node/helpers/wrong-key.pem diff --git a/test/keepaliveManager.ts b/test/node/keepaliveManager.ts similarity index 97% rename from test/keepaliveManager.ts rename to test/node/keepaliveManager.ts index 91d5a24a4..a51bbd54b 100644 --- a/test/keepaliveManager.ts +++ b/test/node/keepaliveManager.ts @@ -1,5 +1,5 @@ import { afterEach, beforeEach, describe, it } from 'node:test' -import KeepaliveManager from '../src/lib/KeepaliveManager' +import KeepaliveManager from '../../src/lib/KeepaliveManager' import { assert } from 'chai' import { useFakeTimers, spy, stub } from 'sinon' import { MqttClient } from 'src' diff --git a/test/message-id-provider.ts b/test/node/message-id-provider.ts similarity index 99% rename from test/message-id-provider.ts rename to test/node/message-id-provider.ts index 897b5f269..1f4508e8a 100644 --- a/test/message-id-provider.ts +++ b/test/node/message-id-provider.ts @@ -1,5 +1,5 @@ import { assert } from 'chai' -import { DefaultMessageIdProvider, UniqueMessageIdProvider } from '../src' +import { DefaultMessageIdProvider, UniqueMessageIdProvider } from '../../src' import { describe, it } from 'node:test' describe('message id provider', () => { diff --git a/test/mqtt.ts b/test/node/mqtt.ts similarity index 99% rename from test/mqtt.ts rename to test/node/mqtt.ts index c76f90873..ab1bd7338 100644 --- a/test/mqtt.ts +++ b/test/node/mqtt.ts @@ -1,6 +1,6 @@ import fs from 'fs' import path from 'path' -import mqtt, { IClientOptions } from '../src' +import mqtt, { IClientOptions } from '../../src' import { describe, it } from 'node:test' import 'should' diff --git a/test/mqtt_store.ts b/test/node/mqtt_store.ts similarity index 88% rename from test/mqtt_store.ts rename to test/node/mqtt_store.ts index 157158fad..95ec180c3 100644 --- a/test/mqtt_store.ts +++ b/test/node/mqtt_store.ts @@ -1,4 +1,4 @@ -import { Store } from '../src' +import { Store } from '../../src' import { describe, it } from 'node:test' import 'should' diff --git a/test/secure_client.ts b/test/node/secure_client.ts similarity index 99% rename from test/secure_client.ts rename to test/node/secure_client.ts index ba81b5413..3b66890bb 100644 --- a/test/secure_client.ts +++ b/test/node/secure_client.ts @@ -1,6 +1,6 @@ import path from 'path' import fs from 'fs' -import mqtt from '../src' +import mqtt from '../../src' import abstractClientTests from './abstract_client' import { MqttSecureServer, MqttServerListener } from './server' import { assert } from 'chai' diff --git a/test/server.ts b/test/node/server.ts similarity index 100% rename from test/server.ts rename to test/node/server.ts diff --git a/test/server_helpers_for_client_tests.ts b/test/node/server_helpers_for_client_tests.ts similarity index 100% rename from test/server_helpers_for_client_tests.ts rename to test/node/server_helpers_for_client_tests.ts diff --git a/test/store.ts b/test/node/store.ts similarity index 82% rename from test/store.ts rename to test/node/store.ts index 24c6cd56f..adbeb0a81 100644 --- a/test/store.ts +++ b/test/node/store.ts @@ -1,4 +1,4 @@ -import Store from '../src/lib/store' +import Store from '../../src/lib/store' import abstractTest from './abstract_store' import { describe } from 'node:test' diff --git a/test/unique_message_id_provider_client.ts b/test/node/unique_message_id_provider_client.ts similarity index 91% rename from test/unique_message_id_provider_client.ts rename to test/node/unique_message_id_provider_client.ts index 3d027b49f..5d2ba0951 100644 --- a/test/unique_message_id_provider_client.ts +++ b/test/node/unique_message_id_provider_client.ts @@ -1,6 +1,6 @@ import abstractClientTests from './abstract_client' import serverBuilder from './server_helpers_for_client_tests' -import { UniqueMessageIdProvider, IClientOptions } from '../src' +import { UniqueMessageIdProvider, IClientOptions } from '../../src' import getPorts from './helpers/port_list' import { describe, after } from 'node:test' diff --git a/test/util.ts b/test/node/util.ts similarity index 100% rename from test/util.ts rename to test/node/util.ts diff --git a/test/websocket_client.ts b/test/node/websocket_client.ts similarity index 99% rename from test/websocket_client.ts rename to test/node/websocket_client.ts index 87c6866ab..da6ac53a1 100644 --- a/test/websocket_client.ts +++ b/test/node/websocket_client.ts @@ -5,7 +5,7 @@ import assert from 'assert' import abstractClientTests from './abstract_client' import getPorts from './helpers/port_list' import { MqttServerNoWait } from './server' -import mqtt, { IClientOptions } from '../src' +import mqtt, { IClientOptions } from '../../src' import { after, describe, it } from 'node:test' const ports = getPorts(4) From e9705c059358763e57a500b4b98367916078d07c Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 22 Nov 2024 10:17:43 +0100 Subject: [PATCH 5/5] fix: move certs to correct folder --- electron-test/test/service/server_launcher.ts | 4 ++-- test/{node => browser}/certs/server-cert.pem | 0 test/{node => browser}/certs/server-key.pem | 0 web-test-runner.config.mjs | 4 ++-- 4 files changed, 4 insertions(+), 4 deletions(-) rename test/{node => browser}/certs/server-cert.pem (100%) rename test/{node => browser}/certs/server-key.pem (100%) diff --git a/electron-test/test/service/server_launcher.ts b/electron-test/test/service/server_launcher.ts index c7108a6c8..1991067fa 100644 --- a/electron-test/test/service/server_launcher.ts +++ b/electron-test/test/service/server_launcher.ts @@ -12,8 +12,8 @@ export default class ServerLauncher implements Services.ServiceInstance { } async onPrepare(): Promise { - const keyPath = pathResolve(__dirname, '../../../test/certs/server-key.pem') - const certPath = pathResolve(__dirname, '../../../test/certs/server-cert.pem') + const keyPath = pathResolve(__dirname, '../../../test/browser/certs/server-key.pem') + const certPath = pathResolve(__dirname, '../../../test/browser/certs/server-cert.pem') this.#aedesBroker = await start({ protos: ['tcp', 'tls'], diff --git a/test/node/certs/server-cert.pem b/test/browser/certs/server-cert.pem similarity index 100% rename from test/node/certs/server-cert.pem rename to test/browser/certs/server-cert.pem diff --git a/test/node/certs/server-key.pem b/test/browser/certs/server-key.pem similarity index 100% rename from test/node/certs/server-key.pem rename to test/browser/certs/server-key.pem diff --git a/web-test-runner.config.mjs b/web-test-runner.config.mjs index 69243c1af..306437a98 100644 --- a/web-test-runner.config.mjs +++ b/web-test-runner.config.mjs @@ -9,8 +9,8 @@ await start({ protos: ['tcp', 'tls', 'ws', 'wss'], wsPort, wssPort, - key: './test/certs/server-key.pem', - cert: './test/certs/server-cert.pem', + key: './test/browser/certs/server-key.pem', + cert: './test/browser/certs/server-cert.pem', verbose: true, stats: false })