-
-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate config test cases (#6335)
- Loading branch information
1 parent
432ce5e
commit 476961a
Showing
1,998 changed files
with
841 additions
and
870 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
packages/rspack-test-tools/src/helper/legacy/fakeSystem.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
98
packages/rspack-test-tools/src/helper/util/checkSourceMap.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
Oops, something went wrong.
476961a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Ran ecosystem CI: Open
476961a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Benchmark detail: Open