Skip to content

Commit

Permalink
chore: migrate css extract test (#6360)
Browse files Browse the repository at this point in the history
* chore: migrate css extract cases

* chore: migrate css extract cases

* chore: migrate css extract cases

* chore: migrate css extract cases

* chore: migrate css extract cases
  • Loading branch information
LingyuCoder authored Apr 25, 2024
1 parent 5379e65 commit af03d75
Show file tree
Hide file tree
Showing 958 changed files with 450 additions and 359 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ examples
diffcases
scripts/test/diff.cjs
scripts/test/binary-path.cjs
plugin-test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ esbuild.cpuprofile

# this node_modules is used for tree-shaking snapshot
!packages/rspack-test-tools/tests/treeShakingCases/node_modules
!packages/rspack/tests/cssExtract/cases/**/node_modules

# Binding artifacts
artifacts
Expand Down Expand Up @@ -223,6 +222,9 @@ justfile
!/webpack-test/**/target
!/webpack-test/cases/**/node_modules

/plugin-test/css-extract/js
!/plugin-test/css-extract/**/node_modules

/webpack-examples/**/dist

smoke-example
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ packages/rspack/tests/cases/parsing/issue-5120-binding/fail.js
packages/rspack/tests/diagnostics/module-parse-failed/lexically_name_error/index.js
packages/rspack-plugin-mini-css-extract/test/cases/**/*

plugin-test/**/*

benchcases/**/*
crates/**/*
target/**/*
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Thanks to:
- The [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin) project created by [@jantimon](https://github.com/jantimon), `@rspack/html-plugin` is a fork of [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin) to avoid some webpack API usage not supported in Rspack.
- The [Turbopack](https://github.com/vercel/turbo) project which inspired the AST path logic of Rspack.
- The [react-refresh-webpack-plugin](https://github.com/pmmmwh/react-refresh-webpack-plugin) created by [@pmmmwh](https://github.com/pmmmwh), which inspires implement react refresh.
- The [mini-css-extract-plugin] project created by [@sokra](https://github.com/sokra) which inspired implement css extract plugin.

## License

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"test:hot": "pnpm --filter \"@rspack/*\" test:hot",
"test:unit": "pnpm --filter \"@rspack/*\" test",
"test:e2e": "pnpm --filter \"@rspack-e2e/*\" test",
"test:ci": "cross-env NODE_OPTIONS=--max_old_space_size=8192 pnpm run build:js && pnpm run test:unit && pnpm test:webpack",
"test:ci": "cross-env NODE_OPTIONS=--max_old_space_size=8192 pnpm run build:js && pnpm run test:unit && npm run test:plugin && pnpm test:webpack",
"test:plugin": "pnpm --filter \"plugin-test\" test",
"test:webpack": "pnpm --filter \"webpack-test\" test:metric",
"api-extractor:local": "pnpm --filter '@rspack/*' api-extractor --local",
"api-extractor:ci": "pnpm --filter '@rspack/*' api-extractor:ci"
Expand Down

This file was deleted.

18 changes: 0 additions & 18 deletions packages/rspack/tests/cssExtract/cases/import/webpack.config.js

This file was deleted.

18 changes: 0 additions & 18 deletions packages/rspack/tests/cssExtract/cases/nested/webpack.config.js

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

18 changes: 0 additions & 18 deletions packages/rspack/tests/cssExtract/cases/simple/webpack.config.js

This file was deleted.

8 changes: 8 additions & 0 deletions plugin-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
>**Note**
> This package is heavily based on [mini-css-extract-plugin/test](https://github.com/webpack-contrib/mini-css-extract-plugin/tree/master/test)
## Credits

Thanks to:

* The [mini-css-extract-plugin] project created by [@sokra](https://github.com/sokra)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* eslint-env browser */
/* eslint-disable no-console */

const hotModuleReplacement = require("../../dist/builtin-plugin/css-extract/hmr/hotModuleReplacement");
const hotModuleReplacement = require("../../packages/rspack/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement");

function getLoadEvent() {
const event = document.createEvent("Event");
Expand All @@ -26,7 +26,7 @@ describe("HMR", () => {
let consoleMock = null;

beforeEach(() => {
consoleMock = jest.spyOn(console, "log").mockImplementation(() => () => {});
consoleMock = jest.spyOn(console, "log").mockImplementation(() => () => { });

jest.spyOn(Date, "now").mockImplementation(() => 1479427200000);

Expand Down
9 changes: 9 additions & 0 deletions plugin-test/css-extract/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* The test code is modified based on
* https://github.com/webpack-contrib/mini-css-extract-plugin/tree/master/test
*
* MIT Licensed
* Author Tobias Koppers @sokra
* Copyright JS Foundation and other contributors
* https://github.com/webpack-contrib/mini-css-extract-plugin/blob/master/LICENSE
*/
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

const path = require("path");
const webpack = require("../../");
const webpack = require("@rspack/core");
const del = require("del");

describe("TestCache", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

const fs = require("fs");
const path = require("path");
const webpack = require("../../");
const webpack = require("@rspack/core");
const yn = require("./helpers/yn");

const { CssExtractRspackPlugin } = webpack;
const UPDATE_TEST = process.env.CSS_CASE_UPDATE;
const UPDATE_TEST = global.updateSnapshot;

function clearDirectory(dirPath) {
let files;
Expand Down Expand Up @@ -92,7 +92,7 @@ function compareDirectory(actual, expected) {
if (UPDATE_TEST) {
fs.writeFileSync(path.resolve(expected, file), actualContent);
} else {
expect(actualContent).toEqual(content);
expect(actualContent.replace(/\r\n/g, "\n").trim()).toEqual(content.replace(/\r\n/g, "\n").trim());
}
}
}
Expand All @@ -109,7 +109,7 @@ describe("TestCases", () => {
// eslint-disable-next-line global-require, import/no-dynamic-require
if (fs.existsSync(filterPath) && !require(filterPath)()) {
describe.skip(test, () => {
it("filtered", () => {});
it("filtered", () => { });
});

return false;
Expand Down Expand Up @@ -137,28 +137,28 @@ describe("TestCases", () => {
));
const webpackConfig = Array.isArray(config)
? config.map(config => {
return {
...config,
optimization: { chunkIds: "named", ...config.optimization },
experiments: {
css: false,
rspackFuture: {
newTreeshaking: true
},
...config.experiments
}
};
})
: {
return {
...config,
optimization: { chunkIds: "named", ...config.optimization },
experiments: {
css: false,
rspackFuture: {
newTreeshaking: true
},
...config.experiments
}
};
};
})
: {
...config,
experiments: {
css: false,
rspackFuture: {
newTreeshaking: true
},
...config.experiments
}
};
const { context } = webpackConfig;

for (const config of [].concat(webpackConfig)) {
Expand Down Expand Up @@ -249,8 +249,7 @@ describe("TestCases", () => {
const expectedDirectory = path.resolve(directoryForCase, "expected");
const expectedDirectoryByVersion = path.join(
expectedDirectory,
`webpack-${webpack.version[0]}${
yn(process.env.OLD_API) ? "" : "-importModule"
`webpack-${webpack.version[0]}${yn(process.env.OLD_API) ? "" : "-importModule"
}`
);

Expand All @@ -267,7 +266,6 @@ describe("TestCases", () => {
const matchAll = res.match(
/__webpack_require__\.h = function \(\) {\n.*return ("[\d\w].*");\n.*};/i
);
console.log(matchAll[1]);
const replacer = new Array(matchAll[1].length);

res = res.replace(
Expand Down Expand Up @@ -301,7 +299,6 @@ describe("TestCases", () => {
});
// eslint-disable-next-line global-require, import/no-dynamic-require
const expectedWarnings = require(warningsFile);
console.log(actualWarnings);
expect(
actualWarnings
.trim()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require("path");
const { createFsFromVolume, Volume } = require("memfs");
const webpack = require("../../");
const webpack = require("@rspack/core");

const assetsNames = assets => assets.map(asset => asset.name);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env browser */
const path = require("path");

const { CssExtractRspackPlugin: MiniCssExtractPlugin } = require("../../dist");
const { CssExtractRspackPlugin: MiniCssExtractPlugin } = require("@rspack/core");

const {
compile,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { CssExtractRspackPlugin } = require("../../../../");
const { CssExtractRspackPlugin } = require("@rspack/core");

module.exports = {
entry: "./index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { CssExtractRspackPlugin } = require("../../../../");
const { CssExtractRspackPlugin } = require("@rspack/core");

module.exports = {
entry: "./index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { CssExtractRspackPlugin } = require("../../../../");
const { CssExtractRspackPlugin } = require("@rspack/core");

module.exports = {
mode: "development",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { CssExtractRspackPlugin } = require("../../../../");
const { CssExtractRspackPlugin } = require("@rspack/core");

module.exports = {
entry: "./index.css",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { CssExtractRspackPlugin } = require("../../../../");
const { CssExtractRspackPlugin } = require("@rspack/core");

module.exports = {
entry: "./index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { CssExtractRspackPlugin } = require("../../../../");
const { CssExtractRspackPlugin } = require("@rspack/core");

module.exports = {
entry: "./index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { CssExtractRspackPlugin } = require("../../../../");
const { CssExtractRspackPlugin } = require("@rspack/core");

module.exports = {
entry: "./index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { CssExtractRspackPlugin } = require("../../../../");
const { CssExtractRspackPlugin } = require("@rspack/core");

module.exports = {
entry: "./index.js",
Expand Down
Loading

2 comments on commit af03d75

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Ran ecosystem CI: Open

suite result
modernjs, self-hosted, Linux, ci ❌ failure
_selftest, ubuntu-latest ✅ success
nx, ubuntu-latest ✅ success
rspress, ubuntu-latest ✅ success
rsbuild, ubuntu-latest ✅ success
compat, ubuntu-latest ✅ success
examples, ubuntu-latest ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Benchmark detail: Open

Name Base (2024-04-25 bc61872) Current Change
10000_development-mode + exec 2.72 s ± 21 ms 2.73 s ± 31 ms +0.20 %
10000_development-mode_hmr + exec 698 ms ± 22 ms 697 ms ± 3.5 ms -0.10 %
10000_production-mode + exec 2.56 s ± 52 ms 2.57 s ± 35 ms +0.56 %
arco-pro_development-mode + exec 2.5 s ± 105 ms 2.46 s ± 75 ms -1.61 %
arco-pro_development-mode_hmr + exec 431 ms ± 1.9 ms 429 ms ± 1 ms -0.37 %
arco-pro_development-mode_hmr_intercept-plugin + exec 445 ms ± 7.1 ms 442 ms ± 3.5 ms -0.68 %
arco-pro_development-mode_intercept-plugin + exec 3.27 s ± 101 ms 3.24 s ± 50 ms -0.77 %
arco-pro_production-mode + exec 4.09 s ± 73 ms 4.03 s ± 91 ms -1.43 %
arco-pro_production-mode_intercept-plugin + exec 4.82 s ± 72 ms 4.8 s ± 77 ms -0.33 %
threejs_development-mode_10x + exec 2.07 s ± 25 ms 2.06 s ± 21 ms -0.52 %
threejs_development-mode_10x_hmr + exec 758 ms ± 8.4 ms 756 ms ± 8 ms -0.37 %
threejs_production-mode_10x + exec 5.28 s ± 42 ms 5.29 s ± 24 ms +0.06 %

Please sign in to comment.