Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7186: Replace webpack.scripts with Jest #7340

Merged
merged 4 commits into from
Jan 16, 2024
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 .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ artifacts
selenium
src/vendors
src/types/swagger.ts
scripts/bin
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ jobs:
node-version-file: package.json
cache: npm
- run: npm ci
- run: npm run build:scripts
- run: npm run generate:headers
- uses: actions/upload-artifact@v4
name: Save headers.json
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const config = {
modulePaths: ["/src"],
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "yaml", "yml", "json"],
testPathIgnorePatterns: ["<rootDir>/selenium/"],
modulePathIgnorePatterns: ["<rootDir>/headers.json"],
transform: {
"^.+\\.[jt]sx?$": "@swc/jest",
"^.+\\.mjs$": "@swc/jest",
Expand Down
8 changes: 1 addition & 7 deletions knip.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ const config = configFactory(process.env, {});
const knipConfig = {
$schema: "https://unpkg.com/knip@3/schema.json",
webpack: {
config: [
"webpack.config.mjs",
"scripts/webpack.scripts.js",
".storybook/main.js",
],
config: ["webpack.config.mjs", ".storybook/main.js"],
},
entry: [
...Object.values(config.entry).map((x) =>
Expand Down Expand Up @@ -65,8 +61,6 @@ const knipConfig = {
// Referenced in scss files
"webext-base-css",
"compass-mixins",
// Polyfills via ProvidePlugin aren't detected by webpack plugin
"min-document",
// Not getting detected by webpack plugin for .storybook/main.js
"style-loader",
"@storybook/react-webpack5",
Expand Down
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"build:webpack": "NODE_OPTIONS=--max_old_space_size=8192 webpack --mode production",
"build:typescript": "tsc --noEmit",
"build:strictNullChecks": "tsc --noEmit --project src/tsconfig.strictNullChecks.json",
"build:scripts": "webpack --config scripts/webpack.scripts.js",
"generate:headers": "NODE_OPTIONS=--stack-trace-limit=100 node scripts/bin/headers.js",
"generate:headers": "npm run test -- src/development/headers.test.ts --no-silent",
"storybook": "storybook dev -p 6006 -s public",
"build-storybook": "storybook build",
"dead-code": "knip"
Expand Down Expand Up @@ -260,7 +259,6 @@
"jest-webextension-mock": "^3.8.9",
"jsdom": "^23.2.0",
"jsdom-testing-mocks": "^1.11.0",
"min-document": "^2.19.0",
"mini-css-extract-plugin": "^2.6.1",
"mockdate": "^3.0.5",
"msw": "^1.3.2",
Expand Down
3 changes: 0 additions & 3 deletions pixiebrix-extension.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/artifacts" />
<excludeFolder url="file://$MODULE_DIR$/browsers/chrome/bundles" />
<excludeFolder url="file://$MODULE_DIR$/scripts/bin" />
<excludeFolder url="file://$MODULE_DIR$/dist" />
<excludeFolder url="file://$MODULE_DIR$/browsers/dist" />
<excludeFolder url="file://$MODULE_DIR$/coverage" />
<excludeFolder url="file://$MODULE_DIR$/storybook-static" />
</content>
Expand Down
75 changes: 0 additions & 75 deletions scripts/webpack.scripts.js

This file was deleted.

1 change: 0 additions & 1 deletion src/__mocks__/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Any file in this folder is picked up automatically by both Jest and Storybook.

- Jest: https://github.com/pixiebrix/pixiebrix-extension/blob/d834064d9e18d0b799cc890110dc35eea8be6daa/jest.config.js#L66
- Storybook: https://github.com/pixiebrix/pixiebrix-extension/blob/d834064d9e18d0b799cc890110dc35eea8be6daa/.storybook/main.js#L50-L63
- headers.ts: https://github.com/pixiebrix/pixiebrix-extension/blob/d834064d9e18d0b799cc890110dc35eea8be6daa/scripts/webpack.scripts.js#L43

### jest.unmock()

Expand Down
30 changes: 10 additions & 20 deletions src/development/headers.ts → src/development/headers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ registerContribBlocks();

Error.stackTraceLimit = Number.POSITIVE_INFINITY;

console.log(`version: ${process.env.NPM_PACKAGE_VERSION}`);
console.log(`version: ${process.env.npm_package_version}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's causing the capitalization change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The webpack config was intentionally changing the ENV. The lowercase ENV is provided by npm run


const brickDefinitions = brickRegistry.builtins.map((brick) => ({
apiVersion: "v1",
header: true,
kind: "read" in brick ? "reader" : "component",
metadata: {
id: brick.id,
version: process.env.NPM_PACKAGE_VERSION,
version: process.env.npm_package_version,
name: brick.name,
description: brick.description,
},
Expand All @@ -50,22 +50,12 @@ const brickDefinitions = brickRegistry.builtins.map((brick) => ({

console.log(`Number of brick headers: ${brickDefinitions.length}`);

if (brickDefinitions.length === 0) {
throw new Error("No brick definitions generated");
}
// Convert the following code to use test expectations
test("brick headers", () => {
// If greater, did you forget to bump EXPECTED_HEADER_COUNT constant?
// If lower, did you forget to register a brick definition?
expect(brickDefinitions).toHaveLength(EXPECTED_HEADER_COUNT);

if (brickDefinitions.length > EXPECTED_HEADER_COUNT) {
throw new Error(
`Expected ${EXPECTED_HEADER_COUNT} brick definitions. Actual: ${brickDefinitions.length}. Did you forget to bump the EXPECTED_HEADER_COUNT constant?`,
);
}

if (brickDefinitions.length < EXPECTED_HEADER_COUNT) {
throw new Error(
`Expected ${EXPECTED_HEADER_COUNT} brick definitions. Actual: ${brickDefinitions.length}. Did you forget to register a brick definition?`,
);
}

fs.writeFileSync("headers.json", JSON.stringify(brickDefinitions));

console.log("headers.json written to disk");
fs.writeFileSync("headers.json", JSON.stringify(brickDefinitions));
console.log("headers.json written to disk");
});
Loading