From bc618727c282abb75f12156502cbfd2e92d00f66 Mon Sep 17 00:00:00 2001 From: harpsealjs Date: Wed, 24 Apr 2024 18:33:00 +0800 Subject: [PATCH] chore: migrate compat case (#6353) chore: migrate remain compat cases --- .github/workflows/test-ng.yml | 2 +- .prettierignore | 12 +- package.json | 1 - packages/rspack-test-tools/etc/api.md | 4 - .../rspack-test-tools/jest.config.compat.js | 21 - packages/rspack-test-tools/jest.config.hot.js | 2 +- packages/rspack-test-tools/jest.config.js | 3 +- .../rspack-test-tools/jest.config.legacy.js | 23 - packages/rspack-test-tools/package.json | 3 +- .../src/processor/stats-api.ts | 10 - .../tests/HashTestCases.test.js | 2 +- ...pWeb.test.js => HotTestStepWeb.hottest.js} | 0 .../rspack-test-tools/tests/Stats.test.js | 2 +- .../tests/WatchTestCases.longtest.js | 6 +- .../tests/__snapshots__/Stats.test.js.snap | 74 ++- .../rspack-test-tools/tests/fixtures/a.js | 3 + .../tests/fixtures/abc-query.js | 3 + .../rspack-test-tools/tests/fixtures/abc.js | 3 + .../rspack-test-tools/tests/fixtures/abc.txt | 1 + .../rspack-test-tools/tests/fixtures/asmjs.js | 22 + .../rspack-test-tools/tests/fixtures/b.js | 6 + .../tests/fixtures/browserslist/package.json | 6 + .../buildDependencies/definedValue.js | 1 + .../fixtures/buildDependencies/esm-cjs-dep.js | 1 + .../fixtures/buildDependencies/esm-dep.mjs | 1 + .../tests/fixtures/buildDependencies/esm.mjs | 9 + .../tests/fixtures/buildDependencies/index.js | 11 + .../fixtures/buildDependencies/loader.js | 6 + .../fixtures/buildDependencies/module.js | 1 + .../tests/fixtures/buildDependencies/run.js | 106 +++++ .../rspack-test-tools/tests/fixtures/c.js | 4 + .../tests/fixtures/callback-loader.js | 5 + .../tests/fixtures/chunk-b.js | 3 + .../tests/fixtures/chunks.js | 3 + .../tests/fixtures/complex.js | 13 + .../tests/fixtures/count-loader.js | 6 + .../rspack-test-tools/tests/fixtures/d.js | 1 + .../tests/fixtures/delay-loader.js | 7 + .../tests/fixtures/empty-dependency.js | 5 + .../tests/fixtures/errors/abc.html | 6 + .../fixtures/errors/add-comment-loader.js | 4 + .../fixtures/errors/async-error-loader.js | 6 + .../tests/fixtures/errors/case-sensitive.js | 2 + .../fixtures/errors/emit-error-loader.js | 6 + .../entry-point-error-loader-required.js | 1 + .../tests/fixtures/errors/entry-point.js} | 0 .../tests/fixtures/errors/file.js} | 0 .../tests/fixtures/errors/has-syntax-error.js | 3 + .../tests/fixtures/errors/identity-loader.js | 4 + .../fixtures/errors/irregular-error-loader.js | 11 + .../tests/fixtures/errors/missingFile.js | 12 + .../errors/module-exports-object-loader.js | 1 + .../errors/module-exports-string-loader.js | 1 + .../errors/module-level-throw-error-loader.js | 1 + .../fixtures/errors/module.parent.require.js | 1 + .../fixtures/errors/no-errors-deprecate.js | 1 + .../tests/fixtures/errors/no-return-loader.js | 2 + .../tests/fixtures/errors/not-a-json.js} | 0 .../fixtures/errors/require.extensions.js | 1 + .../fixtures/errors/require.main.require.js | 1 + .../errors/resolve-fail-esm/answer.js | 1 + .../fixtures/errors/resolve-fail-esm/index.js | 1 + .../errors/resolve-fail-esm/package.json | 3 + .../errors/return-undefined-loader.js | 1 + .../fixtures/errors/throw-error-loader.js | 4 + .../fixtures/errors/throw-error-plugin.js | 7 + .../rspack-test-tools/tests/fixtures/esm/a.js | 2 + .../tests/fixtures/esm/abc.js | 5 + .../rspack-test-tools/tests/fixtures/esm/b.js | 2 + .../rspack-test-tools/tests/fixtures/esm/c.js | 2 + .../rspack-test-tools/tests/fixtures/font.ttf | Bin 0 -> 2830 bytes .../tests/fixtures/items/item (0).js | 1 + .../tests/fixtures/items/item (1).js | 1 + .../tests/fixtures/items/item (2).js | 1 + .../tests/fixtures/items/item (3).js | 1 + .../tests/fixtures/items/item (4).js | 1 + .../tests/fixtures/items/item (5).js | 1 + .../tests/fixtures/items/item (6).js | 1 + .../tests/fixtures/items/item (7).js | 1 + .../tests/fixtures/items/item (8).js | 1 + .../tests/fixtures/items/item (9).js | 1 + .../rspack-test-tools/tests/fixtures/main1.js | 10 + .../rspack-test-tools/tests/fixtures/main2.js | 12 + .../rspack-test-tools/tests/fixtures/main3.js | 4 + .../rspack-test-tools/tests/fixtures/main4.js | 2 + .../tests/fixtures/missing-file.js | 5 + .../tests/fixtures/nodetest/entry.js | 7 + .../tests/fixtures/nodetest/file456.js | 1 + .../tests/fixtures/nodetest/file567.js | 3 + .../tests/fixtures/subdir/watched-file.txt} | 0 .../tests/fixtures/watch/src/index.js | 5 + .../tests/fixtures/watch/src/local.js | 2 + .../tests/fixtures/watched-file.txt} | 0 .../tests/hashCases/full-hash/test.config.js | 0 .../hashCases/full-hash/version0-copy/foo.js | 0 .../full-hash/version0-copy/index.js | 0 .../tests/hashCases/full-hash/version0/foo.js | 0 .../hashCases/full-hash/version0/index.js | 0 .../tests/hashCases/full-hash/version1/foo.js | 0 .../hashCases/full-hash/version1/index.js | 0 .../hashCases/full-hash/webpack.config.js | 0 .../package-path-change/test.config.js | 0 .../version0-copy/index.js | 0 .../node_modules/package/package.json | 0 .../node_modules/package/package0.js | 0 .../package-path-change/version0/index.js | 0 .../node_modules/package/package.json | 0 .../version0/node_modules/package/package0.js | 0 .../package-path-change/version1/index.js | 0 .../node_modules/package/package.json | 0 .../version1/node_modules/package/package1.js | 0 .../package-path-change/webpack.config.js | 0 .../provided-dependency-order/index.js | 0 .../provided-dependency-order/test.config.js | 0 .../webpack.config.js | 0 .../real-content-hash-consistent/src/file.png | 0 .../real-content-hash-consistent/src/index.js | 0 .../test.config.js | 0 .../webpack.config.js | 0 .../tests/hashCases/real-content-hash/a/a.js | 0 .../tests/hashCases/real-content-hash/a/b.js | 0 .../hashCases/real-content-hash/a/file.jpg | 0 .../hashCases/real-content-hash/a/file.png | 0 .../hashCases/real-content-hash/a/index.js | 0 .../hashCases/real-content-hash/a/lazy.js | 0 .../hashCases/real-content-hash/a/module.js | 0 .../tests/hashCases/real-content-hash/b/a.js | 0 .../tests/hashCases/real-content-hash/b/b.js | 0 .../hashCases/real-content-hash/b/file.jpg | 0 .../hashCases/real-content-hash/b/file.png | 0 .../hashCases/real-content-hash/b/index.js | 0 .../hashCases/real-content-hash/b/lazy.js | 0 .../hashCases/real-content-hash/b/module.js | 0 .../real-content-hash/test.config.js | 0 .../real-content-hash/webpack.config.js | 0 packages/rspack-test-tools/tests/package.json | 8 + .../tests/statsAPICases/basic.js | 32 +- .../tests/statsAPICases/child-compiler.js | 4 +- .../tests/statsAPICases/to-string.js | 6 +- .../tests/statsAPICases/verbose-time.js | 6 - .../compiler/multiply-compiler/0/entry1.js | 0 .../compiler/multiply-compiler/0/entry2.js | 0 .../compiler/multiply-compiler/0/file.js | 0 .../compiler/multiply-compiler/1/file.js | 0 .../multiply-compiler/webpack.config.js | 0 .../context/out-of-context/0/bar.less | 0 .../context/out-of-context/0/src/foo.less | 0 .../context/out-of-context/0/src/index.js | 0 .../context/out-of-context/1/bar.less | 0 .../context/out-of-context/2/bar.less | 0 .../context/out-of-context/webpack.config.js | 0 packages/rspack/tests/HashTestCases.test.js | 60 --- .../rspack/tests/WatchTestCases.longtest.js | 5 - .../rspack/tests/WatchTestCases.template.js | 442 ------------------ 154 files changed, 472 insertions(+), 636 deletions(-) delete mode 100644 packages/rspack-test-tools/jest.config.compat.js delete mode 100644 packages/rspack-test-tools/jest.config.legacy.js rename packages/rspack-test-tools/tests/{HotTestStepWeb.test.js => HotTestStepWeb.hottest.js} (100%) create mode 100644 packages/rspack-test-tools/tests/fixtures/a.js create mode 100644 packages/rspack-test-tools/tests/fixtures/abc-query.js create mode 100644 packages/rspack-test-tools/tests/fixtures/abc.js create mode 100644 packages/rspack-test-tools/tests/fixtures/abc.txt create mode 100644 packages/rspack-test-tools/tests/fixtures/asmjs.js create mode 100644 packages/rspack-test-tools/tests/fixtures/b.js create mode 100644 packages/rspack-test-tools/tests/fixtures/browserslist/package.json create mode 100644 packages/rspack-test-tools/tests/fixtures/buildDependencies/definedValue.js create mode 100644 packages/rspack-test-tools/tests/fixtures/buildDependencies/esm-cjs-dep.js create mode 100644 packages/rspack-test-tools/tests/fixtures/buildDependencies/esm-dep.mjs create mode 100644 packages/rspack-test-tools/tests/fixtures/buildDependencies/esm.mjs create mode 100644 packages/rspack-test-tools/tests/fixtures/buildDependencies/index.js create mode 100644 packages/rspack-test-tools/tests/fixtures/buildDependencies/loader.js create mode 100644 packages/rspack-test-tools/tests/fixtures/buildDependencies/module.js create mode 100644 packages/rspack-test-tools/tests/fixtures/buildDependencies/run.js create mode 100644 packages/rspack-test-tools/tests/fixtures/c.js create mode 100644 packages/rspack-test-tools/tests/fixtures/callback-loader.js create mode 100644 packages/rspack-test-tools/tests/fixtures/chunk-b.js create mode 100644 packages/rspack-test-tools/tests/fixtures/chunks.js create mode 100644 packages/rspack-test-tools/tests/fixtures/complex.js create mode 100644 packages/rspack-test-tools/tests/fixtures/count-loader.js create mode 100644 packages/rspack-test-tools/tests/fixtures/d.js create mode 100644 packages/rspack-test-tools/tests/fixtures/delay-loader.js create mode 100644 packages/rspack-test-tools/tests/fixtures/empty-dependency.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/abc.html create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/add-comment-loader.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/async-error-loader.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/case-sensitive.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/emit-error-loader.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/entry-point-error-loader-required.js rename packages/{rspack/tests/hashCases/real-content-hash-consistent/src/file.png => rspack-test-tools/tests/fixtures/errors/entry-point.js} (100%) rename packages/{rspack/tests/hashCases/real-content-hash/a/file.jpg => rspack-test-tools/tests/fixtures/errors/file.js} (100%) create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/has-syntax-error.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/identity-loader.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/irregular-error-loader.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/missingFile.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/module-exports-object-loader.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/module-exports-string-loader.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/module-level-throw-error-loader.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/module.parent.require.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/no-errors-deprecate.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/no-return-loader.js rename packages/{rspack/tests/hashCases/real-content-hash/a/file.png => rspack-test-tools/tests/fixtures/errors/not-a-json.js} (100%) create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/require.extensions.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/require.main.require.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm/answer.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm/index.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm/package.json create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/return-undefined-loader.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/throw-error-loader.js create mode 100644 packages/rspack-test-tools/tests/fixtures/errors/throw-error-plugin.js create mode 100644 packages/rspack-test-tools/tests/fixtures/esm/a.js create mode 100644 packages/rspack-test-tools/tests/fixtures/esm/abc.js create mode 100644 packages/rspack-test-tools/tests/fixtures/esm/b.js create mode 100644 packages/rspack-test-tools/tests/fixtures/esm/c.js create mode 100644 packages/rspack-test-tools/tests/fixtures/font.ttf create mode 100644 packages/rspack-test-tools/tests/fixtures/items/item (0).js create mode 100644 packages/rspack-test-tools/tests/fixtures/items/item (1).js create mode 100644 packages/rspack-test-tools/tests/fixtures/items/item (2).js create mode 100644 packages/rspack-test-tools/tests/fixtures/items/item (3).js create mode 100644 packages/rspack-test-tools/tests/fixtures/items/item (4).js create mode 100644 packages/rspack-test-tools/tests/fixtures/items/item (5).js create mode 100644 packages/rspack-test-tools/tests/fixtures/items/item (6).js create mode 100644 packages/rspack-test-tools/tests/fixtures/items/item (7).js create mode 100644 packages/rspack-test-tools/tests/fixtures/items/item (8).js create mode 100644 packages/rspack-test-tools/tests/fixtures/items/item (9).js create mode 100644 packages/rspack-test-tools/tests/fixtures/main1.js create mode 100644 packages/rspack-test-tools/tests/fixtures/main2.js create mode 100644 packages/rspack-test-tools/tests/fixtures/main3.js create mode 100644 packages/rspack-test-tools/tests/fixtures/main4.js create mode 100644 packages/rspack-test-tools/tests/fixtures/missing-file.js create mode 100644 packages/rspack-test-tools/tests/fixtures/nodetest/entry.js create mode 100644 packages/rspack-test-tools/tests/fixtures/nodetest/file456.js create mode 100644 packages/rspack-test-tools/tests/fixtures/nodetest/file567.js rename packages/{rspack/tests/hashCases/real-content-hash/b/file.jpg => rspack-test-tools/tests/fixtures/subdir/watched-file.txt} (100%) create mode 100644 packages/rspack-test-tools/tests/fixtures/watch/src/index.js create mode 100644 packages/rspack-test-tools/tests/fixtures/watch/src/local.js rename packages/{rspack/tests/hashCases/real-content-hash/b/file.png => rspack-test-tools/tests/fixtures/watched-file.txt} (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/full-hash/test.config.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/full-hash/version0-copy/foo.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/full-hash/version0-copy/index.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/full-hash/version0/foo.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/full-hash/version0/index.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/full-hash/version1/foo.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/full-hash/version1/index.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/full-hash/webpack.config.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/package-path-change/test.config.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/package-path-change/version0-copy/index.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/package-path-change/version0-copy/node_modules/package/package.json (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/package-path-change/version0-copy/node_modules/package/package0.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/package-path-change/version0/index.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/package-path-change/version0/node_modules/package/package.json (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/package-path-change/version0/node_modules/package/package0.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/package-path-change/version1/index.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/package-path-change/version1/node_modules/package/package.json (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/package-path-change/version1/node_modules/package/package1.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/package-path-change/webpack.config.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/provided-dependency-order/index.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/provided-dependency-order/test.config.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/provided-dependency-order/webpack.config.js (100%) create mode 100644 packages/rspack-test-tools/tests/hashCases/real-content-hash-consistent/src/file.png rename packages/{rspack => rspack-test-tools}/tests/hashCases/real-content-hash-consistent/src/index.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/real-content-hash-consistent/test.config.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/real-content-hash-consistent/webpack.config.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/real-content-hash/a/a.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/real-content-hash/a/b.js (100%) create mode 100644 packages/rspack-test-tools/tests/hashCases/real-content-hash/a/file.jpg create mode 100644 packages/rspack-test-tools/tests/hashCases/real-content-hash/a/file.png rename packages/{rspack => rspack-test-tools}/tests/hashCases/real-content-hash/a/index.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/real-content-hash/a/lazy.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/real-content-hash/a/module.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/real-content-hash/b/a.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/real-content-hash/b/b.js (100%) create mode 100644 packages/rspack-test-tools/tests/hashCases/real-content-hash/b/file.jpg create mode 100644 packages/rspack-test-tools/tests/hashCases/real-content-hash/b/file.png rename packages/{rspack => rspack-test-tools}/tests/hashCases/real-content-hash/b/index.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/real-content-hash/b/lazy.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/real-content-hash/b/module.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/real-content-hash/test.config.js (100%) rename packages/{rspack => rspack-test-tools}/tests/hashCases/real-content-hash/webpack.config.js (100%) create mode 100644 packages/rspack-test-tools/tests/package.json rename packages/{rspack => rspack-test-tools}/tests/watchCases/compiler/multiply-compiler/0/entry1.js (100%) rename packages/{rspack => rspack-test-tools}/tests/watchCases/compiler/multiply-compiler/0/entry2.js (100%) rename packages/{rspack => rspack-test-tools}/tests/watchCases/compiler/multiply-compiler/0/file.js (100%) rename packages/{rspack => rspack-test-tools}/tests/watchCases/compiler/multiply-compiler/1/file.js (100%) rename packages/{rspack => rspack-test-tools}/tests/watchCases/compiler/multiply-compiler/webpack.config.js (100%) rename packages/{rspack => rspack-test-tools}/tests/watchCases/context/out-of-context/0/bar.less (100%) rename packages/{rspack => rspack-test-tools}/tests/watchCases/context/out-of-context/0/src/foo.less (100%) rename packages/{rspack => rspack-test-tools}/tests/watchCases/context/out-of-context/0/src/index.js (100%) rename packages/{rspack => rspack-test-tools}/tests/watchCases/context/out-of-context/1/bar.less (100%) rename packages/{rspack => rspack-test-tools}/tests/watchCases/context/out-of-context/2/bar.less (100%) rename packages/{rspack => rspack-test-tools}/tests/watchCases/context/out-of-context/webpack.config.js (100%) delete mode 100644 packages/rspack/tests/HashTestCases.test.js delete mode 100644 packages/rspack/tests/WatchTestCases.longtest.js delete mode 100644 packages/rspack/tests/WatchTestCases.template.js diff --git a/.github/workflows/test-ng.yml b/.github/workflows/test-ng.yml index 4531e95342a..00becbe73bb 100644 --- a/.github/workflows/test-ng.yml +++ b/.github/workflows/test-ng.yml @@ -63,7 +63,7 @@ jobs: - name: Test new runner run: | set -e; - OUTPUT=$((pnpm run test:ng --no-colors --silent=true --force-exit 2>&1 && echo "Test new runner successed" || echo "Test new runner failed") | tail --bytes=50000) + OUTPUT=$((pnpm run test --no-colors --silent=true --force-exit 2>&1 && echo "Test new runner successed" || echo "Test new runner failed") | tail --bytes=50000) echo 'RESULT<> $GITHUB_ENV echo "$OUTPUT" >> $GITHUB_ENV echo 'EOF' >> $GITHUB_ENV diff --git a/.prettierignore b/.prettierignore index a0a9bf45496..bbd7e1b5c17 100644 --- a/.prettierignore +++ b/.prettierignore @@ -11,20 +11,10 @@ packages/rspack/src/config/schema.check.js packages/**/etc/**/* packages/rspack/tests/fixtures/**/* -packages/rspack/tests/statsCases/**/* -packages/rspack/tests/cases/**/* -packages/rspack/tests/configCases/**/* -packages/rspack/tests/hotCases/**/* -packages/rspack/tests/diagnostics/**/* packages/rspack/tests/js/**/* packages/rspack/tests/copyPlugin/build/**/* packages/rspack-test-tools/template/**/* -packages/rspack-test-tools/tests/statsCases/**/* -packages/rspack-test-tools/tests/cases/**/* -packages/rspack-test-tools/tests/configCases/**/* -packages/rspack-test-tools/tests/hotCases/**/* -packages/rspack-test-tools/tests/diagnostics/**/* -packages/rspack-test-tools/tests/js/**/* +packages/rspack-test-tools/tests/**/* 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/**/* diff --git a/package.json b/package.json index 8ee21567145..9fc42798481 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "test:diff": "pnpm --filter \"@rspack/*\" test:diff", "test:hot": "pnpm --filter \"@rspack/*\" test:hot", "test:unit": "pnpm --filter \"@rspack/*\" test", - "test:ng": "pnpm --filter \"@rspack/*\" test:ng", "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:webpack": "pnpm --filter \"webpack-test\" test:metric", diff --git a/packages/rspack-test-tools/etc/api.md b/packages/rspack-test-tools/etc/api.md index 4a547ebfe2e..fcb16b5ba78 100644 --- a/packages/rspack-test-tools/etc/api.md +++ b/packages/rspack-test-tools/etc/api.md @@ -926,10 +926,6 @@ export class StatsAPITaskProcessor extends SimpleTaskPr // (undocumented) static addSnapshotSerializer(): void; // (undocumented) - after(context: ITestContext): Promise; - // (undocumented) - before(context: ITestContext): Promise; - // (undocumented) check(env: ITestEnv, context: ITestContext): Promise; // (undocumented) compiler(context: ITestContext): Promise; diff --git a/packages/rspack-test-tools/jest.config.compat.js b/packages/rspack-test-tools/jest.config.compat.js deleted file mode 100644 index 9d973c8dcba..00000000000 --- a/packages/rspack-test-tools/jest.config.compat.js +++ /dev/null @@ -1,21 +0,0 @@ -const config = require("./jest.config"); - -/** @type {import('jest').Config} */ -module.exports = { - ...config, - testMatch: [ - "/tests/Compiler.test.js", - "/tests/Builtin.test.js", - "/tests/Defaults.unittest.js", - "/tests/Stats.unittest.js", - "/tests/TreeShaking.test.js", - "/tests/ConfigTestCases.basictest.js", - "/tests/TestCasesNormal.basictest.js", - "/tests/HotTestCasesWeb.test.js", - "/tests/HotTestCasesNode.test.js", - "/tests/HotTestCasesWebWorker.test.js", - "/tests/Diagnostics.test.js", - "/tests/HookCases.test.js", - "/tests/StatsTestCases.basictest.js" - ] -}; diff --git a/packages/rspack-test-tools/jest.config.hot.js b/packages/rspack-test-tools/jest.config.hot.js index c8fd382a655..98ef5a58377 100644 --- a/packages/rspack-test-tools/jest.config.hot.js +++ b/packages/rspack-test-tools/jest.config.hot.js @@ -3,5 +3,5 @@ const config = require("./jest.config"); /** @type {import('jest').Config} */ module.exports = { ...config, - testMatch: ["/tests/HotTestStepWeb.test.js"] + testMatch: ["/tests/*.hottest.js"] }; diff --git a/packages/rspack-test-tools/jest.config.js b/packages/rspack-test-tools/jest.config.js index 4eddfb99e41..9a9eb113c36 100644 --- a/packages/rspack-test-tools/jest.config.js +++ b/packages/rspack-test-tools/jest.config.js @@ -11,8 +11,7 @@ const config = { "/tests/*.test.js", "/tests/*.basictest.js", "/tests/*.longtest.js", - "/tests/*.unittest.js", - "/tests/*.difftest.js" + "/tests/*.unittest.js" ], moduleNameMapper: { // Fixed jest-serialize-path not working when non-ascii code contains. diff --git a/packages/rspack-test-tools/jest.config.legacy.js b/packages/rspack-test-tools/jest.config.legacy.js deleted file mode 100644 index 4600d4ca745..00000000000 --- a/packages/rspack-test-tools/jest.config.legacy.js +++ /dev/null @@ -1,23 +0,0 @@ -const config = require("./jest.config"); - -/** @type {import('jest').Config} */ -module.exports = { - ...config, - // can only use filename otherwise will fail by snapshot obsolete - testPathIgnorePatterns: [ - "Compiler.test.js", - "Defaults.unittest.js", - "Stats.test.js", - "TreeShaking.test.js", - "Builtin.test.js", - "HotTestStepWeb.test.js", - "ConfigTestCases.basictest.js", - "TestCasesNormal.basictest.js", - "HotTestCasesWeb.test.js", - "HotTestCasesWebWorker.test.js", - "HotTestCasesNode.test.js", - "Diagnostics.test.js", - "StatsTestCases.basictest.js", - ".difftest.js" - ] -}; diff --git a/packages/rspack-test-tools/package.json b/packages/rspack-test-tools/package.json index d8b5f3dd2a1..26768ec4009 100644 --- a/packages/rspack-test-tools/package.json +++ b/packages/rspack-test-tools/package.json @@ -16,8 +16,7 @@ "build:viewer": "rspack build", "dev:viewer": "rspack serve", "dev": "tsc -b -w", - "test": "cross-env NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.compat.js", - "test:ng": "cross-env SNAPSHOT=legacy NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.legacy.js", + "test": "cross-env NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.js", "test:hot": "cross-env RSPACK_HOT_TEST=true NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.hot.js", "test:diff": "cross-env RSPACK_DIFF=true NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.diff.js", "api-extractor": "api-extractor run --verbose", diff --git a/packages/rspack-test-tools/src/processor/stats-api.ts b/packages/rspack-test-tools/src/processor/stats-api.ts index cab0050d3cb..61e825baa49 100644 --- a/packages/rspack-test-tools/src/processor/stats-api.ts +++ b/packages/rspack-test-tools/src/processor/stats-api.ts @@ -9,10 +9,7 @@ import { } from "../type"; import { createFsFromVolume, Volume } from "memfs"; import fs from "fs"; -import path from "path"; const serializer = require("jest-serializer-path"); -const FAKE_CWD = path.resolve(__dirname, "../../../rspack"); -const CWD = process.cwd(); export interface IStatsAPITaskProcessorOptions { options?: (context: ITestContext) => TCompilerOptions; @@ -55,13 +52,6 @@ export class StatsAPITaskProcessor< await this._statsAPIOptions.check?.(stats!, compiler.getCompiler()!); } - async before(context: ITestContext): Promise { - process.chdir(this._statsAPIOptions.cwd || FAKE_CWD); - } - async after(context: ITestContext): Promise { - process.chdir(CWD); - } - static addSnapshotSerializer() { expect.addSnapshotSerializer(serializer); } diff --git a/packages/rspack-test-tools/tests/HashTestCases.test.js b/packages/rspack-test-tools/tests/HashTestCases.test.js index 79c32a2b59b..5da8d2bb07a 100644 --- a/packages/rspack-test-tools/tests/HashTestCases.test.js +++ b/packages/rspack-test-tools/tests/HashTestCases.test.js @@ -3,7 +3,7 @@ const fs = require("fs"); const { createHashCase } = require(".."); const NAME = "HashTestCases"; -const caseDir = path.resolve(__dirname, "../../rspack/tests/hashCases"); +const caseDir = path.resolve(__dirname, "./hashCases"); const tests = fs .readdirSync(caseDir) diff --git a/packages/rspack-test-tools/tests/HotTestStepWeb.test.js b/packages/rspack-test-tools/tests/HotTestStepWeb.hottest.js similarity index 100% rename from packages/rspack-test-tools/tests/HotTestStepWeb.test.js rename to packages/rspack-test-tools/tests/HotTestStepWeb.hottest.js diff --git a/packages/rspack-test-tools/tests/Stats.test.js b/packages/rspack-test-tools/tests/Stats.test.js index bb26ca80c96..f54f42897ab 100644 --- a/packages/rspack-test-tools/tests/Stats.test.js +++ b/packages/rspack-test-tools/tests/Stats.test.js @@ -1,6 +1,6 @@ const path = require("path"); const fs = require("fs"); -const srcDir = path.resolve(__dirname, "../../rspack/tests"); +const srcDir = __dirname; const caseDir = path.resolve(__dirname, "./statsAPICases"); const { StatsAPITaskProcessor, TestContext, ECompilerType } = require(".."); diff --git a/packages/rspack-test-tools/tests/WatchTestCases.longtest.js b/packages/rspack-test-tools/tests/WatchTestCases.longtest.js index 40f6b75b586..c5a2c34be29 100644 --- a/packages/rspack-test-tools/tests/WatchTestCases.longtest.js +++ b/packages/rspack-test-tools/tests/WatchTestCases.longtest.js @@ -2,9 +2,9 @@ const path = require("path"); const { describeByWalk, createWatchCase } = require(".."); const NAME = "WatchTestCases"; -const caseDir = path.resolve(__dirname, "../../rspack/tests/watchCases"); -const distDir = path.resolve(__dirname, `../../rspack/tests/js/${NAME}`); -const tempDir = path.resolve(__dirname, `../../rspack/tests/js/${NAME}-src`); +const caseDir = path.resolve(__dirname, "./watchCases"); +const distDir = path.resolve(__dirname, `./js/${NAME}`); +const tempDir = path.resolve(__dirname, `./js/${NAME}-src`); describeByWalk(NAME, caseDir, distDir, (name, src, dist) => { createWatchCase( diff --git a/packages/rspack-test-tools/tests/__snapshots__/Stats.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/Stats.test.js.snap index 51314fa4158..7788ceb5a6a 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/Stats.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/Stats.test.js.snap @@ -28,6 +28,7 @@ Object { "chunks": Array [ Object { "auxiliaryFiles": Array [], + "childrenByOrder": Object {}, "entry": true, "files": Array [ "main.js", @@ -94,6 +95,7 @@ Object { Object { "auxiliaryFiles": Array [], "children": Array [], + "childrenByOrder": Object {}, "entry": true, "files": Array [ "main.js", @@ -115,7 +117,9 @@ Object { "moduleType": "javascript/auto", "name": "./fixtures/a.js", "nameForCondition": "/tests/fixtures/a.js", - "optimizationBailout": Array [], + "optimizationBailout": Array [ + "Statement with side_effects in source code at ./fixtures/a.js:1:0-3:2", + ], "orphan": false, "providedExports": Array [], "reasons": Array [ @@ -133,7 +137,7 @@ Object { }; ", "type": "module", - "usedExports": null, + "usedExports": Array [], }, ], "names": Array [ @@ -180,7 +184,9 @@ Object { "moduleType": "javascript/auto", "name": "./fixtures/a.js", "nameForCondition": "/tests/fixtures/a.js", - "optimizationBailout": Array [], + "optimizationBailout": Array [ + "Statement with side_effects in source code at ./fixtures/a.js:1:0-3:2", + ], "orphan": false, "providedExports": Array [], "reasons": Array [ @@ -198,7 +204,7 @@ Object { }; ", "type": "module", - "usedExports": null, + "usedExports": Array [], }, ], "namedChunkGroups": Object { @@ -253,6 +259,7 @@ Object { Object { "auxiliaryFiles": Array [], "children": Array [], + "childrenByOrder": Object {}, "entry": true, "files": Array [ "main.js", @@ -740,7 +747,7 @@ Object { "hotModuleReplacement": false, }, "name": "main.js", - "size": 386, + "size": 378, "type": "asset", }, ], @@ -754,6 +761,7 @@ Object { Object { "auxiliaryFiles": Array [], "children": Array [], + "childrenByOrder": Object {}, "entry": true, "files": Array [ "main.js", @@ -786,7 +794,9 @@ Object { "moduleType": "javascript/auto", "name": "./fixtures/a.js", "nameForCondition": "/tests/fixtures/a.js", - "optimizationBailout": Array [], + "optimizationBailout": Array [ + "Statement with side_effects in source code at ./fixtures/a.js:1:0-3:2", + ], "orphan": false, "providedExports": Array [], "reasons": Array [ @@ -826,7 +836,9 @@ Object { "moduleType": "javascript/auto", "name": "./fixtures/a.js?a=1", "nameForCondition": "/tests/fixtures/a.js", - "optimizationBailout": Array [], + "optimizationBailout": Array [ + "Statement with side_effects in source code at ./fixtures/a.js?a=1:1:0-3:2", + ], "orphan": false, "providedExports": Array [], "reasons": Array [ @@ -866,7 +878,9 @@ Object { "moduleType": "javascript/auto", "name": "./fixtures/c.js?c=3", "nameForCondition": "/tests/fixtures/c.js", - "optimizationBailout": Array [], + "optimizationBailout": Array [ + "Statement with side_effects in source code at ./fixtures/c.js?c=3:1:0-4:2", + ], "orphan": false, "providedExports": Array [], "reasons": Array [ @@ -901,9 +915,14 @@ Object { "moduleType": "javascript/auto", "name": "./fixtures/abc-query.js", "nameForCondition": "/tests/fixtures/abc-query.js", - "optimizationBailout": Array [], + "optimizationBailout": Array [ + "Statement with side_effects in source code at ./fixtures/abc-query.js:1:0-31", + ], "orphan": false, - "providedExports": Array [], + "providedExports": Array [ + "a", + "c", + ], "reasons": Array [ Object { "moduleId": undefined, @@ -919,7 +938,7 @@ Object { exports.c = require(\\"./c?c=3\\"); ", "type": "module", - "usedExports": null, + "usedExports": Array [], }, ], "names": Array [ @@ -936,10 +955,10 @@ exports.c = require(\\"./c?c=3\\"); "assets": Array [ Object { "name": "main.js", - "size": 386, + "size": 378, }, ], - "assetsSize": 386, + "assetsSize": 378, "chunks": Array [ "909", ], @@ -949,7 +968,7 @@ exports.c = require(\\"./c?c=3\\"); "errors": Array [], "errorsCount": 0, "filteredModules": undefined, - "hash": "d74b6e06f8e6041c6743", + "hash": "7faf022bcc5d421ae464", "logging": Object {}, "modules": Array [ Object { @@ -977,7 +996,9 @@ exports.c = require(\\"./c?c=3\\"); "moduleType": "javascript/auto", "name": "./fixtures/a.js", "nameForCondition": "/tests/fixtures/a.js", - "optimizationBailout": Array [], + "optimizationBailout": Array [ + "Statement with side_effects in source code at ./fixtures/a.js:1:0-3:2", + ], "orphan": false, "providedExports": Array [], "reasons": Array [ @@ -1017,7 +1038,9 @@ exports.c = require(\\"./c?c=3\\"); "moduleType": "javascript/auto", "name": "./fixtures/a.js?a=1", "nameForCondition": "/tests/fixtures/a.js", - "optimizationBailout": Array [], + "optimizationBailout": Array [ + "Statement with side_effects in source code at ./fixtures/a.js?a=1:1:0-3:2", + ], "orphan": false, "providedExports": Array [], "reasons": Array [ @@ -1057,7 +1080,9 @@ exports.c = require(\\"./c?c=3\\"); "moduleType": "javascript/auto", "name": "./fixtures/c.js?c=3", "nameForCondition": "/tests/fixtures/c.js", - "optimizationBailout": Array [], + "optimizationBailout": Array [ + "Statement with side_effects in source code at ./fixtures/c.js?c=3:1:0-4:2", + ], "orphan": false, "providedExports": Array [], "reasons": Array [ @@ -1092,9 +1117,14 @@ exports.c = require(\\"./c?c=3\\"); "moduleType": "javascript/auto", "name": "./fixtures/abc-query.js", "nameForCondition": "/tests/fixtures/abc-query.js", - "optimizationBailout": Array [], + "optimizationBailout": Array [ + "Statement with side_effects in source code at ./fixtures/abc-query.js:1:0-31", + ], "orphan": false, - "providedExports": Array [], + "providedExports": Array [ + "a", + "c", + ], "reasons": Array [ Object { "moduleId": undefined, @@ -1110,7 +1140,7 @@ exports.c = require(\\"./c?c=3\\"); exports.c = require(\\"./c?c=3\\"); ", "type": "module", - "usedExports": null, + "usedExports": Array [], }, ], "namedChunkGroups": Object { @@ -1118,10 +1148,10 @@ exports.c = require(\\"./c?c=3\\"); "assets": Array [ Object { "name": "main.js", - "size": 386, + "size": 378, }, ], - "assetsSize": 386, + "assetsSize": 378, "chunks": Array [ "909", ], diff --git a/packages/rspack-test-tools/tests/fixtures/a.js b/packages/rspack-test-tools/tests/fixtures/a.js new file mode 100644 index 00000000000..9e3aafb74c8 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/a.js @@ -0,0 +1,3 @@ +module.exports = function a() { + return "This is a"; +}; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/abc-query.js b/packages/rspack-test-tools/tests/fixtures/abc-query.js new file mode 100644 index 00000000000..eb18ea7bf12 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/abc-query.js @@ -0,0 +1,3 @@ +exports.a = require("./a?a=1"); +// exports.b = require("./b?b=2"); +exports.c = require("./c?c=3"); diff --git a/packages/rspack-test-tools/tests/fixtures/abc.js b/packages/rspack-test-tools/tests/fixtures/abc.js new file mode 100644 index 00000000000..ef3d2ccc79a --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/abc.js @@ -0,0 +1,3 @@ +exports.a = require("./a"); +exports.b = require("./b"); +exports.c = require("./c"); \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/abc.txt b/packages/rspack-test-tools/tests/fixtures/abc.txt new file mode 100644 index 00000000000..f2ba8f84ab5 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/abc.txt @@ -0,0 +1 @@ +abc \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/asmjs.js b/packages/rspack-test-tools/tests/fixtures/asmjs.js new file mode 100644 index 00000000000..59d2101f7ed --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/asmjs.js @@ -0,0 +1,22 @@ +module.exports = function a() { + function b() { + "use asm"; + if (0 == 0) { + return 1 == 1 ? 101 : 102; + } else { + return 0 == 1 ? 103 : 104; + } + } + function c() { + if (0 == 0) { + return 1 == 1 ? 105 : 106; + } else { + return 0 == 1 ? 107 : 108; + } + } + var d = (function() { + "use asm"; + return 1 == 1 ? 109 : 110; + })(); + return b() + c() + d; +}; diff --git a/packages/rspack-test-tools/tests/fixtures/b.js b/packages/rspack-test-tools/tests/fixtures/b.js new file mode 100644 index 00000000000..7e6505aa822 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/b.js @@ -0,0 +1,6 @@ +module.exports = function b() { + return "This is b"; +}; + +// Test CJS top-level return +return; diff --git a/packages/rspack-test-tools/tests/fixtures/browserslist/package.json b/packages/rspack-test-tools/tests/fixtures/browserslist/package.json new file mode 100644 index 00000000000..6c8665a9624 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/browserslist/package.json @@ -0,0 +1,6 @@ +{ + "name": "browserslist-test", + "browserslist": [ + "ie >= 9" + ] +} diff --git a/packages/rspack-test-tools/tests/fixtures/buildDependencies/definedValue.js b/packages/rspack-test-tools/tests/fixtures/buildDependencies/definedValue.js new file mode 100644 index 00000000000..c639052e2fb --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/buildDependencies/definedValue.js @@ -0,0 +1 @@ +module.exports = DEFINED_VALUE; diff --git a/packages/rspack-test-tools/tests/fixtures/buildDependencies/esm-cjs-dep.js b/packages/rspack-test-tools/tests/fixtures/buildDependencies/esm-cjs-dep.js new file mode 100644 index 00000000000..52d586a0e0e --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/buildDependencies/esm-cjs-dep.js @@ -0,0 +1 @@ +module.exports = require("../../js/buildDepsInput/esm-dependency"); diff --git a/packages/rspack-test-tools/tests/fixtures/buildDependencies/esm-dep.mjs b/packages/rspack-test-tools/tests/fixtures/buildDependencies/esm-dep.mjs new file mode 100644 index 00000000000..03e99c08cf8 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/buildDependencies/esm-dep.mjs @@ -0,0 +1 @@ +export { default } from "./esm-cjs-dep.js"; diff --git a/packages/rspack-test-tools/tests/fixtures/buildDependencies/esm.mjs b/packages/rspack-test-tools/tests/fixtures/buildDependencies/esm.mjs new file mode 100644 index 00000000000..6b8775cc057 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/buildDependencies/esm.mjs @@ -0,0 +1,9 @@ +export { default } from "./esm-dep.mjs"; +// prettier-ignore +import './esm-dep.mjs'; + +export const asyncDep = ( + await import("../../js/buildDepsInput/esm-async-dependency.mjs") +).default; +// prettier-ignore +await import('../../js/buildDepsInput/esm-async-dependency.mjs') diff --git a/packages/rspack-test-tools/tests/fixtures/buildDependencies/index.js b/packages/rspack-test-tools/tests/fixtures/buildDependencies/index.js new file mode 100644 index 00000000000..7fe06494fea --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/buildDependencies/index.js @@ -0,0 +1,11 @@ +/* global VALUE */ + +require("dep#with#hash/#.js"); +module.exports = { + // loader: require("./loader!"), + // config: VALUE, + // esmConfig: VALUE2, + // esmAsyncConfig: VALUE3, + // uncached: require("./module"), + // definedValue: require("./definedValue") +}; diff --git a/packages/rspack-test-tools/tests/fixtures/buildDependencies/loader.js b/packages/rspack-test-tools/tests/fixtures/buildDependencies/loader.js new file mode 100644 index 00000000000..ae9730e3293 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/buildDependencies/loader.js @@ -0,0 +1,6 @@ +// eslint-disable-next-line node/no-missing-require +const value = require("../../js/buildDepsInput/loader-dependency"); + +module.exports = () => { + return `module.exports = ${value};`; +}; diff --git a/packages/rspack-test-tools/tests/fixtures/buildDependencies/module.js b/packages/rspack-test-tools/tests/fixtures/buildDependencies/module.js new file mode 100644 index 00000000000..4cebe33cd98 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/buildDependencies/module.js @@ -0,0 +1 @@ +module.exports = VALUE_UNCACHEABLE; diff --git a/packages/rspack-test-tools/tests/fixtures/buildDependencies/run.js b/packages/rspack-test-tools/tests/fixtures/buildDependencies/run.js new file mode 100644 index 00000000000..c83b64a5121 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/buildDependencies/run.js @@ -0,0 +1,106 @@ +const path = require("path"); +const webpack = require("../../.."); +// eslint-disable-next-line node/no-missing-require +const value = require("../../js/buildDepsInput/config-dependency"); + +require("dep#with#hash/#.js"); + +process.exitCode = 1; + +const options = JSON.parse(process.argv[3]); + +const esm = +process.versions.modules >= 83; + +if (esm) { + require("require-dependency-with-exports"); + import("./esm.mjs").then(module => { + run(module); + }); +} else { + run({ default: 1, asyncDep: 1 }); +} + +function run({ default: value2, asyncDep: value3 }) { + const compiler = webpack( + { + mode: "development", + context: path.resolve(__dirname, "../../js/buildDepsInput"), + entry: path.resolve(__dirname, "./index"), + output: { + path: path.resolve(__dirname, "../../js/buildDeps/" + process.argv[2]), + libraryTarget: "commonjs2" + }, + plugins: [ + new webpack.DefinePlugin({ + VALUE: webpack.DefinePlugin.runtimeValue( + () => JSON.stringify(value), + { version: "no" } + ), + VALUE2: webpack.DefinePlugin.runtimeValue( + () => JSON.stringify(value2), + { version: "no" } + ), + VALUE3: webpack.DefinePlugin.runtimeValue( + () => JSON.stringify(value3), + { version: "no" } + ), + VALUE_UNCACHEABLE: webpack.DefinePlugin.runtimeValue( + () => JSON.stringify(value), + true + ), + DEFINED_VALUE: JSON.stringify(options.definedValue || "value") + }) + ], + infrastructureLogging: { + level: "verbose", + debug: /PackFile/ + }, + snapshot: { + // TODO remove webpack 6 + managedPaths: [/^(.+?[\\/]node_modules[\\/])/] + }, + cache: { + type: "filesystem", + cacheDirectory: path.resolve(__dirname, "../../js/buildDepsCache"), + buildDependencies: { + defaultWebpack: [], + config: [ + __filename, + path.resolve(__dirname, "../../../node_modules/.yarn-integrity") + ].concat(esm ? ["../../fixtures/buildDependencies/esm.mjs"] : []), + invalid: options.invalidBuildDependencies + ? ["should-fail-resolving"] + : [], + optionalDepsTest: [ + path.resolve(__dirname, "node_modules/dependency-with-optional") + + "/" + ] + } + } + }, + (err, stats) => { + if (err) { + return console.log(err); + } + if (stats.hasErrors()) { + return console.log(stats.toString({ all: false, errors: true })); + } + if (options.buildTwice) { + compiler.run((err, stats) => { + if (err) { + return console.log(err); + } + if (stats.hasErrors()) { + return console.log(stats.toString({ all: false, errors: true })); + } + process.exitCode = 0; + console.log("OK"); + }); + } else { + console.log(stats.toString()); + process.exitCode = 0; + console.log("OK"); + } + } + ); +} diff --git a/packages/rspack-test-tools/tests/fixtures/c.js b/packages/rspack-test-tools/tests/fixtures/c.js new file mode 100644 index 00000000000..e87b0d47d2e --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/c.js @@ -0,0 +1,4 @@ +module.exports = function b() { + require("./a"); + return "This is c"; +}; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/callback-loader.js b/packages/rspack-test-tools/tests/fixtures/callback-loader.js new file mode 100644 index 00000000000..81a7eed5d88 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/callback-loader.js @@ -0,0 +1,5 @@ +module.exports = function(content) { + var cb = this.getOptions().callback; + cb(this); + return content +} diff --git a/packages/rspack-test-tools/tests/fixtures/chunk-b.js b/packages/rspack-test-tools/tests/fixtures/chunk-b.js new file mode 100644 index 00000000000..92ac13a5e30 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/chunk-b.js @@ -0,0 +1,3 @@ +module.exports = () => { + return import(/* webpackChunkName: "chunkB" */ "./b"); +}; diff --git a/packages/rspack-test-tools/tests/fixtures/chunks.js b/packages/rspack-test-tools/tests/fixtures/chunks.js new file mode 100644 index 00000000000..e00bd76d855 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/chunks.js @@ -0,0 +1,3 @@ +require.ensure(["./a"], function(require) { + require("./b"); +}); \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/complex.js b/packages/rspack-test-tools/tests/fixtures/complex.js new file mode 100644 index 00000000000..c2017f719c4 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/complex.js @@ -0,0 +1,13 @@ +var complex1 = require("./lib/complex1"); +require.ensure(["./lib/complex1", "complexm/step2"], function(require) { + require("./lib/complex1"); + var a = function() {} + require.ensure(["complexm/step1"], function(require) { + require("./lib/complex1"); + var s1 = require("complexm/step1"); + var s2 = require("complexm/step2"); + console.log(s1); + console.log(s2); + }); +}); +console.log(complex1); diff --git a/packages/rspack-test-tools/tests/fixtures/count-loader.js b/packages/rspack-test-tools/tests/fixtures/count-loader.js new file mode 100644 index 00000000000..12b5ba61922 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/count-loader.js @@ -0,0 +1,6 @@ +let counter = 0; + +/** @type {import("@rspack/core").LoaderDefinition} */ +module.exports = function () { + return `module.exports = ${counter++};`; +}; diff --git a/packages/rspack-test-tools/tests/fixtures/d.js b/packages/rspack-test-tools/tests/fixtures/d.js new file mode 100644 index 00000000000..e02d60f55ad --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/d.js @@ -0,0 +1 @@ +module.exports = "This is d" \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/delay-loader.js b/packages/rspack-test-tools/tests/fixtures/delay-loader.js new file mode 100644 index 00000000000..34d23f4a392 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/delay-loader.js @@ -0,0 +1,7 @@ +/** @type {import("@rspack/core").LoaderDefinition} */ +module.exports = function (source) { + var cb = this.async(); + setTimeout(function () { + cb(null, source); + }, 500); +}; diff --git a/packages/rspack-test-tools/tests/fixtures/empty-dependency.js b/packages/rspack-test-tools/tests/fixtures/empty-dependency.js new file mode 100644 index 00000000000..a664a785e1f --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/empty-dependency.js @@ -0,0 +1,5 @@ +module.exports = function b() { + /* eslint-disable node/no-missing-require */ + require(""); + return "This is an empty dependency"; +}; diff --git a/packages/rspack-test-tools/tests/fixtures/errors/abc.html b/packages/rspack-test-tools/tests/fixtures/errors/abc.html new file mode 100644 index 00000000000..32a090d9528 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/abc.html @@ -0,0 +1,6 @@ + + + +

I love webpack :)

+ + diff --git a/packages/rspack-test-tools/tests/fixtures/errors/add-comment-loader.js b/packages/rspack-test-tools/tests/fixtures/errors/add-comment-loader.js new file mode 100644 index 00000000000..ed6dc02ceeb --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/add-comment-loader.js @@ -0,0 +1,4 @@ +/** @type {import("@rspack/core").LoaderDefinition} */ +module.exports = function (source) { + return source + "// some comment"; +}; diff --git a/packages/rspack-test-tools/tests/fixtures/errors/async-error-loader.js b/packages/rspack-test-tools/tests/fixtures/errors/async-error-loader.js new file mode 100644 index 00000000000..5bd4cbbad32 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/async-error-loader.js @@ -0,0 +1,6 @@ +/** @type {import("@rspack/core").LoaderDefinition} */ +module.exports = function (source) { + const callback = this.async(); + const error = new Error("this is a callback error"); + callback(error, source); +}; diff --git a/packages/rspack-test-tools/tests/fixtures/errors/case-sensitive.js b/packages/rspack-test-tools/tests/fixtures/errors/case-sensitive.js new file mode 100644 index 00000000000..f412246ca2e --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/case-sensitive.js @@ -0,0 +1,2 @@ +require("./file"); +require("./FILE"); \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/errors/emit-error-loader.js b/packages/rspack-test-tools/tests/fixtures/errors/emit-error-loader.js new file mode 100644 index 00000000000..9cc82f914af --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/emit-error-loader.js @@ -0,0 +1,6 @@ +/** @type {import("@rspack/core").LoaderDefinition} */ +module.exports = function (source) { + this.emitWarning(new Error("this is a warning")); + this.emitError(new Error("this is an error")); + return source; +}; diff --git a/packages/rspack-test-tools/tests/fixtures/errors/entry-point-error-loader-required.js b/packages/rspack-test-tools/tests/fixtures/errors/entry-point-error-loader-required.js new file mode 100644 index 00000000000..6811cb8072c --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/entry-point-error-loader-required.js @@ -0,0 +1 @@ +require("./emit-error-loader.js!./file"); diff --git a/packages/rspack/tests/hashCases/real-content-hash-consistent/src/file.png b/packages/rspack-test-tools/tests/fixtures/errors/entry-point.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash-consistent/src/file.png rename to packages/rspack-test-tools/tests/fixtures/errors/entry-point.js diff --git a/packages/rspack/tests/hashCases/real-content-hash/a/file.jpg b/packages/rspack-test-tools/tests/fixtures/errors/file.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash/a/file.jpg rename to packages/rspack-test-tools/tests/fixtures/errors/file.js diff --git a/packages/rspack-test-tools/tests/fixtures/errors/has-syntax-error.js b/packages/rspack-test-tools/tests/fixtures/errors/has-syntax-error.js new file mode 100644 index 00000000000..d425f6b8365 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/has-syntax-error.js @@ -0,0 +1,3 @@ +window.foo = { + bar: true,; +}; diff --git a/packages/rspack-test-tools/tests/fixtures/errors/identity-loader.js b/packages/rspack-test-tools/tests/fixtures/errors/identity-loader.js new file mode 100644 index 00000000000..3ae53b4dca3 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/identity-loader.js @@ -0,0 +1,4 @@ +/** @type {import("@rspack/core").LoaderDefinition} */ +module.exports = function (source) { + return source; +}; diff --git a/packages/rspack-test-tools/tests/fixtures/errors/irregular-error-loader.js b/packages/rspack-test-tools/tests/fixtures/errors/irregular-error-loader.js new file mode 100644 index 00000000000..4950c5990c1 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/irregular-error-loader.js @@ -0,0 +1,11 @@ +/** @type {import("@rspack/core").LoaderDefinition} */ +module.exports = function (source) { + const empty = null; + const emptyError = new Error(); + this.emitWarning(empty); + this.emitWarning(emptyError); + this.emitError(empty); + this.emitError(emptyError); + throw "a string error"; + return source; +}; diff --git a/packages/rspack-test-tools/tests/fixtures/errors/missingFile.js b/packages/rspack-test-tools/tests/fixtures/errors/missingFile.js new file mode 100644 index 00000000000..d0663e2d578 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/missingFile.js @@ -0,0 +1,12 @@ + + +// on line 4 +require("./missing"); + + + + + + +// on line 12 char 10 + require("./dir/missing2"); \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/errors/module-exports-object-loader.js b/packages/rspack-test-tools/tests/fixtures/errors/module-exports-object-loader.js new file mode 100644 index 00000000000..f053ebf7976 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/module-exports-object-loader.js @@ -0,0 +1 @@ +module.exports = {}; diff --git a/packages/rspack-test-tools/tests/fixtures/errors/module-exports-string-loader.js b/packages/rspack-test-tools/tests/fixtures/errors/module-exports-string-loader.js new file mode 100644 index 00000000000..38b08af1d77 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/module-exports-string-loader.js @@ -0,0 +1 @@ +module.exports = ""; diff --git a/packages/rspack-test-tools/tests/fixtures/errors/module-level-throw-error-loader.js b/packages/rspack-test-tools/tests/fixtures/errors/module-level-throw-error-loader.js new file mode 100644 index 00000000000..e0c4ef30082 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/module-level-throw-error-loader.js @@ -0,0 +1 @@ +throw new Error("this is a thrown error from module level"); diff --git a/packages/rspack-test-tools/tests/fixtures/errors/module.parent.require.js b/packages/rspack-test-tools/tests/fixtures/errors/module.parent.require.js new file mode 100644 index 00000000000..f13326a68e1 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/module.parent.require.js @@ -0,0 +1 @@ +module.parent.require('./file'); diff --git a/packages/rspack-test-tools/tests/fixtures/errors/no-errors-deprecate.js b/packages/rspack-test-tools/tests/fixtures/errors/no-errors-deprecate.js new file mode 100644 index 00000000000..8c83c9fd53b --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/no-errors-deprecate.js @@ -0,0 +1 @@ +require('./file'); diff --git a/packages/rspack-test-tools/tests/fixtures/errors/no-return-loader.js b/packages/rspack-test-tools/tests/fixtures/errors/no-return-loader.js new file mode 100644 index 00000000000..fb59fd7e8a4 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/no-return-loader.js @@ -0,0 +1,2 @@ +/** @type {import("@rspack/core").LoaderDefinition} */ +module.exports = function () { }; diff --git a/packages/rspack/tests/hashCases/real-content-hash/a/file.png b/packages/rspack-test-tools/tests/fixtures/errors/not-a-json.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash/a/file.png rename to packages/rspack-test-tools/tests/fixtures/errors/not-a-json.js diff --git a/packages/rspack-test-tools/tests/fixtures/errors/require.extensions.js b/packages/rspack-test-tools/tests/fixtures/errors/require.extensions.js new file mode 100644 index 00000000000..57ce5abebe6 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/require.extensions.js @@ -0,0 +1 @@ +require.extensions[".js"] = function() {}; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/errors/require.main.require.js b/packages/rspack-test-tools/tests/fixtures/errors/require.main.require.js new file mode 100644 index 00000000000..b29827f3ed4 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/require.main.require.js @@ -0,0 +1 @@ +require.main.require('./file'); diff --git a/packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm/answer.js b/packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm/answer.js new file mode 100644 index 00000000000..7814b2b1c19 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm/answer.js @@ -0,0 +1 @@ +export const answer = 42; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm/index.js b/packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm/index.js new file mode 100644 index 00000000000..d6311e3e873 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm/index.js @@ -0,0 +1 @@ +import { answer } from './answer' \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm/package.json b/packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm/package.json new file mode 100644 index 00000000000..aead43de364 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/errors/return-undefined-loader.js b/packages/rspack-test-tools/tests/fixtures/errors/return-undefined-loader.js new file mode 100644 index 00000000000..cc40a4649c9 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/return-undefined-loader.js @@ -0,0 +1 @@ +module.exports = () => {}; diff --git a/packages/rspack-test-tools/tests/fixtures/errors/throw-error-loader.js b/packages/rspack-test-tools/tests/fixtures/errors/throw-error-loader.js new file mode 100644 index 00000000000..18dbe380958 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/throw-error-loader.js @@ -0,0 +1,4 @@ +/** @type {import("@rspack/core").LoaderDefinition} */ +module.exports = function (source) { + throw new Error("this is a thrown error"); +}; diff --git a/packages/rspack-test-tools/tests/fixtures/errors/throw-error-plugin.js b/packages/rspack-test-tools/tests/fixtures/errors/throw-error-plugin.js new file mode 100644 index 00000000000..220dfe835c5 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/errors/throw-error-plugin.js @@ -0,0 +1,7 @@ +module.exports = { + apply(compiler) { + compiler.hooks.compilation.tap("Errors.test-unhandled-throws", compilation => { + throw new Error('foo'); + }); + } +}; diff --git a/packages/rspack-test-tools/tests/fixtures/esm/a.js b/packages/rspack-test-tools/tests/fixtures/esm/a.js new file mode 100644 index 00000000000..6088796d053 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/esm/a.js @@ -0,0 +1,2 @@ +export const a = 1; +export default 1; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/esm/abc.js b/packages/rspack-test-tools/tests/fixtures/esm/abc.js new file mode 100644 index 00000000000..f7c0f2c68e8 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/esm/abc.js @@ -0,0 +1,5 @@ +import { a } from './a'; +import b from './b'; +import * as c from './c'; + +a, b, c \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/esm/b.js b/packages/rspack-test-tools/tests/fixtures/esm/b.js new file mode 100644 index 00000000000..58619af7eee --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/esm/b.js @@ -0,0 +1,2 @@ +export const b = 2; +export default 2; diff --git a/packages/rspack-test-tools/tests/fixtures/esm/c.js b/packages/rspack-test-tools/tests/fixtures/esm/c.js new file mode 100644 index 00000000000..f7e967d95bc --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/esm/c.js @@ -0,0 +1,2 @@ +export const c = 3; +export default 3; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/font.ttf b/packages/rspack-test-tools/tests/fixtures/font.ttf new file mode 100644 index 0000000000000000000000000000000000000000..37af10e09df8f0465dcef081997dbdd0b0d3f323 GIT binary patch literal 2830 zcmb_e`%;@l6#wn+M-oCtkV1(jLl+DT&>)dvYPb{`D3Z|;GNnbdV+%rCrsbwkN^NQ1 z!*_9f2A{-N@ORFBUx-}%OZd*&v*&)!-U0(4i@*Q;0}l12`pPQFEI~NfSO=!omsTIn z_kA_0oJ7(>Vr6w~{AI#0RK>>D-sa)(BzaXJRRRpj=bJ}|$fJ+q8g)9J@4k6Pwk2@h z$^oeN?mXSx?)?jCGylH4XJC#~34 z_cl)t-Iq>hhS|XHZ|*(y^%>>-NPptt@Zjk9vnM2ufJZ8c-a=Yp>@uhPRtQhp)#_I8 zrU|a?k5Nlf{p!nN3!cl((IP(5-Vkpq-L=s9mVgeW$v~zW^7H@C9HTj8@bRe@fn?AKqC}w9aZ-(?ors&VUNaG_P)l5;=1eh z70=Z+tJscDQ&)(tT1h0?uhJ{YT6eGN)M6hZA%ssQDalGfWUE@YP*wF3W7V9~IFpLQ zE)AzA?9U}$2H|uEtT%w%0(u+#z&$6hL%(YXc5*9B2v_^z-6(uC#oI%o50MJh54i{e zNJfD@15IElarZ{w>;tR#m0PLRwYsbzRQ2=dwstj^i%$x zKlYUMclLL4;72>L^s(jr#7ahg!{>cbEhn$A3=SH&=`cPfGk)e8ViFRH!%;Jj^amLKo$24KG=~>$%3PS??G8s{A9x z$5-lzzQLgU!&{u`T-O;NE?Fem*lQ(;#>KG(>Ho9=x^ed^ z4O8I%Z8L2a%&K{0w#;iegI9sQ*Sxn}r<-u=Zcon1RS*qC&*V%sL(7`{X!A9bY literal 0 HcmV?d00001 diff --git a/packages/rspack-test-tools/tests/fixtures/items/item (0).js b/packages/rspack-test-tools/tests/fixtures/items/item (0).js new file mode 100644 index 00000000000..d1a44b64cc8 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/items/item (0).js @@ -0,0 +1 @@ +module.exports = 0; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/items/item (1).js b/packages/rspack-test-tools/tests/fixtures/items/item (1).js new file mode 100644 index 00000000000..c8bfc30c221 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/items/item (1).js @@ -0,0 +1 @@ +module.exports = 1; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/items/item (2).js b/packages/rspack-test-tools/tests/fixtures/items/item (2).js new file mode 100644 index 00000000000..d6fbb1723e4 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/items/item (2).js @@ -0,0 +1 @@ +module.exports = 2; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/items/item (3).js b/packages/rspack-test-tools/tests/fixtures/items/item (3).js new file mode 100644 index 00000000000..678d19e15e0 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/items/item (3).js @@ -0,0 +1 @@ +module.exports = 3; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/items/item (4).js b/packages/rspack-test-tools/tests/fixtures/items/item (4).js new file mode 100644 index 00000000000..32c87826a5d --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/items/item (4).js @@ -0,0 +1 @@ +module.exports = 4; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/items/item (5).js b/packages/rspack-test-tools/tests/fixtures/items/item (5).js new file mode 100644 index 00000000000..717ba9046cc --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/items/item (5).js @@ -0,0 +1 @@ +module.exports = 5; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/items/item (6).js b/packages/rspack-test-tools/tests/fixtures/items/item (6).js new file mode 100644 index 00000000000..c641e570aab --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/items/item (6).js @@ -0,0 +1 @@ +module.exports = 6; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/items/item (7).js b/packages/rspack-test-tools/tests/fixtures/items/item (7).js new file mode 100644 index 00000000000..ca070f53b73 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/items/item (7).js @@ -0,0 +1 @@ +module.exports = 7; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/items/item (8).js b/packages/rspack-test-tools/tests/fixtures/items/item (8).js new file mode 100644 index 00000000000..cb31a1a375a --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/items/item (8).js @@ -0,0 +1 @@ +module.exports = 8; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/items/item (9).js b/packages/rspack-test-tools/tests/fixtures/items/item (9).js new file mode 100644 index 00000000000..f378f58575f --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/items/item (9).js @@ -0,0 +1 @@ +module.exports = 9; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/main1.js b/packages/rspack-test-tools/tests/fixtures/main1.js new file mode 100644 index 00000000000..0f88fa96387 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/main1.js @@ -0,0 +1,10 @@ +var a = require("./a"); +if(x) { + for(var i = 0; i < 100; i++) { + while(true) + require("./b"); + do { + i++; + } while(require("m1/a")()); + } +} \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/main2.js b/packages/rspack-test-tools/tests/fixtures/main2.js new file mode 100644 index 00000000000..dbcaf9b4df2 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/main2.js @@ -0,0 +1,12 @@ +var a = require("./a"); +with(x) { + switch(a) { + case 1: + require("./b"); + default: + require.ensure(["m1/a"], function() { + var a = require("m1/a"), + b = require("m1/b"); + }); + } +} \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/main3.js b/packages/rspack-test-tools/tests/fixtures/main3.js new file mode 100644 index 00000000000..c2a398af0c5 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/main3.js @@ -0,0 +1,4 @@ +var a = require("./a"); +require.ensure([], function(require) { + require("./c.js"); +}); \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/main4.js b/packages/rspack-test-tools/tests/fixtures/main4.js new file mode 100644 index 00000000000..52ef1d2bf87 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/main4.js @@ -0,0 +1,2 @@ +var six = 6; +require("bundle!./items/item (" + six + ")"); \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/missing-file.js b/packages/rspack-test-tools/tests/fixtures/missing-file.js new file mode 100644 index 00000000000..83cca93441b --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/missing-file.js @@ -0,0 +1,5 @@ +module.exports = function b() { + /* eslint-disable node/no-missing-require */ + require("./nonexistentfile"); + return "This is a missing file"; +}; diff --git a/packages/rspack-test-tools/tests/fixtures/nodetest/entry.js b/packages/rspack-test-tools/tests/fixtures/nodetest/entry.js new file mode 100644 index 00000000000..01280dd74fe --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/nodetest/entry.js @@ -0,0 +1,7 @@ +exports.loadChunk = function(id, cb) { + require(["./file" + id], function(result) { + cb(result); + }); +}; +exports.nextTick = process.nextTick; +exports.fs = require("fs"); \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/nodetest/file456.js b/packages/rspack-test-tools/tests/fixtures/nodetest/file456.js new file mode 100644 index 00000000000..69cb5c6cd79 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/nodetest/file456.js @@ -0,0 +1 @@ +module.exports = 123; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/fixtures/nodetest/file567.js b/packages/rspack-test-tools/tests/fixtures/nodetest/file567.js new file mode 100644 index 00000000000..dfb44209fae --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/nodetest/file567.js @@ -0,0 +1,3 @@ +define({ + a: 1 +}); \ No newline at end of file diff --git a/packages/rspack/tests/hashCases/real-content-hash/b/file.jpg b/packages/rspack-test-tools/tests/fixtures/subdir/watched-file.txt similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash/b/file.jpg rename to packages/rspack-test-tools/tests/fixtures/subdir/watched-file.txt diff --git a/packages/rspack-test-tools/tests/fixtures/watch/src/index.js b/packages/rspack-test-tools/tests/fixtures/watch/src/index.js new file mode 100644 index 00000000000..b79b14a3a0e --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/watch/src/index.js @@ -0,0 +1,5 @@ +import "package"; +import "inline-loader!package"; + +import "./local"; +import "inline-loader!./local"; diff --git a/packages/rspack-test-tools/tests/fixtures/watch/src/local.js b/packages/rspack-test-tools/tests/fixtures/watch/src/local.js new file mode 100644 index 00000000000..67d46e2b228 --- /dev/null +++ b/packages/rspack-test-tools/tests/fixtures/watch/src/local.js @@ -0,0 +1,2 @@ +import "package"; +import "inline-loader!package"; diff --git a/packages/rspack/tests/hashCases/real-content-hash/b/file.png b/packages/rspack-test-tools/tests/fixtures/watched-file.txt similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash/b/file.png rename to packages/rspack-test-tools/tests/fixtures/watched-file.txt diff --git a/packages/rspack/tests/hashCases/full-hash/test.config.js b/packages/rspack-test-tools/tests/hashCases/full-hash/test.config.js similarity index 100% rename from packages/rspack/tests/hashCases/full-hash/test.config.js rename to packages/rspack-test-tools/tests/hashCases/full-hash/test.config.js diff --git a/packages/rspack/tests/hashCases/full-hash/version0-copy/foo.js b/packages/rspack-test-tools/tests/hashCases/full-hash/version0-copy/foo.js similarity index 100% rename from packages/rspack/tests/hashCases/full-hash/version0-copy/foo.js rename to packages/rspack-test-tools/tests/hashCases/full-hash/version0-copy/foo.js diff --git a/packages/rspack/tests/hashCases/full-hash/version0-copy/index.js b/packages/rspack-test-tools/tests/hashCases/full-hash/version0-copy/index.js similarity index 100% rename from packages/rspack/tests/hashCases/full-hash/version0-copy/index.js rename to packages/rspack-test-tools/tests/hashCases/full-hash/version0-copy/index.js diff --git a/packages/rspack/tests/hashCases/full-hash/version0/foo.js b/packages/rspack-test-tools/tests/hashCases/full-hash/version0/foo.js similarity index 100% rename from packages/rspack/tests/hashCases/full-hash/version0/foo.js rename to packages/rspack-test-tools/tests/hashCases/full-hash/version0/foo.js diff --git a/packages/rspack/tests/hashCases/full-hash/version0/index.js b/packages/rspack-test-tools/tests/hashCases/full-hash/version0/index.js similarity index 100% rename from packages/rspack/tests/hashCases/full-hash/version0/index.js rename to packages/rspack-test-tools/tests/hashCases/full-hash/version0/index.js diff --git a/packages/rspack/tests/hashCases/full-hash/version1/foo.js b/packages/rspack-test-tools/tests/hashCases/full-hash/version1/foo.js similarity index 100% rename from packages/rspack/tests/hashCases/full-hash/version1/foo.js rename to packages/rspack-test-tools/tests/hashCases/full-hash/version1/foo.js diff --git a/packages/rspack/tests/hashCases/full-hash/version1/index.js b/packages/rspack-test-tools/tests/hashCases/full-hash/version1/index.js similarity index 100% rename from packages/rspack/tests/hashCases/full-hash/version1/index.js rename to packages/rspack-test-tools/tests/hashCases/full-hash/version1/index.js diff --git a/packages/rspack/tests/hashCases/full-hash/webpack.config.js b/packages/rspack-test-tools/tests/hashCases/full-hash/webpack.config.js similarity index 100% rename from packages/rspack/tests/hashCases/full-hash/webpack.config.js rename to packages/rspack-test-tools/tests/hashCases/full-hash/webpack.config.js diff --git a/packages/rspack/tests/hashCases/package-path-change/test.config.js b/packages/rspack-test-tools/tests/hashCases/package-path-change/test.config.js similarity index 100% rename from packages/rspack/tests/hashCases/package-path-change/test.config.js rename to packages/rspack-test-tools/tests/hashCases/package-path-change/test.config.js diff --git a/packages/rspack/tests/hashCases/package-path-change/version0-copy/index.js b/packages/rspack-test-tools/tests/hashCases/package-path-change/version0-copy/index.js similarity index 100% rename from packages/rspack/tests/hashCases/package-path-change/version0-copy/index.js rename to packages/rspack-test-tools/tests/hashCases/package-path-change/version0-copy/index.js diff --git a/packages/rspack/tests/hashCases/package-path-change/version0-copy/node_modules/package/package.json b/packages/rspack-test-tools/tests/hashCases/package-path-change/version0-copy/node_modules/package/package.json similarity index 100% rename from packages/rspack/tests/hashCases/package-path-change/version0-copy/node_modules/package/package.json rename to packages/rspack-test-tools/tests/hashCases/package-path-change/version0-copy/node_modules/package/package.json diff --git a/packages/rspack/tests/hashCases/package-path-change/version0-copy/node_modules/package/package0.js b/packages/rspack-test-tools/tests/hashCases/package-path-change/version0-copy/node_modules/package/package0.js similarity index 100% rename from packages/rspack/tests/hashCases/package-path-change/version0-copy/node_modules/package/package0.js rename to packages/rspack-test-tools/tests/hashCases/package-path-change/version0-copy/node_modules/package/package0.js diff --git a/packages/rspack/tests/hashCases/package-path-change/version0/index.js b/packages/rspack-test-tools/tests/hashCases/package-path-change/version0/index.js similarity index 100% rename from packages/rspack/tests/hashCases/package-path-change/version0/index.js rename to packages/rspack-test-tools/tests/hashCases/package-path-change/version0/index.js diff --git a/packages/rspack/tests/hashCases/package-path-change/version0/node_modules/package/package.json b/packages/rspack-test-tools/tests/hashCases/package-path-change/version0/node_modules/package/package.json similarity index 100% rename from packages/rspack/tests/hashCases/package-path-change/version0/node_modules/package/package.json rename to packages/rspack-test-tools/tests/hashCases/package-path-change/version0/node_modules/package/package.json diff --git a/packages/rspack/tests/hashCases/package-path-change/version0/node_modules/package/package0.js b/packages/rspack-test-tools/tests/hashCases/package-path-change/version0/node_modules/package/package0.js similarity index 100% rename from packages/rspack/tests/hashCases/package-path-change/version0/node_modules/package/package0.js rename to packages/rspack-test-tools/tests/hashCases/package-path-change/version0/node_modules/package/package0.js diff --git a/packages/rspack/tests/hashCases/package-path-change/version1/index.js b/packages/rspack-test-tools/tests/hashCases/package-path-change/version1/index.js similarity index 100% rename from packages/rspack/tests/hashCases/package-path-change/version1/index.js rename to packages/rspack-test-tools/tests/hashCases/package-path-change/version1/index.js diff --git a/packages/rspack/tests/hashCases/package-path-change/version1/node_modules/package/package.json b/packages/rspack-test-tools/tests/hashCases/package-path-change/version1/node_modules/package/package.json similarity index 100% rename from packages/rspack/tests/hashCases/package-path-change/version1/node_modules/package/package.json rename to packages/rspack-test-tools/tests/hashCases/package-path-change/version1/node_modules/package/package.json diff --git a/packages/rspack/tests/hashCases/package-path-change/version1/node_modules/package/package1.js b/packages/rspack-test-tools/tests/hashCases/package-path-change/version1/node_modules/package/package1.js similarity index 100% rename from packages/rspack/tests/hashCases/package-path-change/version1/node_modules/package/package1.js rename to packages/rspack-test-tools/tests/hashCases/package-path-change/version1/node_modules/package/package1.js diff --git a/packages/rspack/tests/hashCases/package-path-change/webpack.config.js b/packages/rspack-test-tools/tests/hashCases/package-path-change/webpack.config.js similarity index 100% rename from packages/rspack/tests/hashCases/package-path-change/webpack.config.js rename to packages/rspack-test-tools/tests/hashCases/package-path-change/webpack.config.js diff --git a/packages/rspack/tests/hashCases/provided-dependency-order/index.js b/packages/rspack-test-tools/tests/hashCases/provided-dependency-order/index.js similarity index 100% rename from packages/rspack/tests/hashCases/provided-dependency-order/index.js rename to packages/rspack-test-tools/tests/hashCases/provided-dependency-order/index.js diff --git a/packages/rspack/tests/hashCases/provided-dependency-order/test.config.js b/packages/rspack-test-tools/tests/hashCases/provided-dependency-order/test.config.js similarity index 100% rename from packages/rspack/tests/hashCases/provided-dependency-order/test.config.js rename to packages/rspack-test-tools/tests/hashCases/provided-dependency-order/test.config.js diff --git a/packages/rspack/tests/hashCases/provided-dependency-order/webpack.config.js b/packages/rspack-test-tools/tests/hashCases/provided-dependency-order/webpack.config.js similarity index 100% rename from packages/rspack/tests/hashCases/provided-dependency-order/webpack.config.js rename to packages/rspack-test-tools/tests/hashCases/provided-dependency-order/webpack.config.js diff --git a/packages/rspack-test-tools/tests/hashCases/real-content-hash-consistent/src/file.png b/packages/rspack-test-tools/tests/hashCases/real-content-hash-consistent/src/file.png new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack/tests/hashCases/real-content-hash-consistent/src/index.js b/packages/rspack-test-tools/tests/hashCases/real-content-hash-consistent/src/index.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash-consistent/src/index.js rename to packages/rspack-test-tools/tests/hashCases/real-content-hash-consistent/src/index.js diff --git a/packages/rspack/tests/hashCases/real-content-hash-consistent/test.config.js b/packages/rspack-test-tools/tests/hashCases/real-content-hash-consistent/test.config.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash-consistent/test.config.js rename to packages/rspack-test-tools/tests/hashCases/real-content-hash-consistent/test.config.js diff --git a/packages/rspack/tests/hashCases/real-content-hash-consistent/webpack.config.js b/packages/rspack-test-tools/tests/hashCases/real-content-hash-consistent/webpack.config.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash-consistent/webpack.config.js rename to packages/rspack-test-tools/tests/hashCases/real-content-hash-consistent/webpack.config.js diff --git a/packages/rspack/tests/hashCases/real-content-hash/a/a.js b/packages/rspack-test-tools/tests/hashCases/real-content-hash/a/a.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash/a/a.js rename to packages/rspack-test-tools/tests/hashCases/real-content-hash/a/a.js diff --git a/packages/rspack/tests/hashCases/real-content-hash/a/b.js b/packages/rspack-test-tools/tests/hashCases/real-content-hash/a/b.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash/a/b.js rename to packages/rspack-test-tools/tests/hashCases/real-content-hash/a/b.js diff --git a/packages/rspack-test-tools/tests/hashCases/real-content-hash/a/file.jpg b/packages/rspack-test-tools/tests/hashCases/real-content-hash/a/file.jpg new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack-test-tools/tests/hashCases/real-content-hash/a/file.png b/packages/rspack-test-tools/tests/hashCases/real-content-hash/a/file.png new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack/tests/hashCases/real-content-hash/a/index.js b/packages/rspack-test-tools/tests/hashCases/real-content-hash/a/index.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash/a/index.js rename to packages/rspack-test-tools/tests/hashCases/real-content-hash/a/index.js diff --git a/packages/rspack/tests/hashCases/real-content-hash/a/lazy.js b/packages/rspack-test-tools/tests/hashCases/real-content-hash/a/lazy.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash/a/lazy.js rename to packages/rspack-test-tools/tests/hashCases/real-content-hash/a/lazy.js diff --git a/packages/rspack/tests/hashCases/real-content-hash/a/module.js b/packages/rspack-test-tools/tests/hashCases/real-content-hash/a/module.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash/a/module.js rename to packages/rspack-test-tools/tests/hashCases/real-content-hash/a/module.js diff --git a/packages/rspack/tests/hashCases/real-content-hash/b/a.js b/packages/rspack-test-tools/tests/hashCases/real-content-hash/b/a.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash/b/a.js rename to packages/rspack-test-tools/tests/hashCases/real-content-hash/b/a.js diff --git a/packages/rspack/tests/hashCases/real-content-hash/b/b.js b/packages/rspack-test-tools/tests/hashCases/real-content-hash/b/b.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash/b/b.js rename to packages/rspack-test-tools/tests/hashCases/real-content-hash/b/b.js diff --git a/packages/rspack-test-tools/tests/hashCases/real-content-hash/b/file.jpg b/packages/rspack-test-tools/tests/hashCases/real-content-hash/b/file.jpg new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack-test-tools/tests/hashCases/real-content-hash/b/file.png b/packages/rspack-test-tools/tests/hashCases/real-content-hash/b/file.png new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack/tests/hashCases/real-content-hash/b/index.js b/packages/rspack-test-tools/tests/hashCases/real-content-hash/b/index.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash/b/index.js rename to packages/rspack-test-tools/tests/hashCases/real-content-hash/b/index.js diff --git a/packages/rspack/tests/hashCases/real-content-hash/b/lazy.js b/packages/rspack-test-tools/tests/hashCases/real-content-hash/b/lazy.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash/b/lazy.js rename to packages/rspack-test-tools/tests/hashCases/real-content-hash/b/lazy.js diff --git a/packages/rspack/tests/hashCases/real-content-hash/b/module.js b/packages/rspack-test-tools/tests/hashCases/real-content-hash/b/module.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash/b/module.js rename to packages/rspack-test-tools/tests/hashCases/real-content-hash/b/module.js diff --git a/packages/rspack/tests/hashCases/real-content-hash/test.config.js b/packages/rspack-test-tools/tests/hashCases/real-content-hash/test.config.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash/test.config.js rename to packages/rspack-test-tools/tests/hashCases/real-content-hash/test.config.js diff --git a/packages/rspack/tests/hashCases/real-content-hash/webpack.config.js b/packages/rspack-test-tools/tests/hashCases/real-content-hash/webpack.config.js similarity index 100% rename from packages/rspack/tests/hashCases/real-content-hash/webpack.config.js rename to packages/rspack-test-tools/tests/hashCases/real-content-hash/webpack.config.js diff --git a/packages/rspack-test-tools/tests/package.json b/packages/rspack-test-tools/tests/package.json new file mode 100644 index 00000000000..e62451ab4ca --- /dev/null +++ b/packages/rspack-test-tools/tests/package.json @@ -0,0 +1,8 @@ +{ + "name": "rspack-core-tests", + "version": "1.0.0", + "description": "this is generated to avoid lookup @rspack/core's package.json and affected by the exports field ", + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/packages/rspack-test-tools/tests/statsAPICases/basic.js b/packages/rspack-test-tools/tests/statsAPICases/basic.js index 1a41cd48ed0..ed43f3a553c 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/basic.js +++ b/packages/rspack-test-tools/tests/statsAPICases/basic.js @@ -18,20 +18,22 @@ module.exports = { expect(typeof stats?.hash).toBe("string"); expect(stats?.toJson(statsOptions)).toMatchSnapshot(); expect(stats?.toString(statsOptions)).toMatchInlineSnapshot(` - "PublicPath: auto - asset main.js 211 bytes {909} [emitted] (name: main) - Entrypoint main 211 bytes = main.js - chunk {909} main.js (main) [entry] - ./fixtures/a.js [585] {909} - [no exports] - [used exports unknown] - entry ./fixtures/a - ./fixtures/a.js [585] {909} - [no exports] - [used exports unknown] - entry ./fixtures/a - - Rspack compiled successfully (57e46af248a1c1fe076f)" - `); + "PublicPath: auto + asset main.js 211 bytes {909} [emitted] (name: main) + Entrypoint main 211 bytes = main.js + chunk {909} main.js (main) [entry] + ./fixtures/a.js [585] {909} + [no exports] + [no exports used] + Statement with side_effects in source code at ./fixtures/a.js:1:0-3:2 + entry ./fixtures/a + ./fixtures/a.js [585] {909} + [no exports] + [no exports used] + Statement with side_effects in source code at ./fixtures/a.js:1:0-3:2 + entry ./fixtures/a + + Rspack compiled successfully (57e46af248a1c1fe076f)" + `); } }; diff --git a/packages/rspack-test-tools/tests/statsAPICases/child-compiler.js b/packages/rspack-test-tools/tests/statsAPICases/child-compiler.js index b7096e0fe76..7ae43bc1802 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/child-compiler.js +++ b/packages/rspack-test-tools/tests/statsAPICases/child-compiler.js @@ -54,7 +54,7 @@ module.exports = { "hotModuleReplacement": false, }, "name": "TestChild.js", - "size": 738, + "size": 726, "type": "asset", }, Object { @@ -89,7 +89,7 @@ module.exports = { "hotModuleReplacement": false, }, "name": "TestChild.js", - "size": 738, + "size": 726, "type": "asset", }, ], diff --git a/packages/rspack-test-tools/tests/statsAPICases/to-string.js b/packages/rspack-test-tools/tests/statsAPICases/to-string.js index 0f62b4ab3e6..4b53901ad6d 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/to-string.js +++ b/packages/rspack-test-tools/tests/statsAPICases/to-string.js @@ -10,8 +10,8 @@ module.exports = { expect(stats?.toString({ timings: false, version: false })) .toMatchInlineSnapshot(` "PublicPath: auto - asset main.js 738 bytes [emitted] (name: main) - Entrypoint main 738 bytes = main.js + asset main.js 726 bytes [emitted] (name: main) + Entrypoint main 726 bytes = main.js ./fixtures/a.js ./fixtures/b.js ./fixtures/c.js @@ -30,7 +30,7 @@ module.exports = { help: You may need an appropriate loader to handle this file type. - Rspack compiled with 1 error (8137ab425c2721784808)" + Rspack compiled with 1 error (dce75c423b760e8a8c35)" `); } }; diff --git a/packages/rspack-test-tools/tests/statsAPICases/verbose-time.js b/packages/rspack-test-tools/tests/statsAPICases/verbose-time.js index 42ab93fae95..cc855af2a4a 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/verbose-time.js +++ b/packages/rspack-test-tools/tests/statsAPICases/verbose-time.js @@ -13,13 +13,8 @@ module.exports = { .replace(/\d+ ms/g, "X ms") ).toMatchInlineSnapshot(` "LOG from rspack.Compilation - module add task: X ms - module process dependencies task: X ms - module factorize task: X ms - module build task: X ms finish modules: X ms optimize dependencies: X ms - optimize dependencies: X ms create chunks: X ms optimize: X ms module ids: X ms @@ -47,7 +42,6 @@ module.exports = { finish compilation: X ms seal compilation: X ms emitAssets: X ms - done hook: X ms LOG from rspack.EnsureChunkConditionsPlugin ensure chunk conditions: X ms diff --git a/packages/rspack/tests/watchCases/compiler/multiply-compiler/0/entry1.js b/packages/rspack-test-tools/tests/watchCases/compiler/multiply-compiler/0/entry1.js similarity index 100% rename from packages/rspack/tests/watchCases/compiler/multiply-compiler/0/entry1.js rename to packages/rspack-test-tools/tests/watchCases/compiler/multiply-compiler/0/entry1.js diff --git a/packages/rspack/tests/watchCases/compiler/multiply-compiler/0/entry2.js b/packages/rspack-test-tools/tests/watchCases/compiler/multiply-compiler/0/entry2.js similarity index 100% rename from packages/rspack/tests/watchCases/compiler/multiply-compiler/0/entry2.js rename to packages/rspack-test-tools/tests/watchCases/compiler/multiply-compiler/0/entry2.js diff --git a/packages/rspack/tests/watchCases/compiler/multiply-compiler/0/file.js b/packages/rspack-test-tools/tests/watchCases/compiler/multiply-compiler/0/file.js similarity index 100% rename from packages/rspack/tests/watchCases/compiler/multiply-compiler/0/file.js rename to packages/rspack-test-tools/tests/watchCases/compiler/multiply-compiler/0/file.js diff --git a/packages/rspack/tests/watchCases/compiler/multiply-compiler/1/file.js b/packages/rspack-test-tools/tests/watchCases/compiler/multiply-compiler/1/file.js similarity index 100% rename from packages/rspack/tests/watchCases/compiler/multiply-compiler/1/file.js rename to packages/rspack-test-tools/tests/watchCases/compiler/multiply-compiler/1/file.js diff --git a/packages/rspack/tests/watchCases/compiler/multiply-compiler/webpack.config.js b/packages/rspack-test-tools/tests/watchCases/compiler/multiply-compiler/webpack.config.js similarity index 100% rename from packages/rspack/tests/watchCases/compiler/multiply-compiler/webpack.config.js rename to packages/rspack-test-tools/tests/watchCases/compiler/multiply-compiler/webpack.config.js diff --git a/packages/rspack/tests/watchCases/context/out-of-context/0/bar.less b/packages/rspack-test-tools/tests/watchCases/context/out-of-context/0/bar.less similarity index 100% rename from packages/rspack/tests/watchCases/context/out-of-context/0/bar.less rename to packages/rspack-test-tools/tests/watchCases/context/out-of-context/0/bar.less diff --git a/packages/rspack/tests/watchCases/context/out-of-context/0/src/foo.less b/packages/rspack-test-tools/tests/watchCases/context/out-of-context/0/src/foo.less similarity index 100% rename from packages/rspack/tests/watchCases/context/out-of-context/0/src/foo.less rename to packages/rspack-test-tools/tests/watchCases/context/out-of-context/0/src/foo.less diff --git a/packages/rspack/tests/watchCases/context/out-of-context/0/src/index.js b/packages/rspack-test-tools/tests/watchCases/context/out-of-context/0/src/index.js similarity index 100% rename from packages/rspack/tests/watchCases/context/out-of-context/0/src/index.js rename to packages/rspack-test-tools/tests/watchCases/context/out-of-context/0/src/index.js diff --git a/packages/rspack/tests/watchCases/context/out-of-context/1/bar.less b/packages/rspack-test-tools/tests/watchCases/context/out-of-context/1/bar.less similarity index 100% rename from packages/rspack/tests/watchCases/context/out-of-context/1/bar.less rename to packages/rspack-test-tools/tests/watchCases/context/out-of-context/1/bar.less diff --git a/packages/rspack/tests/watchCases/context/out-of-context/2/bar.less b/packages/rspack-test-tools/tests/watchCases/context/out-of-context/2/bar.less similarity index 100% rename from packages/rspack/tests/watchCases/context/out-of-context/2/bar.less rename to packages/rspack-test-tools/tests/watchCases/context/out-of-context/2/bar.less diff --git a/packages/rspack/tests/watchCases/context/out-of-context/webpack.config.js b/packages/rspack-test-tools/tests/watchCases/context/out-of-context/webpack.config.js similarity index 100% rename from packages/rspack/tests/watchCases/context/out-of-context/webpack.config.js rename to packages/rspack-test-tools/tests/watchCases/context/out-of-context/webpack.config.js diff --git a/packages/rspack/tests/HashTestCases.test.js b/packages/rspack/tests/HashTestCases.test.js deleted file mode 100644 index 7b592fdba16..00000000000 --- a/packages/rspack/tests/HashTestCases.test.js +++ /dev/null @@ -1,60 +0,0 @@ -const path = require("path"); -const fs = require("fs"); -const util = require("util"); -const { rspack } = require("../dist"); -const serializer = require("jest-serializer-path"); - -expect.addSnapshotSerializer(serializer); - -const base = path.resolve(__dirname, "hashCases"); -const tests = fs.readdirSync(base).filter(testName => { - return ( - !testName.startsWith(".") && - (fs.existsSync(path.resolve(base, testName, "index.js")) || - fs.existsSync(path.resolve(base, testName, "webpack.config.js"))) - ); -}); - -describe("HashTestCases", () => { - tests.forEach(testName => { - it("should print correct hash for " + testName, async () => { - const testPath = path.resolve(base, testName); - const configPath = path.resolve(testPath, "webpack.config.js"); - const testConfigPath = path.resolve(testPath, "test.config.js"); - let config; - if (fs.existsSync(configPath)) { - config = require(configPath); - } else { - throw new Error("HashTestCases must have a webpack.config.js"); - } - const isMultiCompiler = Array.isArray(config); - if (!isMultiCompiler && typeof config === "object") { - config.context ??= testPath; - config.entry ??= "./index"; - config.output ??= {}; - config.output.path ??= path.resolve(testPath, "dist"); - } - let testConfig; - if (fs.existsSync(testConfigPath)) { - testConfig = require(testConfigPath); - } - const stats = await util.promisify(rspack)(config); - if (!stats) return expect(false); - const statsJson = stats.toJson({ assets: true }); - // case ends with error should generate errors - if (/error$/.test(testName)) { - expect(statsJson.errors.length > 0); - } else { - expect(statsJson.errors.length === 0); - } - - if (testConfig && testConfig.validate) { - testConfig.validate(stats); - } else { - throw new Error( - "HashTestCases should have test.config.js and a validate method" - ); - } - }); - }); -}); diff --git a/packages/rspack/tests/WatchTestCases.longtest.js b/packages/rspack/tests/WatchTestCases.longtest.js deleted file mode 100644 index 14de99b424e..00000000000 --- a/packages/rspack/tests/WatchTestCases.longtest.js +++ /dev/null @@ -1,5 +0,0 @@ -const { describeCases } = require("./WatchTestCases.template"); - -describeCases({ - name: "WatchTestCases" -}); diff --git a/packages/rspack/tests/WatchTestCases.template.js b/packages/rspack/tests/WatchTestCases.template.js deleted file mode 100644 index 7f6b8b1919e..00000000000 --- a/packages/rspack/tests/WatchTestCases.template.js +++ /dev/null @@ -1,442 +0,0 @@ -"use strict"; - -require("./helpers/warmup-webpack"); - -const path = require("path"); -const fs = require("graceful-fs"); -const vm = require("vm"); -const rimraf = require("rimraf"); -const checkArrayExpectation = require("./checkArrayExpectation"); -const createLazyTestEnv = require("./helpers/createLazyTestEnv"); -const { remove } = require("./helpers/remove"); -const prepareOptions = require("./helpers/prepareOptions"); -const deprecationTracking = require("./helpers/deprecationTracking"); -const FakeDocument = require("./helpers/FakeDocument"); - -function copyDiff(src, dest, initial) { - fs.mkdirSync(dest, { recursive: true }); - const files = fs.readdirSync(src); - files.forEach(filename => { - const srcFile = path.join(src, filename); - const destFile = path.join(dest, filename); - const directory = fs.statSync(srcFile).isDirectory(); - if (directory) { - copyDiff(srcFile, destFile, initial); - } else { - var content = fs.readFileSync(srcFile); - if (/^DELETE\s*$/.test(content.toString("utf-8"))) { - fs.unlinkSync(destFile); - } else if (/^DELETE_DIRECTORY\s*$/.test(content.toString("utf-8"))) { - rimraf.sync(destFile); - } else { - fs.writeFileSync(destFile, content); - if (initial) { - const longTimeAgo = Date.now() - 1000 * 60 * 60 * 24; - fs.utimesSync( - destFile, - Date.now() - longTimeAgo, - Date.now() - longTimeAgo - ); - } - } - } - }); -} - -const describeCases = config => { - describe(config.name, () => { - if (process.env.NO_WATCH_TESTS) { - it.skip("long running tests excluded", () => {}); - return; - } - - const casesPath = path.join(__dirname, "watchCases"); - let categories = fs.readdirSync(casesPath); - - categories = categories.map(cat => { - return { - name: cat, - tests: fs - .readdirSync(path.join(casesPath, cat)) - .filter(folder => folder.indexOf("_") < 0) - .filter(testName => { - const testDirectory = path.join(casesPath, cat, testName); - const filterPath = path.join(testDirectory, "test.filter.js"); - if (fs.existsSync(filterPath) && !require(filterPath)(config)) { - describe.skip(testName, () => it("filtered", () => {})); - return false; - } - return true; - }) - .sort() - }; - }); - beforeAll(() => { - let dest = path.join(__dirname, "js"); - fs.mkdirSync(dest, { recursive: true }); - dest = path.join(__dirname, "js", config.name + "-src"); - fs.mkdirSync(dest, { recursive: true }); - }); - categories.forEach(category => { - beforeAll(() => { - const dest = path.join( - __dirname, - "js", - config.name + "-src", - category.name - ); - fs.mkdirSync(dest, { recursive: true }); - }); - describe(category.name, () => { - category.tests.forEach(testName => { - describe(testName, () => { - const tempDirectory = path.join( - __dirname, - "js", - config.name + "-src", - category.name, - testName - ); - const testDirectory = path.join(casesPath, category.name, testName); - const runs = fs - .readdirSync(testDirectory) - .sort() - .filter(name => { - return fs - .statSync(path.join(testDirectory, name)) - .isDirectory(); - }) - .map(name => ({ name })); - - beforeAll(done => { - rimraf(tempDirectory, done); - }); - - it( - testName + " should compile", - done => { - const outputDirectory = path.join( - __dirname, - "js", - config.name, - category.name, - testName - ); - - rimraf.sync(outputDirectory); - - let options = {}; - const configPath = path.join( - testDirectory, - "webpack.config.js" - ); - if (fs.existsSync(configPath)) { - options = prepareOptions(require(configPath), { - testPath: outputDirectory, - srcPath: tempDirectory - }); - } - const applyConfig = (options, idx) => { - if (!options.mode) options.mode = "development"; - if (!options.context) options.context = tempDirectory; - if (!options.entry) options.entry = "./index.js"; - if (!options.target) options.target = "async-node"; - if (!options.output) options.output = {}; - if (!options.output.path) - options.output.path = outputDirectory; - // CHANGE: The pathinfo is currently not supported in rspack - // if (typeof options.output.pathinfo === "undefined") - // options.output.pathinfo = true; - if (!options.output.filename) - options.output.filename = "bundle.js"; - if (options.cache && options.cache.type === "filesystem") { - const cacheDirectory = path.join(tempDirectory, ".cache"); - options.cache.cacheDirectory = cacheDirectory; - options.cache.name = `config-${idx}`; - } - if (config.experiments) { - if (!options.experiments) options.experiments = {}; - for (const key of Object.keys(config.experiments)) { - if (options.experiments[key] === undefined) - options.experiments[key] = config.experiments[key]; - } - } - if (config.optimization) { - if (!options.optimization) options.optimization = {}; - for (const key of Object.keys(config.optimization)) { - if (options.optimization[key] === undefined) - options.optimization[key] = config.optimization[key]; - } - } - }; - if (Array.isArray(options)) { - options.forEach(applyConfig); - } else { - applyConfig(options, 0); - } - - const state = {}; - let runIdx = 0; - let waitMode = false; - let run = runs[runIdx]; - let triggeringFilename; - let lastHash = ""; - const currentWatchStepModule = require("./helpers/currentWatchStep"); - let compilationFinished = done; - currentWatchStepModule.step = run.name; - copyDiff( - path.join(testDirectory, run.name), - tempDirectory, - true - ); - - setTimeout(() => { - const deprecationTracker = deprecationTracking.start(); - const webpack = require(".."); - const compiler = webpack(options); - compiler.hooks.invalid.tap( - "WatchTestCasesTest", - (filename, mtime) => { - triggeringFilename = filename; - } - ); - compiler.watch( - { - aggregateTimeout: 1000 - }, - (err, stats) => { - if (err) return compilationFinished(err); - if (!stats) { - return compilationFinished( - new Error("No stats reported from Compiler") - ); - } - if (stats.hash === lastHash) return; - lastHash = stats.hash; - if (run.done && lastHash !== stats.hash) { - return compilationFinished( - new Error( - "Compilation changed but no change was issued " + - lastHash + - " != " + - stats.hash + - " (run " + - runIdx + - ")\n" + - "Triggering change: " + - triggeringFilename - ) - ); - } - if (waitMode) return; - run.done = true; - run.stats = stats; - if (err) return compilationFinished(err); - const statOptions = { - preset: "verbose", - cached: true, - cachedAssets: true, - cachedModules: true, - colors: false - }; - fs.mkdirSync(outputDirectory, { recursive: true }); - fs.writeFileSync( - path.join( - outputDirectory, - `stats.${runs[runIdx] && runs[runIdx].name}.txt` - ), - stats.toString(statOptions), - "utf-8" - ); - const jsonStats = stats.toJson({ - errorDetails: true - }); - if ( - checkArrayExpectation( - path.join(testDirectory, run.name), - jsonStats, - "error", - "Error", - compilationFinished - ) - ) - return; - if ( - checkArrayExpectation( - path.join(testDirectory, run.name), - jsonStats, - "warning", - "Warning", - compilationFinished - ) - ) - return; - - const globalContext = { - console: console, - expect: expect, - setTimeout, - clearTimeout, - document: new FakeDocument() - }; - - function _require(currentDirectory, module) { - if (Array.isArray(module) || /^\.\.?\//.test(module)) { - let fn; - let content; - let p; - if (Array.isArray(module)) { - p = path.join(currentDirectory, module[0]); - content = module - .map(arg => { - p = path.join(currentDirectory, arg); - return fs.readFileSync(p, "utf-8"); - }) - .join("\n"); - } else { - p = path.join(currentDirectory, module); - content = fs.readFileSync(p, "utf-8"); - } - if ( - options.target === "web" || - options.target === "webworker" - ) { - fn = vm.runInNewContext( - "(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE, expect, window, self) {" + - 'function nsObj(m) { Object.defineProperty(m, Symbol.toStringTag, { value: "Module" }); return m; }' + - content + - "\n})", - globalContext, - p - ); - } else { - fn = vm.runInThisContext( - "(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE, expect) {" + - "global.expect = expect;" + - 'function nsObj(m) { Object.defineProperty(m, Symbol.toStringTag, { value: "Module" }); return m; }' + - content + - "\n})", - p - ); - } - const m = { - exports: {} - }; - fn.call( - m.exports, - _require.bind(null, path.dirname(p)), - m, - m.exports, - path.dirname(p), - p, - run.it, - run.name, - jsonStats, - state, - expect, - globalContext, - globalContext - ); - return module.exports; - } else if ( - testConfig.modules && - module in testConfig.modules - ) { - return testConfig.modules[module]; - } else return jest.requireActual(module); - } - - let testConfig = {}; - try { - // try to load a test file - testConfig = require(path.join( - testDirectory, - "test.config.js" - )); - } catch (e) { - // empty - } - - if (testConfig.noTests) - return process.nextTick(compilationFinished); - _require( - outputDirectory, - testConfig.bundlePath || "./bundle.js" - ); - - if (run.getNumberOfTests() < 1) - return compilationFinished( - new Error("No tests exported by test case") - ); - - run.it( - "should compile the next step", - done => { - runIdx++; - if (runIdx < runs.length) { - run = runs[runIdx]; - waitMode = true; - setTimeout(() => { - waitMode = false; - compilationFinished = done; - currentWatchStepModule.step = run.name; - copyDiff( - path.join(testDirectory, run.name), - tempDirectory, - false - ); - }, 1500); - } else { - const deprecations = deprecationTracker(); - if ( - checkArrayExpectation( - testDirectory, - { deprecations }, - "deprecation", - "Deprecation", - done - ) - ) { - compiler.close(() => {}); - return; - } - compiler.close(done); - } - }, - 45000 - ); - - compilationFinished(); - } - ); - }, 300); - }, - 45000 - ); - - for (const run of runs) { - const { it: _it, getNumberOfTests } = createLazyTestEnv( - 10000, - run.name - ); - run.it = _it; - run.getNumberOfTests = getNumberOfTests; - it(`${run.name} should allow to read stats`, done => { - if (run.stats) { - run.stats.toString({ all: true }); - run.stats = undefined; - } - done(); - }); - } - - afterAll(() => { - remove(tempDirectory); - }); - }); - }); - }); - }); - }); -}; -exports.describeCases = describeCases;