Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions test/Cli.basictest.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,14 @@ describe("Cli", () => {
// Most important - it clears the cache
jest.resetModules();
process.env = { ...OLD_ENV };
// Prevent `process.env.FORCE_COLOR` from being auto set by `jest-worker`
if (OLD_ENV.FORCE_COLOR) {
delete process.env.FORCE_COLOR;
}
// Prevent `process.env.TERM` default value
if (OLD_ENV.TERM) {
delete process.env.TERM;
}
});

afterAll(() => {
Expand Down Expand Up @@ -459,25 +467,22 @@ describe("Cli", () => {
expect(isColorSupported()).toBe(isCI);
});

it("env CI", () => {
process.env.CI = "1";

expect(isColorSupported()).toBe(true);
});

it("env GITHUB_ACTIONS", () => {
process.env.CI = "1";
process.env.GITHUB_ACTIONS = "1";

expect(isColorSupported()).toBe(true);
});

it("env GITLAB_CI", () => {
process.env.CI = "1";
process.env.GITLAB_CI = "1";

expect(isColorSupported()).toBe(true);
});

it("env CIRCLECI", () => {
process.env.CI = "1";
process.env.CIRCLECI = "1";

expect(isColorSupported()).toBe(true);
Expand Down
3 changes: 3 additions & 0 deletions test/configCases/worker/node-worker-esm-class-worker/chunk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function getMessage(msg) {
return msg + " from worker with ESM import";
}
17 changes: 17 additions & 0 deletions test/configCases/worker/node-worker-esm-class-worker/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Worker } from "worker_threads";

it("should support class worker chunk in Node.js", async () => {
const worker = new Worker(new URL("./worker.js" + __resourceQuery, import.meta.url));

const promise = new Promise((resolve, reject) => {
worker.on("message", resolve);
worker.on("error", reject);
});

worker.postMessage("hello");

const result = await promise;
expect(result).toBe("hello from worker with ESM import");

await worker.terminate();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";

module.exports = {
findBundle() {
return "./bundle.mjs";
},
moduleScope(scope) {
scope.URL = URL;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

const supportsWorker = require("../../../helpers/supportsWorker");

module.exports = () => supportsWorker();
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

/** @type {import("../../../../").Configuration} */
module.exports = {
target: "node14",
entry: "./index.js",
optimization: {
chunkIds: "named"
},
output: {
module: true,
filename: "bundle.mjs"
},
experiments: {
outputModule: true
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { parentPort } = require("worker_threads");

const { getMessage } = require("./chunk.js");

parentPort.on("message", (msg) => {
// Worker with ESM import
parentPort.postMessage(getMessage(msg));
});
3 changes: 3 additions & 0 deletions test/configCases/worker/node-worker-require/chunk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function getMessage(msg) {
return msg + " from worker with ESM import";
}
22 changes: 22 additions & 0 deletions test/configCases/worker/node-worker-require/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Worker } from "worker_threads";

it("should support ESM worker chunks in Node.js", async () => {
const worker = new Worker(
new URL("./worker.js" + __resourceQuery, import.meta.url),
{
type: "module"
}
);

const promise = new Promise((resolve, reject) => {
worker.on("message", resolve);
worker.on("error", reject);
});

worker.postMessage("hello");

const result = await promise;
expect(result).toBe("hello from worker with ESM import");

await worker.terminate();
});
22 changes: 22 additions & 0 deletions test/configCases/worker/node-worker-require/test.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use strict";

const fs = require("fs");
const path = require("path");

module.exports = {
findBundle() {
return "./bundle.js";
},
afterExecute(options) {
const workerCode = fs.readFileSync(
path.resolve(options.output.path, "./worker_js.bundle.js"),
"utf8"
);

if (!/require\(\) chunk loading for javascript/.test(workerCode)) {
throw new Error(
"require was not found in the worker code for loading async chunks"
);
}
}
};
5 changes: 5 additions & 0 deletions test/configCases/worker/node-worker-require/test.filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

const supportsWorker = require("../../../helpers/supportsWorker");

module.exports = () => supportsWorker();
14 changes: 14 additions & 0 deletions test/configCases/worker/node-worker-require/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";

/** @type {import("../../../../").Configuration} */
module.exports = {
target: "async-node14",
entry: "./index.js",
optimization: {
chunkIds: "named"
},
output: {
filename: "bundle.js",
workerChunkLoading: "require"
}
};
8 changes: 8 additions & 0 deletions test/configCases/worker/node-worker-require/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { parentPort } from "worker_threads";

const { getMessage } = await import("./chunk.js");

parentPort.on("message", (msg) => {
// Worker with ESM import
parentPort.postMessage(getMessage(msg));
});
24 changes: 12 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1496,9 +1496,9 @@
integrity sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==

"@types/node@*", "@types/node@^24.0.13":
version "24.0.14"
resolved "https://registry.yarnpkg.com/@types/node/-/node-24.0.14.tgz#6e3d4fb6d858c48c69707394e1a0e08ce1ecc1bc"
integrity sha512-4zXMWD91vBLGRtHK3YbIoFMia+1nqEz72coM42C5ETjnNCa/heoj7NT1G67iAfOqMmcfhuCZ4uNpyz8EjlAejw==
version "24.0.15"
resolved "https://registry.yarnpkg.com/@types/node/-/node-24.0.15.tgz#f34fbc973e7d64217106e0c59ed8761e6b51381e"
integrity sha512-oaeTSbCef7U/z7rDeJA138xpG3NuKc64/rZ2qmUFkFJmnMsAPaluIifqyWd8hSSMxyP9oie3dLAqYPblag9KgA==
dependencies:
undici-types "~7.8.0"

Expand Down Expand Up @@ -3315,9 +3315,9 @@ eslint-compat-utils@^0.5.1:
semver "^7.5.4"

eslint-config-prettier@^10.1.1:
version "10.1.5"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-10.1.5.tgz#00c18d7225043b6fbce6a665697377998d453782"
integrity sha512-zc1UmCpNltmVY34vuLRV61r1K27sWuX39E+uyUnY8xS2Bex88VV9cugG+UZbRSRGtGyFboj+D8JODyme1plMpw==
version "10.1.8"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-10.1.8.tgz#15734ce4af8c2778cc32f0b01b37b0b5cd1ecb97"
integrity sha512-82GZUjRS0p/jganf6q1rEO25VSoHH0hKPCTrgillPjdI/3bgBhAE1QzHrHTizjpRvy6pGAvKjDJtk2pF9NDq8w==

eslint-config-webpack@^4.4.1:
version "4.4.1"
Expand Down Expand Up @@ -3418,9 +3418,9 @@ eslint-plugin-n@^17.21.0:
ts-declaration-location "^1.0.6"

eslint-plugin-prettier@^5.5.0:
version "5.5.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-5.5.1.tgz#470820964de9aedb37e9ce62c3266d2d26d08d15"
integrity sha512-dobTkHT6XaEVOo8IO90Q4DOSxnm3Y151QxPJlM/vKC0bVy+d6cVWQZLlFiuZPP0wS6vZwSKeJgKkcS+KfMBlRw==
version "5.5.3"
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-5.5.3.tgz#1f88e9220a72ac8be171eec5f9d4e4d529b5f4a0"
integrity sha512-NAdMYww51ehKfDyDhv59/eIItUVzU0Io9H2E8nHNGKEeeqlnci+1gCvrHib6EmZdf6GxF+LCV5K7UC65Ezvw7w==
dependencies:
prettier-linter-helpers "^1.0.0"
synckit "^0.11.7"
Expand Down Expand Up @@ -3875,9 +3875,9 @@ fork-ts-checker-webpack-plugin@^9.0.2:
tapable "^2.2.1"

form-data@^4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.3.tgz#608b1b3f3e28be0fccf5901fc85fb3641e5cf0ae"
integrity sha512-qsITQPfmvMOSAdeyZ+12I1c+CKSstAFAwu+97zrnWAbIr5u8wfsExUzCesVLC8NgHuRUqNN4Zy6UPWUTRGslcA==
version "4.0.4"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.4.tgz#784cdcce0669a9d68e94d11ac4eea98088edd2c4"
integrity sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
Expand Down
Loading