Skip to content

Commit 8b7c1d1

Browse files
Merge pull request #1 from Manas-Dikshit/fix/workererror-integration
test: use existing webpack test infra for worker-error integration test
2 parents ef4be86 + 033a99e commit 8b7c1d1

2 files changed

Lines changed: 6 additions & 36 deletions

File tree

src/WorkerError.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ const buildStackTrace = (err, workerStack = '', workerId = 'unknown') => {
1111
// Compute the difference between the worker's stack and the error's stack
1212
const extraWorkerLines = workerStackLines.slice(
1313
0,
14-
Math.max(0, workerStackLines.length - originStackLines.length)
14+
Math.max(0, workerStackLines.length - originStackLines.length),
1515
);
1616

1717
// Build a readable, merged stack trace
1818
const mergedStack = [
1919
`Thread Loader (Worker ${workerId})`,
2020
err?.message || 'Unknown error',
2121
extraWorkerLines.join('\n'),
22-
...originStackLines
22+
...originStackLines,
2323
]
2424
.filter(Boolean)
2525
.join('\n');

test/integration/worker-error.test.js

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,9 @@ import fixtureConfig from '../fixtures/error-project/webpack.config';
55
test('WorkerError integration: wraps and formats worker error', (done) => {
66
const config = fixtureConfig({ threads: 1 });
77

8-
const compiler = webpack(config);
9-
10-
compiler.run((err, stats) => {
11-
const finish = (cbErr) => {
12-
compiler.close(() => {
13-
try {
14-
// Ensure any worker pools created by thread-loader are terminated so
15-
// Jest can exit cleanly. Match the options used in the fixture.
16-
// Require the runtime workerPools from dist and terminate the pool.
17-
// eslint-disable-next-line global-require
18-
const { getPool } = require('../../dist/workerPools');
19-
const pool = getPool({ workers: 1, workerParallelJobs: 2, poolTimeout: 2000 });
20-
if (pool && typeof pool.terminate === 'function') {
21-
pool.terminate();
22-
}
23-
} catch (e) {
24-
// ignore cleanup errors
25-
}
26-
27-
// Allow a short grace period for child-process pipes and timeouts
28-
// to unwind before finishing the test so Jest can exit cleanly.
29-
setTimeout(() => {
30-
if (cbErr) {
31-
done(cbErr);
32-
} else {
33-
done();
34-
}
35-
}, 50);
36-
});
37-
};
38-
8+
webpack(config, (err, stats) => {
399
if (err) {
40-
finish(err);
10+
done(err);
4111
return;
4212
}
4313

@@ -59,9 +29,9 @@ test('WorkerError integration: wraps and formats worker error', (done) => {
5929
// Expect combined stack trace contains at least one 'at' line
6030
expect(stack).toMatch(/\n\s*at\s+/);
6131

62-
finish();
32+
done();
6333
} catch (e) {
64-
finish(e);
34+
done(e);
6535
}
6636
});
6737
}, 30000);

0 commit comments

Comments
 (0)