From c6ea73f93a6c820fd4cdbe3dda3cf74913400b30 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Sat, 27 Jul 2024 04:05:58 +0800 Subject: [PATCH] Update test for `--debug-print-ast` (#16518) --- .../__snapshots__/debug-print-ast.js.snap | 5 ----- .../integration/__tests__/debug-print-ast.js | 20 ++++++++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) delete mode 100644 tests/integration/__tests__/__snapshots__/debug-print-ast.js.snap diff --git a/tests/integration/__tests__/__snapshots__/debug-print-ast.js.snap b/tests/integration/__tests__/__snapshots__/debug-print-ast.js.snap deleted file mode 100644 index 4a0ac898b..000000000 --- a/tests/integration/__tests__/__snapshots__/debug-print-ast.js.snap +++ /dev/null @@ -1,5 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`prints information for debugging AST --debug-print-ast (stdout) 1`] = `"{"type":"File","start":0,"end":18,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":18,"index":18}},"range":[0,18],"errors":[],"program":{"type":"Program","start":0,"end":18,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":18,"index":18}},"range":[0,18],"sourceType":"module","interpreter":null,"body":[{"type":"VariableDeclaration","start":0,"end":18,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":18,"index":18}},"range":[0,18],"declarations":[{"type":"VariableDeclarator","start":6,"end":17,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":17,"index":17}},"range":[6,17],"id":{"type":"Identifier","start":6,"end":9,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":9,"index":9},"identifierName":"foo"},"range":[6,9],"name":"foo"},"init":{"type":"StringLiteral","start":12,"end":17,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":17,"index":17}},"range":[12,17],"extra":{"rawValue":"foo","raw":"'foo'"},"value":"foo"}}],"kind":"const"}],"directives":[]},"comments":[],"tokens":[{"type":{"label":"const","keyword":"const","beforeExpr":false,"startsExpr":false,"rightAssociative":false,"isLoop":false,"isAssign":false,"prefix":false,"postfix":false,"binop":null,"updateContext":null},"value":"const","start":0,"end":5,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":5,"index":5}}},{"type":{"label":"name","beforeExpr":false,"startsExpr":true,"rightAssociative":false,"isLoop":false,"isAssign":false,"prefix":false,"postfix":false,"binop":null,"updateContext":null},"value":"foo","start":6,"end":9,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":9,"index":9}}},{"type":{"label":"=","beforeExpr":true,"startsExpr":false,"rightAssociative":false,"isLoop":false,"isAssign":true,"prefix":false,"postfix":false,"binop":null,"updateContext":null},"value":"=","start":10,"end":11,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":11,"index":11}}},{"type":{"label":"string","beforeExpr":false,"startsExpr":true,"rightAssociative":false,"isLoop":false,"isAssign":false,"prefix":false,"postfix":false,"binop":null,"updateContext":null},"value":"foo","start":12,"end":17,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":17,"index":17}}},{"type":{"label":";","beforeExpr":true,"startsExpr":false,"rightAssociative":false,"isLoop":false,"isAssign":false,"prefix":false,"postfix":false,"binop":null,"updateContext":null},"start":17,"end":18,"loc":{"start":{"line":1,"column":17,"index":17},"end":{"line":1,"column":18,"index":18}}},{"type":{"label":"eof","beforeExpr":false,"startsExpr":false,"rightAssociative":false,"isLoop":false,"isAssign":false,"prefix":false,"postfix":false,"binop":null,"updateContext":null},"start":18,"end":18,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":18,"index":18}}}]}"`; - -exports[`prints information for debugging AST --debug-print-ast (write) 1`] = `[]`; diff --git a/tests/integration/__tests__/debug-print-ast.js b/tests/integration/__tests__/debug-print-ast.js index 9bea76f64..9361d7db0 100644 --- a/tests/integration/__tests__/debug-print-ast.js +++ b/tests/integration/__tests__/debug-print-ast.js @@ -1,8 +1,14 @@ -describe("prints information for debugging AST --debug-print-ast", () => { - runCli("cli/with-shebang", ["--debug-print-ast", "--parser", "babel"], { - input: "const foo = 'foo';", - }).test({ - stderr: "", - status: 0, - }); +test("prints information for debugging AST --debug-print-ast", async () => { + const { stdout } = await runCli( + "cli/with-shebang", + ["--debug-print-ast", "--parser", "babel"], + { + input: "const foo = 'foo';", + }, + ); + + const data = JSON.parse(stdout); + + expect(data).toHaveProperty("type", "File"); + expect(data).toHaveProperty("program.type", "Program"); });