mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[sprout] patch bug + add verbose mode
--- ``` yarn sprout --verbose ``` Verbose mode prints out all outputs of tests. The test output is a status (`ok` or `exception`), a returned or thrown value, and a set of console logs. Currently as of #1960 , this is the output: ```sh $ yarn workspace babel-plugin-react-forget run build && node ../sprout/dist/main.js --verbose $ rimraf dist && tsc PASS alias-nested-member-path ok {"y":{"z":[]}} PASS assignment-variations-complex-lvalue ok {"y":{"z":4}} PASS assignment-variations ok 1 PASS chained-assignment-expressions ok {"z":null} PASS computed-call-evaluation-order ok {"f":"[[ function params=0 ]]"} [ "A", "B", "arg", "original" ] PASS const-propagation-into-function-expression-primitive ok 42 [ "42" ] PASS constant-propagation-for ok 0 PASS constant-propagation-while ok 0 PASS constant-propagation ok -6 [ "foo" ] PASS controlled-input ok <input value="0"> PASS do-while-continue ok [1.5,1,0.5] PASS do-while-simple ok [6,4,2] PASS expression-with-assignment ok 5 PASS for-of-break ok [] PASS for-of-conditional-break ok [] PASS for-of-continue ok [0.5,1,1.5] PASS for-of-destructure ok [0,2,4] PASS for-of-simple ok [0,2,4] PASS function-declaration-reassign ok {} PASS function-declaration-redeclare ok "[[ function params=0 ]]" PASS lambda-reassign-primitive ok 41 PASS lambda-reassign-shadowed-primitive ok {} PASS property-call-evaluation-order ok {"f":"[[ function params=0 ]]"} [ "A", "arg", "original" ] PASS reactive-scope-grouping ok {"y":[{}]} PASS sequentially-constant-progagatable-if-test-conditions ok "ok" PASS simple-function-1 ok "[[ function params=1 ]]" PASS ssa-complex-multiple-if ok PASS ssa-complex-single-if ok PASS ssa-for ok 11 PASS ssa-if-else ok PASS ssa-objectexpression-phi ok {"x":1,"y":3} PASS ssa-property-call ok {"x":[[]]} PASS ssa-property ok {"x":[]} PASS ssa-return ok 2 PASS ssa-simple-phi ok PASS ssa-simple ok PASS ssa-single-if ok PASS ssa-switch ok PASS ssa-throw exception undefined PASS ssa-while ok 10 PASS type-field-load ok 1 PASS type-test-field-store ok {} PASS type-test-primitive ok 2 PASS update-expression-constant-propagation ok {"a":0,"b":0,"c":2,"d":2,"e":0} 44 Tests, 44 Passed, 0 Failed ✨ Done in 9.27s. ```
This commit is contained in:
@@ -29,10 +29,22 @@ const PLACEHOLDER_VALUE = Symbol();
|
||||
const seen = new Map();
|
||||
|
||||
return JSON.stringify(result, (_key, val) => {
|
||||
if (typeof val === "object") {
|
||||
if (typeof val === "function") {
|
||||
return `[[ function params=${val.length} ]]`;
|
||||
} else if (typeof val === "object") {
|
||||
let id = seen.get(val);
|
||||
if (id != null) {
|
||||
return `[[ cyclic ref *${id} ]]`;
|
||||
} else if (val instanceof Map) {
|
||||
return {
|
||||
kind: "Map",
|
||||
value: Array.from(val.entries()), // or with spread: value: [...value]
|
||||
};
|
||||
} else if (val instanceof Set) {
|
||||
return {
|
||||
kind: "Set",
|
||||
value: Array.from(val.values()), // or with spread: value: [...value]
|
||||
};
|
||||
}
|
||||
seen.set(val, seen.size);
|
||||
}
|
||||
@@ -56,7 +68,7 @@ export function doEval(source: string): EvaluatorResult {
|
||||
let exports = {
|
||||
FIXTURE_ENTRYPOINT: {
|
||||
fn: globalThis.placeholderFn,
|
||||
args: [],
|
||||
params: [],
|
||||
isComponent: false,
|
||||
},
|
||||
};
|
||||
@@ -64,14 +76,18 @@ export function doEval(source: string): EvaluatorResult {
|
||||
try {
|
||||
${source}
|
||||
reachedInvoke = true;
|
||||
|
||||
if (exports.FIXTURE_ENTRYPOINT.isComponent) {
|
||||
if (exports.FIXTURE_ENTRYPOINT == null || exports.FIXTURE_ENTRYPOINT.fn === globalThis.placeholderFn) {
|
||||
return {
|
||||
kind: "UnexpectedError",
|
||||
value: 'FIXTURE_ENTRYPOINT not exported!',
|
||||
};
|
||||
} else if (exports.FIXTURE_ENTRYPOINT.isComponent) {
|
||||
// try to run fixture as a react component
|
||||
const result = render(
|
||||
React.createElement(
|
||||
exports.FIXTURE_ENTRYPOINT.fn,
|
||||
exports.FIXTURE_ENTRYPOINT.params)
|
||||
).asFragment().textContent;
|
||||
).container.innerHTML;
|
||||
|
||||
return {
|
||||
kind: "ok",
|
||||
@@ -83,7 +99,7 @@ export function doEval(source: string): EvaluatorResult {
|
||||
WrapperTestComponent,
|
||||
exports.FIXTURE_ENTRYPOINT
|
||||
)
|
||||
).asFragment().textContent;
|
||||
).container.innerHTML;
|
||||
|
||||
return {
|
||||
kind: "ok",
|
||||
@@ -96,11 +112,6 @@ export function doEval(source: string): EvaluatorResult {
|
||||
kind: "UnexpectedError",
|
||||
value: e.toString(),
|
||||
};
|
||||
} else if (e === PLACEHOLDER_VALUE) {
|
||||
return {
|
||||
kind: "UnexpectedError",
|
||||
value: 'FIXTURE_ENTRYPOINT not defined!',
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
kind: "exception",
|
||||
|
||||
@@ -37,6 +37,7 @@ process.on("SIGTERM", function () {
|
||||
type RunnerOptions = {
|
||||
filter: boolean;
|
||||
sync: boolean;
|
||||
verbose: boolean;
|
||||
};
|
||||
|
||||
const opts: RunnerOptions = yargs
|
||||
@@ -52,6 +53,9 @@ const opts: RunnerOptions = yargs
|
||||
`Evaluate fixtures in filter mode ("${FILTER_FILENAME}")\n`
|
||||
)
|
||||
.default("filter", false)
|
||||
.boolean("verbose")
|
||||
.describe("verbose", "Print results of passing fixtures.")
|
||||
.default("verbose", false)
|
||||
.help("help")
|
||||
.strict()
|
||||
.parseSync(hideBin(process.argv));
|
||||
@@ -64,7 +68,8 @@ function logsEqual(a: Array<string>, b: Array<string>) {
|
||||
}
|
||||
|
||||
function reportResults(
|
||||
results: Array<[string, RunnerWorker.TestResult]>
|
||||
results: Array<[string, RunnerWorker.TestResult]>,
|
||||
verbose: boolean
|
||||
): boolean {
|
||||
const failures: Array<[string, RunnerWorker.TestResult]> = [];
|
||||
|
||||
@@ -92,6 +97,15 @@ function reportResults(
|
||||
console.log(
|
||||
chalk.green.inverse.bold(" PASS ") + " " + chalk.dim(fixtureName)
|
||||
);
|
||||
if (verbose) {
|
||||
console.log(
|
||||
` ${forgetResult.kind} ${forgetResult.value} ${
|
||||
forgetResult.logs.length > 0
|
||||
? JSON.stringify(forgetResult.logs, undefined, 2)
|
||||
: ""
|
||||
}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +153,6 @@ function reportResults(
|
||||
2
|
||||
)}\nFound: ${JSON.stringify(nonForgetResult, undefined, 2)}`
|
||||
);
|
||||
failures.push([fixtureName, result]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,7 +209,7 @@ export async function main(opts: RunnerOptions): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
const isSuccess = reportResults(results);
|
||||
const isSuccess = reportResults(results, opts.verbose);
|
||||
process.exit(isSuccess ? 0 : 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user