Test second format (#7565)

This commit is contained in:
fisker Cheung authored and GitHub committed 2020-03-21 13:43:01 +02:00
1 parent 12d0be9874
commit 71b2d35d59
4 files changed
+64 -6

No files matched your search

+3 -1
View File
@@ -12,7 +12,9 @@ Here's what you need to know about the tests:
- The tests use [Jest snapshots](https://facebook.github.io/jest/docs/en/snapshot-testing.html). - The tests use [Jest snapshots](https://facebook.github.io/jest/docs/en/snapshot-testing.html).
- You can make changes and run `jest -u` (or `yarn test -u`) to update the snapshots. Then run `git diff` to take a look at what changed. Always update the snapshots when opening a PR. - You can make changes and run `jest -u` (or `yarn test -u`) to update the snapshots. Then run `git diff` to take a look at what changed. Always update the snapshots when opening a PR.
- You can run `AST_COMPARE=1 jest` for a more robust test run. That formats each file, re-parses it, and compares the new AST with the original one and makes sure they are semantically equivalent. - You can run `AST_COMPARE=1 DEEP_COMPARE=1 jest` for a more robust test run.
- `AST_COMPARE` That formats each file, re-parses it, and compares the new AST with the original one and makes sure they are semantically equivalent.
- `DEEP_COMPARE` That formats each file, then formats the output again, and checks that the second output is the same as the first.
- Each test folder has a `jsfmt.spec.js` that runs the tests. For JavaScript files, generally you can just put `run_spec(__dirname, ["babel", "flow", "typescript"]);` there. This will verify that the output using each parser is the same. You can also pass options as the third argument, like this: `run_spec(__dirname, ["babel"], { trailingComma: "es5" });` - Each test folder has a `jsfmt.spec.js` that runs the tests. For JavaScript files, generally you can just put `run_spec(__dirname, ["babel", "flow", "typescript"]);` there. This will verify that the output using each parser is the same. You can also pass options as the third argument, like this: `run_spec(__dirname, ["babel"], { trailingComma: "es5" });`
- `tests/flow/` contains the Flow test suite, and is not supposed to be edited by hand. To update it, clone the Flow repo next to the Prettier repo and run: `node scripts/sync-flow-tests.js ../flow/tests/`. - `tests/flow/` contains the Flow test suite, and is not supposed to be edited by hand. To update it, clone the Flow repo next to the Prettier repo and run: `node scripts/sync-flow-tests.js ../flow/tests/`.
- If you would like to debug prettier locally, you can either debug it in node or the browser. The easiest way to debug it in the browser is to run the interactive `docs` REPL locally. The easiest way to debug it in node, is to create a local test file with some example code you want formatted and either run it in an editor like VS Code or run it directly via `./bin/prettier.js <your_test_file>`. - If you would like to debug prettier locally, you can either debug it in node or the browser. The easiest way to debug it in the browser is to run the interactive `docs` REPL locally. The easiest way to debug it in node, is to create a local test file with some example code you want formatted and either run it in an editor like VS Code or run it directly via `./bin/prettier.js <your_test_file>`.
+1 -1
View File
@@ -22,7 +22,7 @@
"angular-html-parser": "1.4.0", "angular-html-parser": "1.4.0",
"camelcase": "5.3.1", "camelcase": "5.3.1",
"chalk": "3.0.0", "chalk": "3.0.0",
"ci-info": "2.0.0", "ci-info": "watson/ci-info#f43f6a1cefff47fb361c88cf4b943fdbcaafe540",
"cjk-regex": "2.0.0", "cjk-regex": "2.0.0",
"cosmiconfig": "6.0.0", "cosmiconfig": "6.0.0",
"dashify": "2.0.0", "dashify": "2.0.0",
+58 -1
View File
@@ -7,6 +7,7 @@ const { isCI } = require("ci-info");
const { TEST_STANDALONE, TEST_CRLF } = process.env; const { TEST_STANDALONE, TEST_CRLF } = process.env;
const AST_COMPARE = isCI || process.env.AST_COMPARE; const AST_COMPARE = isCI || process.env.AST_COMPARE;
const DEEP_COMPARE = isCI || process.env.DEEP_COMPARE;
const CURSOR_PLACEHOLDER = "<|>"; const CURSOR_PLACEHOLDER = "<|>";
const RANGE_START_PLACEHOLDER = "<<<PRETTIER_RANGE_START>>>"; const RANGE_START_PLACEHOLDER = "<<<PRETTIER_RANGE_START>>>";
@@ -16,6 +17,42 @@ const prettier = !TEST_STANDALONE
? require("prettier/local") ? require("prettier/local")
: require("prettier/standalone"); : require("prettier/standalone");
// TODO: these test files need fix
const unstableTests = new Map(
[
"class_comment/comments.js",
["comments/dangling_array.js", options => options.semi === false],
["comments/jsx.js", options => options.semi === false],
"comments/return-statement.js",
"comments/tagged-template-literal.js",
"comments_closure_typecast/iife.js",
"css_atrule/include.css",
"graphql_interface/separator-detection.graphql",
[
"html_angular/attributes.component.html",
options => options.printWidth === 1
],
"html_prettier_ignore/cases.html",
"js_empty/semicolon.js",
"jsx_ignore/jsx_ignore.js",
"markdown_footnoteDefinition/multiline.md",
"markdown_spec/example-234.md",
"markdown_spec/example-235.md",
"multiparser_html_js/script-tag-escaping.html",
[
"multiparser_js_markdown/codeblock.js",
options => options.proseWrap === "always"
],
["no-semi/comments.js", options => options.semi === false],
"yaml_prettier_ignore/document.yml"
].map(fixture => {
const [file, isUnstable = () => true] = Array.isArray(fixture)
? fixture
: [fixture];
return [path.join(__dirname, "../tests/", file), isUnstable];
})
);
global.run_spec = (dirname, parsers, options) => { global.run_spec = (dirname, parsers, options) => {
// `IS_PARSER_INFERENCE_TESTS` mean to test `inferParser` on `standalone` // `IS_PARSER_INFERENCE_TESTS` mean to test `inferParser` on `standalone`
const IS_PARSER_INFERENCE_TESTS = dirname.endsWith("parser-inference"); const IS_PARSER_INFERENCE_TESTS = dirname.endsWith("parser-inference");
@@ -105,6 +142,26 @@ global.run_spec = (dirname, parsers, options) => {
parsersToVerify.push("babel-ts"); parsersToVerify.push("babel-ts");
} }
if (
DEEP_COMPARE &&
typeof rangeStart === "undefined" &&
typeof rangeEnd === "undefined" &&
typeof cursorOffset === "undefined" &&
!TEST_CRLF
) {
test(`${basename} second format`, () => {
const secondOutput = format(output, filename, mainOptions);
const isUnstable = unstableTests.get(filename);
if (isUnstable && isUnstable(options || {})) {
// To keep eye on failed tests, this assert never supposed to pass,
// if it fails, just remove the file from `unstableTests`
expect(secondOutput).not.toEqual(output);
} else {
expect(secondOutput).toEqual(output);
}
});
}
for (const parser of parsersToVerify) { for (const parser of parsersToVerify) {
const verifyOptions = { ...baseOptions, parser }; const verifyOptions = { ...baseOptions, parser };
@@ -127,7 +184,7 @@ global.run_spec = (dirname, parsers, options) => {
} }
if (AST_COMPARE) { if (AST_COMPARE) {
test(`${filename} parse`, () => { test(`${basename} parse`, () => {
const parseOptions = { ...mainOptions }; const parseOptions = { ...mainOptions };
delete parseOptions.cursorOffset; delete parseOptions.cursorOffset;
+2 -3
View File
@@ -2112,10 +2112,9 @@ chrome-trace-event@^1.0.2:
dependencies: dependencies:
tslib "^1.9.0" tslib "^1.9.0"
ci-info@2.0.0, ci-info@^2.0.0: ci-info@^2.0.0, ci-info@watson/ci-info#f43f6a1cefff47fb361c88cf4b943fdbcaafe540:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46" resolved "https://codeload.github.com/watson/ci-info/tar.gz/f43f6a1cefff47fb361c88cf4b943fdbcaafe540"
integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==
cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3: cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3:
version "1.0.4" version "1.0.4"