diff --git a/cspell.json b/cspell.json index 737b46957..7c12cb021 100644 --- a/cspell.json +++ b/cspell.json @@ -322,6 +322,7 @@ "standalones", "Stankiewicz", "starturl", + "stylefmt", "styleguides", "stylelint", "stylelintrc", diff --git a/tests/handlebars/venerable/__snapshots__/jsfmt.spec.js.snap b/tests/html/handlebars-venerable/__snapshots__/jsfmt.spec.js.snap similarity index 100% rename from tests/handlebars/venerable/__snapshots__/jsfmt.spec.js.snap rename to tests/html/handlebars-venerable/__snapshots__/jsfmt.spec.js.snap diff --git a/tests/handlebars/venerable/jsfmt.spec.js b/tests/html/handlebars-venerable/jsfmt.spec.js similarity index 100% rename from tests/handlebars/venerable/jsfmt.spec.js rename to tests/html/handlebars-venerable/jsfmt.spec.js diff --git a/tests/handlebars/venerable/template.html b/tests/html/handlebars-venerable/template.html similarity index 100% rename from tests/handlebars/venerable/template.html rename to tests/html/handlebars-venerable/template.html diff --git a/tests/html/lwc/__snapshots__/jsfmt.spec.js.snap b/tests/lwc/lwc/__snapshots__/jsfmt.spec.js.snap similarity index 100% rename from tests/html/lwc/__snapshots__/jsfmt.spec.js.snap rename to tests/lwc/lwc/__snapshots__/jsfmt.spec.js.snap diff --git a/tests/html/lwc/attributes.html b/tests/lwc/lwc/attributes.html similarity index 100% rename from tests/html/lwc/attributes.html rename to tests/lwc/lwc/attributes.html diff --git a/tests/html/lwc/jsfmt.spec.js b/tests/lwc/lwc/jsfmt.spec.js similarity index 100% rename from tests/html/lwc/jsfmt.spec.js rename to tests/lwc/lwc/jsfmt.spec.js diff --git a/tests/css/trailing-comma/__snapshots__/jsfmt.spec.js.snap b/tests/scss/trailing-comma/__snapshots__/jsfmt.spec.js.snap similarity index 100% rename from tests/css/trailing-comma/__snapshots__/jsfmt.spec.js.snap rename to tests/scss/trailing-comma/__snapshots__/jsfmt.spec.js.snap diff --git a/tests/css/trailing-comma/at-rules.css b/tests/scss/trailing-comma/at-rules.css similarity index 100% rename from tests/css/trailing-comma/at-rules.css rename to tests/scss/trailing-comma/at-rules.css diff --git a/tests/css/trailing-comma/declaration.css b/tests/scss/trailing-comma/declaration.css similarity index 100% rename from tests/css/trailing-comma/declaration.css rename to tests/scss/trailing-comma/declaration.css diff --git a/tests/css/trailing-comma/jsfmt.spec.js b/tests/scss/trailing-comma/jsfmt.spec.js similarity index 100% rename from tests/css/trailing-comma/jsfmt.spec.js rename to tests/scss/trailing-comma/jsfmt.spec.js diff --git a/tests/css/trailing-comma/list.css b/tests/scss/trailing-comma/list.css similarity index 100% rename from tests/css/trailing-comma/list.css rename to tests/scss/trailing-comma/list.css diff --git a/tests/css/trailing-comma/map.css b/tests/scss/trailing-comma/map.css similarity index 100% rename from tests/css/trailing-comma/map.css rename to tests/scss/trailing-comma/map.css diff --git a/tests/css/trailing-comma/selector_list.css b/tests/scss/trailing-comma/selector_list.css similarity index 100% rename from tests/css/trailing-comma/selector_list.css rename to tests/scss/trailing-comma/selector_list.css diff --git a/tests/css/trailing-comma/variable.css b/tests/scss/trailing-comma/variable.css similarity index 100% rename from tests/css/trailing-comma/variable.css rename to tests/scss/trailing-comma/variable.css diff --git a/tests/angular/component-examples/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/angular-component-examples/__snapshots__/jsfmt.spec.js.snap similarity index 100% rename from tests/angular/component-examples/__snapshots__/jsfmt.spec.js.snap rename to tests/typescript/angular-component-examples/__snapshots__/jsfmt.spec.js.snap diff --git a/tests/angular/component-examples/jsfmt.spec.js b/tests/typescript/angular-component-examples/jsfmt.spec.js similarity index 100% rename from tests/angular/component-examples/jsfmt.spec.js rename to tests/typescript/angular-component-examples/jsfmt.spec.js diff --git a/tests/angular/component-examples/test.component.ts b/tests/typescript/angular-component-examples/test.component.ts similarity index 100% rename from tests/angular/component-examples/test.component.ts rename to tests/typescript/angular-component-examples/test.component.ts diff --git a/tests_config/run_spec.js b/tests_config/run_spec.js index 0daf7e402..a693df248 100644 --- a/tests_config/run_spec.js +++ b/tests_config/run_spec.js @@ -4,6 +4,7 @@ const fs = require("fs"); const path = require("path"); const raw = require("jest-snapshot-serializer-raw").wrap; const { isCI } = require("ci-info"); +const checkParsers = require("./utils/check-parsers"); const { TEST_STANDALONE } = process.env; const AST_COMPARE = isCI || process.env.AST_COMPARE; @@ -54,6 +55,9 @@ global.run_spec = (fixtures, parsers, options) => { fixtures = typeof fixtures === "string" ? { dirname: fixtures } : fixtures; const { dirname } = fixtures; + // Make sure tests are in correct location + checkParsers(dirname, parsers); + // `IS_PARSER_INFERENCE_TESTS` mean to test `inferParser` on `standalone` const IS_PARSER_INFERENCE_TESTS = isTestDirectory( dirname, diff --git a/tests_config/utils/check-parsers.js b/tests_config/utils/check-parsers.js new file mode 100644 index 000000000..8939d598b --- /dev/null +++ b/tests_config/utils/check-parsers.js @@ -0,0 +1,79 @@ +"use strict"; + +const path = require("path"); +const { outdent } = require("outdent"); + +const TESTS_ROOT = path.join(__dirname, "../../tests"); + +const getCategory = (dirname) => + path.relative(TESTS_ROOT, dirname).split(path.sep).shift(); + +const categoryParsers = new Map( + [ + ["angular", ["angular", "__ng_interpolation"]], + ["css", ["css" /* ,"less", "scss" These may allow, but not using */]], + ["flow", ["babel", "flow", "babel-flow"]], + ["flow-repo", ["babel", "flow", "babel-flow"]], + ["graphql", ["graphql"]], + ["handlebars", ["glimmer"]], + ["html", ["html"]], + ["js", ["babel", "flow", "babel-flow", "typescript", "babel-ts"]], + ["json", ["json", "json5", "json-stringify"]], + ["jsx", ["babel", "flow", "babel-flow", "typescript", "babel-ts"]], + ["less", ["css", "less"]], + ["lwc", ["lwc"]], + ["markdown", ["markdown"]], + ["mdx", ["mdx"]], + ["scss", ["css", "scss"]], + ["stylefmt-repo", ["css"]], + ["typescript", ["typescript", "babel-ts"]], + ["vue", ["vue"]], + ["yaml", ["yaml"]], + ].map(([category, parsers]) => [category, new Set(parsers)]) +); + +const getParserCategories = (parser) => { + const categories = []; + for (const [category, parsers] of categoryParsers) { + if (parsers.has(parser)) { + categories.push(category); + } + } + + return categories; +}; + +const checkParser = (dirname, parsers) => { + const category = getCategory(dirname); + const allowedParsers = categoryParsers.get(category); + + if (!allowedParsers) { + return; + } + + for (const parser of parsers) { + if (!allowedParsers.has(parser)) { + const suggestCategories = getParserCategories(parser); + + const suggestion = + suggestCategories.length === 0 + ? "" + : outdent` + Suggest move your tests to: + ${suggestCategories + .map((category) => `- ${path.join(TESTS_ROOT, category)}`) + .join("\n")} + + Or config to allow use this parser in "${__filename}". + `; + + throw new Error( + `Parser "${parser}" should not used in "${dirname}".${ + suggestion ? `\n\n${suggestion}` : "" + }` + ); + } + } +}; + +module.exports = checkParser;