Skip to content

Commit

Permalink
test: add dist test (closes #231)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKolarik committed Apr 17, 2023
1 parent 2ef0f29 commit 06100b1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ jobs:
run: |
npm run lint
npm run coverage
npm run test:dist
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 28 additions & 0 deletions test/dist.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
}

0 comments on commit 06100b1

Please sign in to comment.