From 80f664c25de52289e41994ea3431cc8eb8a425cf Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 22 Nov 2024 10:04:43 +0100 Subject: [PATCH] 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) -})