stonyx 0.2.3-beta.52 → 0.2.3-beta.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/test-setup.js +25 -0
- package/package.json +1 -1
package/dist/cli/test-setup.js
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
1
2
|
import { pathToFileURL } from 'url';
|
|
2
3
|
const cwd = process.cwd();
|
|
3
4
|
const { default: Stonyx } = await import('stonyx');
|
|
4
5
|
const { default: config } = await import(pathToFileURL(`${cwd}/config/environment.js`).href);
|
|
5
6
|
new Stonyx(config, cwd);
|
|
7
|
+
// Drain the event loop once qunit finishes. Modules loaded by Stonyx
|
|
8
|
+
// (e.g. @stonyx/rest-server) may keep listeners/servers open that would
|
|
9
|
+
// otherwise block the process from exiting, causing CI to hit timeouts
|
|
10
|
+
// even though all tests passed.
|
|
11
|
+
//
|
|
12
|
+
// qunit's CLI bin does `delete require.cache[qunitPath]` and re-requires
|
|
13
|
+
// qunit before running, so any qunit instance we grab synchronously from
|
|
14
|
+
// this --import setup is a DIFFERENT object than the one qunit's CLI
|
|
15
|
+
// actually uses. We defer the hook registration with setImmediate so it
|
|
16
|
+
// runs AFTER the qunit bin has populated require.cache with its own
|
|
17
|
+
// instance; grabbing qunit via CJS require at that point returns the
|
|
18
|
+
// instance the tests are running on.
|
|
19
|
+
//
|
|
20
|
+
// See: https://github.com/abofs/stonyx/issues/55
|
|
21
|
+
const require = createRequire(import.meta.url);
|
|
22
|
+
setImmediate(() => {
|
|
23
|
+
const qunitPath = require.resolve('qunit', {
|
|
24
|
+
paths: [`${cwd}/node_modules`, cwd]
|
|
25
|
+
});
|
|
26
|
+
const QUnit = require(qunitPath);
|
|
27
|
+
QUnit.on('runEnd', () => {
|
|
28
|
+
setImmediate(() => process.exit(process.exitCode ?? 0));
|
|
29
|
+
});
|
|
30
|
+
});
|