Skip to content

Commit 381e0c0

Browse files
committed
test(worker): cover regexp fallback without worker threads
1 parent f256eef commit 381e0c0

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎test/parallel-option.test.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ const ENABLE_WORKER_THREADS =
4040
? process.env.ENABLE_WORKER_THREADS === "true"
4141
: true;
4242

43+
const WORKER_THREADS_AVAILABLE = (() => {
44+
try {
45+
require("worker_threads");
46+
return true;
47+
} catch (_error) {
48+
return false;
49+
}
50+
})();
51+
4352
jest.mock("jest-worker", () => ({
4453
Worker: jest.fn().mockImplementation((workerPath) => ({
4554
transform: (workerTransform = jest.fn((data) =>
@@ -235,6 +244,20 @@ describe("parallel option", () => {
235244
expect(workerTransform).not.toHaveBeenCalled();
236245
});
237246

247+
it("should use transform for a RegExp when worker threads are unavailable", async () => {
248+
if (WORKER_THREADS_AVAILABLE) return;
249+
250+
new MinimizerPlugin({
251+
parallel: true,
252+
extractComments: /license/i,
253+
}).apply(compiler);
254+
255+
await compile(compiler);
256+
257+
expect(workerTransform).toHaveBeenCalled();
258+
expect(workerMinify).not.toHaveBeenCalled();
259+
});
260+
238261
it('should match snapshot for the "false" value', async () => {
239262
new MinimizerPlugin({ parallel: false }).apply(compiler);
240263

0 commit comments

Comments
 (0)