Skip to content

Commit

Permalink
chore: migrate config test cases (#6335)
Browse files Browse the repository at this point in the history
  • Loading branch information
LingyuCoder authored Apr 23, 2024
1 parent 432ce5e commit 476961a
Show file tree
Hide file tree
Showing 1,998 changed files with 841 additions and 870 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ node_modules/
!webpack-test/*/**/node_modules
!packages/rspack-cli/tests/**/node_modules
!packages/rspack/tests/**/node_modules
!packages/rspack/tests/configCases/less/resolve/node_modules
!packages/rspack-test-tools/tests/**/node_modules
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
Expand Down
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ 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/tests/cases/parsing/issue-5120-binding/fail.js
packages/rspack/tests/diagnostics/module-parse-failed/lexically_name_error/index.js
Expand Down
3 changes: 2 additions & 1 deletion packages/rspack-test-tools/jest.config.compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
"<rootDir>/tests/Builtin.test.js",
"<rootDir>/tests/Defaults.unittest.js",
"<rootDir>/tests/Stats.unittest.js",
"<rootDir>/tests/TreeShaking.test.js"
"<rootDir>/tests/TreeShaking.test.js",
"<rootDir>/tests/ConfigTestCases.basictest.js"
]
};
1 change: 1 addition & 0 deletions packages/rspack-test-tools/jest.config.legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
"TreeShaking.test.js",
"Builtin.test.js",
"HotTestStepWeb.test.js",
"ConfigTestCases.basictest.js",
".difftest.js"
]
};
1 change: 1 addition & 0 deletions packages/rspack-test-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@arco-design/web-react": "^2.56.1",
"@monaco-editor/react": "^4.6.0",
"@rspack/cli": "workspace:*",
"@rspack/plugin-minify": "workspace:*",
"@swc/jest": "^0.2.29",
"@types/prettier": "^2.7.2",
"@types/react": "^18.2.48",
Expand Down
122 changes: 122 additions & 0 deletions packages/rspack-test-tools/src/helper/legacy/fakeSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// @ts-nocheck
const System = {
register: (name, deps, fn) => {
if (!System.registry) {
throw new Error("System is no initialized");
}
if (typeof name !== "string") {
fn = deps;
deps = name;
name = System._nextName;
}
if (!Array.isArray(deps)) {
fn = deps;
deps = [];
}
const dynamicExport = result => {
if (System.registry[name] !== entry) {
throw new Error(`Module ${name} calls dynamicExport too late`);
}
entry.exports = result;
for (const mod of Object.keys(System.registry)) {
const m = System.registry[mod];
if (!m.deps) continue;
for (let i = 0; i < m.deps.length; i++) {
const dep = m.deps[i];
if (dep !== name) continue;
const setters = m.mod.setters[i];
setters(result);
}
}
};
const systemContext = {
meta: {
url: `/${name}.js`
},
import() {
return Promise.resolve();
}
};
if (name in System.registry) {
throw new Error(`Module ${name} is already registered`);
}
const mod = fn(dynamicExport, systemContext);
if (deps.length > 0) {
if (!Array.isArray(mod.setters)) {
throw new Error(
`Module ${name} must have setters, because it has dependencies`
);
}
if (mod.setters.length !== deps.length) {
throw new Error(
`Module ${name} has incorrect number of setters for the dependencies`
);
}
}
const entry = {
name,
deps,
fn,
mod,
executed: false,
exports: undefined
};
System.registry[name] = entry;
},
set: (name, exports) => {
System.registry[name] = {
name,
executed: true,
exports
};
},
registry: undefined,
_require: undefined,
_nextName: "(anonym)",
setRequire: req => {
System._require = req;
},
init: modules => {
System.registry = {};
if (modules) {
for (const name of Object.keys(modules)) {
System.registry[name] = {
executed: true,
exports: modules[name]
};
}
}
},
execute: name => {
const m = System.registry[name];
if (!m) throw new Error(`Module ${name} not registered`);
if (m.executed) throw new Error(`Module ${name} was already executed`);
return System.ensureExecuted(name);
},
ensureExecuted: name => {
let m = System.registry[name];
if (!m && System._require) {
const oldName = System._nextName;
System._nextName = name;
System._require(name);
System._nextName = oldName;
m = System.registry[name];
}
if (!m) {
throw new Error(`Module ${name} not registered`);
}
if (!m.executed) {
m.executed = true;
for (let i = 0; i < m.deps.length; i++) {
const dep = m.deps[i];
const setters = m.mod.setters[i];
System.ensureExecuted(dep);
const { exports } = System.registry[dep];
if (exports !== undefined) setters(exports);
}
m.mod.execute();
}
return m.exports;
}
};
module.exports = System;
98 changes: 98 additions & 0 deletions packages/rspack-test-tools/src/helper/util/checkSourceMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// @ts-nocheck
// Check the mapping of various key locations back to the original source
export default async function checkSourceMap(out, outCodeMap, toSearch) {
let failed = false;
const recordCheck = (success, message) => {
if (!success) {
failed = true;
console.error(`❌ ${message}`);
}
};

const sourceMap = require("source-map");
const path = require("path");

const sources = JSON.parse(outCodeMap).sources;
for (let source of sources) {
if (sources.filter(s => s === source).length > 1) {
throw new Error(
`Duplicate source ${JSON.stringify(source)} found in source map`
);
}
}
const map = await new sourceMap.SourceMapConsumer(outCodeMap);
for (const id in toSearch) {
const outIndex = out.indexOf(id);
if (outIndex < 0)
throw new Error(`Failed to find "${id}" in output ${out}`);
const outLines = out.slice(0, outIndex).split("\n");
const outLine = outLines.length;
const outLastLine = outLines[outLines.length - 1];
let outColumn = outLastLine.length;
const { source, line, column } = map.originalPositionFor({
line: outLine,
column: outColumn
});

const inSource = toSearch[id];
recordCheck(
source === inSource,
`expected source: ${inSource}, observed source: ${source}@${line}:${column}, {out_source}@${outLine}:${outColumn}.`
);

const inCode = map.sourceContentFor(source);
let inIndex = inCode.indexOf(id);
if (inIndex < 0) inIndex = inCode.indexOf(`'${id}'`);
if (inIndex < 0)
throw new Error(`Failed to find "${id}" in input ${inCode}`);
const inLines = inCode.slice(0, inIndex).split("\n");
const inLine = inLines.length;
const inLastLine = inLines[inLines.length - 1];
let inColumn = inLastLine.length;

if (path.extname(source) === "css") {
const outMatch = /\s*content:\s*$/.exec(outLastLine);
const inMatch = /\bcontent:\s*$/.exec(inLastLine);
if (outMatch) outColumn -= outMatch[0].length;
if (inMatch) inColumn -= inMatch[0].length;
}

const expected = JSON.stringify({ source, line: inLine, column: inColumn });
const observed = JSON.stringify({ source, line, column });
recordCheck(
expected === observed,
`expected original position: ${expected}, observed original position: ${observed}, out: ${
outLine + "," + outColumn + "," + outIndex + ":" + id
}`
);

// Also check the reverse mapping
const positions = map.allGeneratedPositionsFor({
source,
line: inLine,
column: inColumn
});
recordCheck(
positions.length > 0,
`expected generated positions: 1, observed generated positions: ${positions.length}`
);
let found = false;
for (const { line, column } of positions) {
if (line === outLine && column === outColumn) {
found = true;
break;
}
}
const expectedPosition = JSON.stringify({
line: outLine,
column: outColumn
});
const observedPositions = JSON.stringify(positions);
recordCheck(
found,
`expected generated position: ${expectedPosition}, observed generated positions: ${observedPositions}`
);
}

return !failed;
}
55 changes: 55 additions & 0 deletions packages/rspack-test-tools/src/helper/util/filterUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// @ts-nocheck
const FilteredStatus = {
TODO: "TODO",
PARTIAL_PASS: "PARTIAL_PASS",
FAILED: "FAILED",
NO_PLAN: "NO_PLAN"
};

function validateFilteredStatus(status) {
return Object.values(FilteredStatus).includes(status);
}

function normalizeFilterFlag(flag, testName) {
if (flag === false) {
return { status: FilteredStatus.TODO, reason: "TODO" };
}
if (flag === -1) {
return { status: FilteredStatus.NO_PLAN, reason: "No plan" };
}
if (typeof flag === "string") {
return { status: FilteredStatus.FAILED, reason: flag };
}
if (Array.isArray(flag)) {
const [status, reason = "empty"] = flag;
if (validateFilteredStatus(status)) {
return { status, reason };
}
}
throw new Error(`Unvalidate filter flag "${flag}" for "${testName}"`);
}

function encodeFilteredTest(status, reason) {
return `{{ status = ${status}, reason = ${reason} }}`;
}

function decodeFilteredTest(encoded) {
const regex = /(.*) {{ status = (.*), reason = (.*) }}$/;
const result = encoded.match(regex);
if (result === null) {
return result;
}
const [, fullName, status, reason] = result;
return { fullName, status, reason };
}

function normalizeFilteredTestName(flag, testName) {
const { status, reason } = normalizeFilterFlag(flag, testName);
return encodeFilteredTest(status, reason);
}

module.exports = {
FilteredStatus,
decodeFilteredTest,
normalizeFilteredTestName
};
Loading

2 comments on commit 476961a

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Ran ecosystem CI: Open

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

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Benchmark detail: Open

Name Base (2024-04-23 81c41c8) Current Change
10000_development-mode + exec 2.69 s ± 45 ms 2.72 s ± 60 ms +1.31 %
10000_development-mode_hmr + exec 682 ms ± 2.6 ms 696 ms ± 15 ms +2.09 %
10000_production-mode + exec 2.5 s ± 29 ms 2.56 s ± 51 ms +2.27 %
arco-pro_development-mode + exec 2.51 s ± 77 ms 2.5 s ± 85 ms -0.38 %
arco-pro_development-mode_hmr + exec 430 ms ± 2 ms 430 ms ± 2 ms +0.15 %
arco-pro_development-mode_hmr_intercept-plugin + exec 441 ms ± 4.3 ms 441 ms ± 3.3 ms +0.02 %
arco-pro_development-mode_intercept-plugin + exec 3.21 s ± 65 ms 3.27 s ± 70 ms +1.91 %
arco-pro_production-mode + exec 3.95 s ± 87 ms 4.02 s ± 72 ms +1.84 %
arco-pro_production-mode_intercept-plugin + exec 4.69 s ± 55 ms 4.79 s ± 110 ms +2.18 %
threejs_development-mode_10x + exec 2.06 s ± 20 ms 2.07 s ± 35 ms +0.58 %
threejs_development-mode_10x_hmr + exec 748 ms ± 8.2 ms 773 ms ± 5.5 ms +3.34 %
threejs_production-mode_10x + exec 5.15 s ± 49 ms 5.21 s ± 80 ms +1.17 %

Please sign in to comment.