From 06100b1127cdf62e3b73a72c2fd96a7db408e2c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kol=C3=A1rik?= Date: Mon, 17 Apr 2023 16:31:49 +0200 Subject: [PATCH] test: add dist test (closes #231) --- .github/workflows/ci.yml | 1 + package.json | 1 + test/dist.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 test/dist.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b74f31b..ee874b25 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,3 +37,4 @@ jobs: run: | npm run lint npm run coverage + npm run test:dist diff --git a/package.json b/package.json index 1a26a60a..0b736e51 100644 --- a/package.json +++ b/package.json @@ -105,6 +105,7 @@ "prepare": "npm run download:jsons; husky install || echo 'Failed to install husky'", "start": "NODE_ENV=production node --max_old_space_size=3584 --max-semi-space-size=128 --experimental-loader newrelic/esm-loader.mjs dist/index.js", "test": "npm run lint:js && npm run test:mocha", + "test:dist": "node --test-reporter=spec test/dist.js", "test:mocha": "NODE_ENV=test FAKE_PROBE_IP=1 NEW_RELIC_ENABLED=false NEW_RELIC_LOG_ENABLED=false mocha", "test:mocha:dev": "TS_NODE_TRANSPILE_ONLY=true NODE_ENV=test FAKE_PROBE_IP=1 NEW_RELIC_ENABLED=false NEW_RELIC_LOG_ENABLED=false mocha", "test:perf": "tsx test-perf/index.ts" diff --git a/test/dist.js b/test/dist.js new file mode 100644 index 00000000..37e7a17b --- /dev/null +++ b/test/dist.js @@ -0,0 +1,28 @@ +import assert from 'node:assert'; +import cluster from 'node:cluster'; +import { describe, it } from 'node:test'; + +if (!cluster.isPrimary) { + import('../dist/index.js'); +} else { + describe('dist build', () => { + it('loads and doesn\'t crash', async () => { + await import('../dist/index.js'); + + await new Promise((resolve, reject) => { + setTimeout(resolve, 10000).unref(); + cluster.removeAllListeners('exit'); + + cluster.on('exit', ({ code, signal }) => { + reject(new assert.AssertionError({ message: `Exited with code ${code}, signal ${signal}.` })); + }); + }); + + cluster.removeAllListeners('exit'); + + Object.values(cluster.workers).forEach((worker) => { + worker.kill(); + }); + }); + }); +}