Skip to content

Commit

Permalink
chore: migrate hot test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
LingyuCoder committed Apr 24, 2024
1 parent 3abf966 commit 9cd8629
Show file tree
Hide file tree
Showing 467 changed files with 56 additions and 450 deletions.
5 changes: 4 additions & 1 deletion packages/rspack-test-tools/jest.config.compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module.exports = {
"<rootDir>/tests/Stats.unittest.js",
"<rootDir>/tests/TreeShaking.test.js",
"<rootDir>/tests/ConfigTestCases.basictest.js",
"<rootDir>/tests/TestCasesNormal.basictest.js"
"<rootDir>/tests/TestCasesNormal.basictest.js",
"<rootDir>/tests/HotTestCasesWeb.test.js",
"<rootDir>/tests/HotTestCasesNode.test.js",
"<rootDir>/tests/HotTestCasesWebWorker.test.js"
]
};
3 changes: 3 additions & 0 deletions packages/rspack-test-tools/jest.config.legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module.exports = {
"HotTestStepWeb.test.js",
"ConfigTestCases.basictest.js",
"TestCasesNormal.basictest.js",
"HotTestCasesWeb.test.js",
"HotTestCasesWebWorker.test.js",
"HotTestCasesNode.test.js",
".difftest.js"
]
};
15 changes: 15 additions & 0 deletions packages/rspack-test-tools/src/helper/legacy/supportsWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @ts-nocheck
const nodeVersion = process.versions.node.split(".").map(Number);

module.exports = function supportsWorker() {
// Verify that in the current node version new Worker() accepts URL as the first parameter:
// https://nodejs.org/api/worker_threads.html#worker_threads_new_worker_filename_options
if (nodeVersion[0] >= 14) {
return true;
} else if (nodeVersion[0] === 13 && nodeVersion[1] >= 12) {
return true;
} else if (nodeVersion[0] === 12 && nodeVersion[1] >= 17) {
return true;
}
return false;
};
24 changes: 24 additions & 0 deletions packages/rspack-test-tools/src/helper/util/expectWarningFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @ts-nocheck
module.exports = () => {
let warnings = [];
let oldWarn;

beforeEach(done => {
oldWarn = console.warn;
console.warn = m => warnings.push(m);
done();
});

afterEach(done => {
expectWarning();
console.warn = oldWarn;
done();
});

const expectWarning = (...regexp) => {
expect(warnings).toEqual(regexp.map(r => expect.stringMatching(r)));
warnings.length = 0;
};

return expectWarning;
};
4 changes: 2 additions & 2 deletions packages/rspack-test-tools/tests/HotTestCasesNode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const path = require("path");
const { describeByWalk, createHotCase } = require("..");

const NAME = "HotTestCases";
const caseDir = path.resolve(__dirname, "../../rspack/tests/hotCases");
const distDir = path.resolve(__dirname, `../../rspack/tests/js/hot-cases-node`);
const caseDir = path.resolve(__dirname, "./hotCases");
const distDir = path.resolve(__dirname, `./js/hot-cases-node`);

describeByWalk(NAME, caseDir, distDir, (name, src, dist) => {
createHotCase(name, src, dist, "async-node");
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-test-tools/tests/HotTestCasesWeb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const path = require("path");
const { describeByWalk, createHotCase } = require("..");

const NAME = "HotTestCases";
const caseDir = path.resolve(__dirname, "../../rspack/tests/hotCases");
const distDir = path.resolve(__dirname, `../../rspack/tests/js/hot-cases-web`);
const caseDir = path.resolve(__dirname, "./hotCases");
const distDir = path.resolve(__dirname, `./js/hot-cases-web`);

describeByWalk(NAME, caseDir, distDir, (name, src, dist) => {
createHotCase(name, src, dist, "web");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ const path = require("path");
const { describeByWalk, createHotCase } = require("..");

const NAME = "HotTestCases";
const caseDir = path.resolve(__dirname, "../../rspack/tests/hotCases");
const distDir = path.resolve(
__dirname,
`../../rspack/tests/js/hot-cases-worker`
);
const caseDir = path.resolve(__dirname, "./hotCases");
const distDir = path.resolve(__dirname, `./js/hot-cases-worker`);

describeByWalk(NAME, caseDir, distDir, (name, src, dist) => {
createHotCase(name, src, dist, "webworker");
Expand Down
7 changes: 2 additions & 5 deletions packages/rspack-test-tools/tests/HotTestStepWeb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ const path = require("path");
const { describeByWalk, createHotStepCase } = require("../dist");

const NAME = "HotStepTestCasesNode";
const caseDir = path.resolve(__dirname, "../../rspack/tests/hotCases");
const distDir = path.resolve(
__dirname,
`../../rspack/tests/js/hot-step-cases-web`
);
const caseDir = path.resolve(__dirname, "./hotCases");
const distDir = path.resolve(__dirname, `./js/hot-step-cases-web`);

process.env["RSPACK_HOT_TEST"] = "true";

Expand Down
Loading

0 comments on commit 9cd8629

Please sign in to comment.