@samitouri / QOS-React-1 / commits / c4ae2a48dc

[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. ```

Mofei Zhang committed Aug 16, 2023 at 15:32 UTC c4ae2a48dcd81ccd4a82326d7d3b9e7c9b3b457f
2 files changed +38 -14
compiler/forget/packages/sprout/src/runner-evaluator.ts
+22 -11
@@ -29,10 +29,22 @@ const PLACEHOLDER_VALUE = Symbol();
29 const seen = new Map();
30
31 return JSON.stringify(result, (_key, val) => {
32 - if (typeof val === "object") {
32 + if (typeof val === "function") {
33 + return `[[ function params=${val.length} ]]`;
34 + } else if (typeof val === "object") {
35 let id = seen.get(val);
36 if (id != null) {
37 return `[[ cyclic ref *${id} ]]`;
38 + } else if (val instanceof Map) {
39 + return {
40 + kind: "Map",
41 + value: Array.from(val.entries()), // or with spread: value: [...value]
42 + };
43 + } else if (val instanceof Set) {
44 + return {
45 + kind: "Set",
46 + value: Array.from(val.values()), // or with spread: value: [...value]
47 + };
48 }
49 seen.set(val, seen.size);
50 }
@@ -56,7 +68,7 @@ export function doEval(source: string): EvaluatorResult {
68 let exports = {
69 FIXTURE_ENTRYPOINT: {
70 fn: globalThis.placeholderFn,
59 - args: [],
71 + params: [],
72 isComponent: false,
73 },
74 };
@@ -64,14 +76,18 @@ export function doEval(source: string): EvaluatorResult {
76 try {
77 ${source}
78 reachedInvoke = true;
67 -
68 - if (exports.FIXTURE_ENTRYPOINT.isComponent) {
79 + if (exports.FIXTURE_ENTRYPOINT == null || exports.FIXTURE_ENTRYPOINT.fn === globalThis.placeholderFn) {
80 + return {
81 + kind: "UnexpectedError",
82 + value: 'FIXTURE_ENTRYPOINT not exported!',
83 + };
84 + } else if (exports.FIXTURE_ENTRYPOINT.isComponent) {
85 // try to run fixture as a react component
86 const result = render(
87 React.createElement(
88 exports.FIXTURE_ENTRYPOINT.fn,
89 exports.FIXTURE_ENTRYPOINT.params)
74 - ).asFragment().textContent;
90 + ).container.innerHTML;
91
92 return {
93 kind: "ok",
@@ -83,7 +99,7 @@ export function doEval(source: string): EvaluatorResult {
99 WrapperTestComponent,
100 exports.FIXTURE_ENTRYPOINT
101 )
86 - ).asFragment().textContent;
102 + ).container.innerHTML;
103
104 return {
105 kind: "ok",
@@ -96,11 +112,6 @@ export function doEval(source: string): EvaluatorResult {
112 kind: "UnexpectedError",
113 value: e.toString(),
114 };
99 - } else if (e === PLACEHOLDER_VALUE) {
100 - return {
101 - kind: "UnexpectedError",
102 - value: 'FIXTURE_ENTRYPOINT not defined!',
103 - };
115 } else {
116 return {
117 kind: "exception",
compiler/forget/packages/sprout/src/runner.ts
+16 -3
@@ -37,6 +37,7 @@ process.on("SIGTERM", function () {
37 type RunnerOptions = {
38 filter: boolean;
39 sync: boolean;
40 + verbose: boolean;
41 };
42
43 const opts: RunnerOptions = yargs
@@ -52,6 +53,9 @@ const opts: RunnerOptions = yargs
53 `Evaluate fixtures in filter mode ("${FILTER_FILENAME}")\n`
54 )
55 .default("filter", false)
56 + .boolean("verbose")
57 + .describe("verbose", "Print results of passing fixtures.")
58 + .default("verbose", false)
59 .help("help")
60 .strict()
61 .parseSync(hideBin(process.argv));
@@ -64,7 +68,8 @@ function logsEqual(a: Array<string>, b: Array<string>) {
68 }
69
70 function reportResults(
67 - results: Array<[string, RunnerWorker.TestResult]>
71 + results: Array<[string, RunnerWorker.TestResult]>,
72 + verbose: boolean
73 ): boolean {
74 const failures: Array<[string, RunnerWorker.TestResult]> = [];
75
@@ -92,6 +97,15 @@ function reportResults(
97 console.log(
98 chalk.green.inverse.bold(" PASS ") + " " + chalk.dim(fixtureName)
99 );
100 + if (verbose) {
101 + console.log(
102 + ` ${forgetResult.kind} ${forgetResult.value} ${
103 + forgetResult.logs.length > 0
104 + ? JSON.stringify(forgetResult.logs, undefined, 2)
105 + : ""
106 + }`
107 + );
108 + }
109 }
110 }
111
@@ -139,7 +153,6 @@ function reportResults(
153 2
154 )}\nFound: ${JSON.stringify(nonForgetResult, undefined, 2)}`
155 );
142 - failures.push([fixtureName, result]);
156 }
157 }
158 }
@@ -196,7 +209,7 @@ export async function main(opts: RunnerOptions): Promise<void> {
209 }
210 }
211
199 - const isSuccess = reportResults(results);
212 + const isSuccess = reportResults(results, opts.verbose);
213 process.exit(isSuccess ? 0 : 1);
214 }
215