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
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = {
testRegex: ["/test/.*\\.(test.js|test.ts)$"],
moduleFileExtensions: ["ts", "js", "json"],
snapshotResolver: "<rootDir>/scripts/snapshot-resolver.js",
watchPlugins: ["jest-watch-typeahead/filename", "jest-watch-typeahead/testname"],
setupFilesAfterEnv: ["<rootDir>/scripts/setup-test.js"],
globalTeardown: "<rootDir>/scripts/cleanup-test.js",
globalSetup: "<rootDir>/scripts/global-setup.js",
Expand Down
17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"test:cli": "jest test --reporters=default",
"test:packages": "jest packages/ --reporters=default",
"test:ci": "yarn test:cli && yarn test:packages",
"test:watch": "jest test/ packages/ --watch",
"publish:monorepo": "yarn build && lerna version && lerna publish from-git",
"update:docs": "node ./scripts/update-docs",
"prepare": "husky"
Expand All @@ -55,10 +54,10 @@
"@babel/register": "^7.15.8",
"@eslint/js": "^9.28.0",
"@eslint/markdown": "^7.1.0",
"@commitlint/cli": "^19.4.0",
"@commitlint/config-conventional": "^19.2.2",
"@commitlint/cli": "^20.2.0",
"@commitlint/config-conventional": "^20.2.0",
"@stylistic/eslint-plugin": "^5.0.0",
"@types/jest": "^29.5.13",
"@types/jest": "^30.0.0",
"@types/node": "^22.5.5",
"@types/rechoir": "^0.6.1",
"coffeescript": "^2.7.0",
Expand All @@ -72,16 +71,15 @@
"eslint-config-prettier": "^10.1.5",
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-jest": "^29.0.1",
"eslint-plugin-jsdoc": "^51.2.3",
"eslint-plugin-jsdoc": "^61.5.0",
"eslint-plugin-n": "^17.19.0",
"eslint-plugin-prettier": "^5.4.1",
"eslint-plugin-unicorn": "^60.0.0",
"eslint-plugin-unicorn": "^62.0.0",
"execa": "^5.0.0",
"get-port": "^5.1.1",
"globals": "^16.2.0",
"husky": "^9.1.4",
"jest": "^29.4.1",
"jest-watch-typeahead": "^2.2.2",
"jest": "^30.2.0",
"lerna": "^8.1.8",
"lint-staged": "^15.2.9",
"mini-css-extract-plugin": "^2.6.1",
Expand All @@ -90,15 +88,14 @@
"readable-stream": "^4.5.2",
"sass": "^1.54.9",
"sass-loader": "^16.0.2",
"strip-ansi": "^6.0.1",
"style-loader": "^4.0.0",
"ts-jest": "^29.0.1",
"ts-loader": "^9.3.1",
"ts-node": "^10.9.1",
"typescript": "^5.0.4",
"typescript-eslint": "^8.35.0",
"webpack": "^5.103.0",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-bundle-analyzer": "^5.1.0",
"webpack-dev-server": "^5.1.0"
},
"peerDependencies": {
Expand Down
14 changes: 7 additions & 7 deletions smoketests/helpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require("node:fs");
const path = require("node:path");
const { stripVTControlCharacters } = require("node:util");
const execa = require("execa");
const stripAnsi = require("strip-ansi");

const ROOT_PATH = process.env.GITHUB_WORKSPACE || path.resolve(__dirname, "..");

Expand Down Expand Up @@ -48,7 +48,7 @@ const runTest = (pkg, cliArgs = [], logMessage = undefined, isSubPackage = false
let hasPassed = false;

proc.stderr.on("data", (chunk) => {
const data = stripAnsi(chunk.toString());
const data = stripVTControlCharacters(chunk.toString());

console.log(` stderr: ${data}`);

Expand Down Expand Up @@ -99,7 +99,7 @@ const runTestStdout = ({ packageName, cliArgs, logMessage, isSubPackage } = {})
let hasPassed = false;

proc.stdout.on("data", (chunk) => {
const data = stripAnsi(chunk.toString());
const data = stripVTControlCharacters(chunk.toString());

console.log(` stdout: ${data}`);

Expand All @@ -110,7 +110,7 @@ const runTestStdout = ({ packageName, cliArgs, logMessage, isSubPackage } = {})
});

proc.stderr.on("data", (chunk) => {
const data = stripAnsi(chunk.toString());
const data = stripVTControlCharacters(chunk.toString());
console.log(` stderr: ${data}`);
});

Expand Down Expand Up @@ -153,7 +153,7 @@ const runTestStdoutWithInput = ({
let hasPassed = false;

proc.stdout.on("data", (chunk) => {
const data = stripAnsi(chunk.toString());
const data = stripVTControlCharacters(chunk.toString());
console.log(` stdout: ${data}`);

if (data.includes(logMessage)) {
Expand All @@ -169,7 +169,7 @@ const runTestStdoutWithInput = ({
});

proc.stderr.on("data", (chunk) => {
const data = stripAnsi(chunk.toString());
const data = stripVTControlCharacters(chunk.toString());
console.log(` stderr: ${data}`);
});

Expand Down Expand Up @@ -214,7 +214,7 @@ const runTestWithHelp = (pkg, cliArgs = [], logMessage = undefined, isSubPackage
let hasPassed = false;

proc.stderr.on("data", (chunk) => {
const data = stripAnsi(chunk.toString());
const data = stripVTControlCharacters(chunk.toString());

console.log(` stderr: ${data}`);

Expand Down
2 changes: 1 addition & 1 deletion test/api/__snapshots__/CLI.test.js.snap.webpack5
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`CLI API custom help output should display help information 1`] = `
[
Expand Down
62 changes: 31 additions & 31 deletions test/api/do-install.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const stripAnsi = require("strip-ansi");
const { stripVTControlCharacters } = require("node:util");
const CLI = require("../../packages/webpack-cli/lib/webpack-cli");

const readlineQuestionMock = jest.fn();
Expand Down Expand Up @@ -39,9 +39,9 @@ describe("doInstall", () => {
const installResult = await cli.doInstall("test-package");

expect(installResult).toBe("test-package");
expect(readlineQuestionMock.mock.calls).toHaveLength(1);
expect(spawnMock.mock.calls).toHaveLength(1);
expect(stripAnsi(readlineQuestionMock.mock.calls[0][0])).toContain(
expect(readlineQuestionMock).toHaveBeenCalledTimes(1);
expect(spawnMock).toHaveBeenCalledTimes(1);
expect(stripVTControlCharacters(readlineQuestionMock.mock.calls[0][0])).toContain(
"Would you like to install 'test-package' package? (That will run 'npm install -D test-package')",
);

Expand All @@ -57,9 +57,9 @@ describe("doInstall", () => {
const installResult = await cli.doInstall("test-package");

expect(installResult).toBe("test-package");
expect(readlineQuestionMock.mock.calls).toHaveLength(1);
expect(spawnMock.mock.calls).toHaveLength(1);
expect(stripAnsi(readlineQuestionMock.mock.calls[0][0])).toContain(
expect(readlineQuestionMock).toHaveBeenCalledTimes(1);
expect(spawnMock).toHaveBeenCalledTimes(1);
expect(stripVTControlCharacters(readlineQuestionMock.mock.calls[0][0])).toContain(
"Would you like to install 'test-package' package? (That will run 'yarn add -D test-package')",
);

Expand All @@ -75,9 +75,9 @@ describe("doInstall", () => {
const installResult = await cli.doInstall("test-package");

expect(installResult).toBe("test-package");
expect(readlineQuestionMock.mock.calls).toHaveLength(1);
expect(spawnMock.mock.calls).toHaveLength(1);
expect(stripAnsi(readlineQuestionMock.mock.calls[0][0])).toContain(
expect(readlineQuestionMock).toHaveBeenCalledTimes(1);
expect(spawnMock).toHaveBeenCalledTimes(1);
expect(stripVTControlCharacters(readlineQuestionMock.mock.calls[0][0])).toContain(
"Would you like to install 'test-package' package? (That will run 'pnpm install -D test-package')",
);

Expand All @@ -94,10 +94,10 @@ describe("doInstall", () => {
const installResult = await cli.doInstall("test-package", { preMessage });

expect(installResult).toBe("test-package");
expect(preMessage.mock.calls).toHaveLength(1);
expect(readlineQuestionMock.mock.calls).toHaveLength(1);
expect(spawnMock.mock.calls).toHaveLength(1);
expect(stripAnsi(readlineQuestionMock.mock.calls[0][0])).toContain(
expect(preMessage).toHaveBeenCalledTimes(1);
expect(readlineQuestionMock).toHaveBeenCalledTimes(1);
expect(spawnMock).toHaveBeenCalledTimes(1);
expect(stripVTControlCharacters(readlineQuestionMock.mock.calls[0][0])).toContain(
"Would you like to install 'test-package' package? (That will run 'npm install -D test-package')",
);

Expand All @@ -113,9 +113,9 @@ describe("doInstall", () => {
const installResult = await cli.doInstall("test-package");

expect(installResult).toBe("test-package");
expect(readlineQuestionMock.mock.calls).toHaveLength(1);
expect(spawnMock.mock.calls).toHaveLength(1);
expect(stripAnsi(readlineQuestionMock.mock.calls[0][0])).toContain(
expect(readlineQuestionMock).toHaveBeenCalledTimes(1);
expect(spawnMock).toHaveBeenCalledTimes(1);
expect(stripVTControlCharacters(readlineQuestionMock.mock.calls[0][0])).toContain(
"Would you like to install 'test-package' package? (That will run 'npm install -D test-package')",
);

Expand All @@ -131,9 +131,9 @@ describe("doInstall", () => {
const installResult = await cli.doInstall("test-package");

expect(installResult).toBe("test-package");
expect(readlineQuestionMock.mock.calls).toHaveLength(1);
expect(spawnMock.mock.calls).toHaveLength(1);
expect(stripAnsi(readlineQuestionMock.mock.calls[0][0])).toContain(
expect(readlineQuestionMock).toHaveBeenCalledTimes(1);
expect(spawnMock).toHaveBeenCalledTimes(1);
expect(stripVTControlCharacters(readlineQuestionMock.mock.calls[0][0])).toContain(
"Would you like to install 'test-package' package? (That will run 'npm install -D test-package')",
);

Expand All @@ -149,9 +149,9 @@ describe("doInstall", () => {
const installResult = await cli.doInstall("test-package");

expect(installResult).toBe("test-package");
expect(readlineQuestionMock.mock.calls).toHaveLength(1);
expect(spawnMock.mock.calls).toHaveLength(1);
expect(stripAnsi(readlineQuestionMock.mock.calls[0][0])).toContain(
expect(readlineQuestionMock).toHaveBeenCalledTimes(1);
expect(spawnMock).toHaveBeenCalledTimes(1);
expect(stripVTControlCharacters(readlineQuestionMock.mock.calls[0][0])).toContain(
"Would you like to install 'test-package' package? (That will run 'npm install -D test-package')",
);

Expand All @@ -167,9 +167,9 @@ describe("doInstall", () => {
const installResult = await cli.doInstall("test-package");

expect(installResult).toBeUndefined();
expect(readlineQuestionMock.mock.calls).toHaveLength(1);
expect(readlineQuestionMock).toHaveBeenCalledTimes(1);
// runCommand should not be called, because the installation is not confirmed
expect(spawnMock.mock.calls).toHaveLength(0);
expect(spawnMock).not.toHaveBeenCalled();
expect(mockExit.mock.calls[0][0]).toBe(2);

mockExit.mockRestore();
Expand All @@ -182,9 +182,9 @@ describe("doInstall", () => {
const installResult = await cli.doInstall("test-package");

expect(installResult).toBeUndefined();
expect(readlineQuestionMock.mock.calls).toHaveLength(1);
expect(readlineQuestionMock).toHaveBeenCalledTimes(1);
// runCommand should not be called, because the installation is not confirmed
expect(spawnMock.mock.calls).toHaveLength(0);
expect(spawnMock).not.toHaveBeenCalled();
expect(mockExit.mock.calls[0][0]).toBe(2);

mockExit.mockRestore();
Expand All @@ -197,9 +197,9 @@ describe("doInstall", () => {
const installResult = await cli.doInstall("test-package");

expect(installResult).toBeUndefined();
expect(readlineQuestionMock.mock.calls).toHaveLength(1);
expect(readlineQuestionMock).toHaveBeenCalledTimes(1);
// runCommand should not be called, because the installation is not confirmed
expect(spawnMock.mock.calls).toHaveLength(0);
expect(spawnMock).not.toHaveBeenCalled();
expect(mockExit.mock.calls[0][0]).toBe(2);

mockExit.mockRestore();
Expand All @@ -212,9 +212,9 @@ describe("doInstall", () => {
const installResult = await cli.doInstall("test-package");

expect(installResult).toBeUndefined();
expect(readlineQuestionMock.mock.calls).toHaveLength(1);
expect(readlineQuestionMock).toHaveBeenCalledTimes(1);
// runCommand should not be called, because the installation is not confirmed
expect(spawnMock.mock.calls).toHaveLength(0);
expect(spawnMock).not.toHaveBeenCalled();
expect(mockExit.mock.calls[0][0]).toBe(2);

mockExit.mockRestore();
Expand Down
18 changes: 9 additions & 9 deletions test/api/get-default-package-manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,56 +46,56 @@ describe("getPackageManager", () => {
cwdSpy.mockReturnValue(testYarnLockPath);

expect(cli.getDefaultPackageManager()).toBe("yarn");
expect(syncMock.mock.calls).toHaveLength(0);
expect(syncMock).not.toHaveBeenCalled();
});

it("should find package-lock.json", () => {
cwdSpy.mockReturnValue(testNpmLockPath);

expect(cli.getDefaultPackageManager()).toBe("npm");
expect(syncMock.mock.calls).toHaveLength(0);
expect(syncMock).not.toHaveBeenCalled();
});

it("should find pnpm-lock.yaml", () => {
cwdSpy.mockReturnValue(testPnpmLockPath);

expect(cli.getDefaultPackageManager()).toBe("pnpm");
expect(syncMock.mock.calls).toHaveLength(0);
expect(syncMock).not.toHaveBeenCalled();
});

it("should prioritize npm over pnpm", () => {
cwdSpy.mockReturnValue(testNpmAndPnpmPath);

expect(cli.getDefaultPackageManager()).toBe("npm");
expect(syncMock.mock.calls).toHaveLength(0);
expect(syncMock).not.toHaveBeenCalled();
});

it("should prioritize npm over yarn", () => {
cwdSpy.mockReturnValue(testNpmAndYarnPath);

expect(cli.getDefaultPackageManager()).toBe("npm");
expect(syncMock.mock.calls).toHaveLength(0);
expect(syncMock).not.toHaveBeenCalled();
});

it("should prioritize yarn over pnpm", () => {
cwdSpy.mockReturnValue(testYarnAndPnpmPath);

expect(cli.getDefaultPackageManager()).toBe("yarn");
expect(syncMock.mock.calls).toHaveLength(0);
expect(syncMock).not.toHaveBeenCalled();
});

it("should prioritize npm with many lock files", () => {
cwdSpy.mockReturnValue(testAllPath);

expect(cli.getDefaultPackageManager()).toBe("npm");
expect(syncMock.mock.calls).toHaveLength(0);
expect(syncMock).not.toHaveBeenCalled();
});

it("should prioritize global npm over other package managers", () => {
cwdSpy.mockReturnValue(noLockPath);

expect(cli.getDefaultPackageManager()).toBe("npm");
expect(syncMock.mock.calls).toHaveLength(1);
expect(syncMock).toHaveBeenCalledTimes(1);
});

it("should throw error if no package manager is found", () => {
Expand All @@ -110,6 +110,6 @@ describe("getPackageManager", () => {
expect(cli.getDefaultPackageManager()).toBeFalsy();
expect(mockExit).toHaveBeenCalledWith(2);
expect(consoleMock).toHaveBeenCalledTimes(1);
expect(syncMock.mock.calls).toHaveLength(3); // 3 calls for npm, yarn and pnpm
expect(syncMock).toHaveBeenCalledTimes(3); // 3 calls for npm, yarn and pnpm
});
});
2 changes: 1 addition & 1 deletion test/build/import-local/import-local.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe("import local", () => {
const { exitCode, stderr, stdout } = await run(__dirname, [], {
env: { WEBPACK_CLI_SKIP_IMPORT_LOCAL: true },
});
expect(importLocalMock).toHaveBeenCalledTimes(0);
expect(importLocalMock).not.toHaveBeenCalled();
expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`output flag named bundles should output file in bin directory using default webpack config with warning for empty output value: stderr 1`] = `
"[webpack-cli] Error: Option '-o, --output-path <value>' argument missing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`stats flag should log error when an unknown flag stats value is passed: stderr 1`] = `
"[webpack-cli] Invalid value 'foo' for the '--stats' option
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`--target flag should reset the \`target\` option when the \`--target-reset\` is used for multiple targets: stderr 1`] = `""`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`Node target should emit the correct code: stderr 1`] = `""`;
Loading
Loading