renaming jsfmt.spec.js to format.test.js (#16244)
Co-authored-by: fisker <lionkay@gmail.com>
This commit is contained in:
1 parent
1663d59e72
commit
16449ce914
2475 files changed
+36
-9
No files matched your search
+1
-1
@@ -17,5 +17,5 @@ trim_trailing_whitespace = false
|
||||
[tests/{**/__snapshots__/*, tests/format/**/*}]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[tests/format/**/jsfmt.spec.js]
|
||||
[tests/format/**/format.test.js]
|
||||
trim_trailing_whitespace = true
|
||||
@@ -2,6 +2,8 @@
|
||||
# Do not use `tests/format/**/*`, since it will ignore directories
|
||||
# https://github.com/eslint/eslint/issues/17964#issuecomment-1879772142
|
||||
tests/format/**/*.*
|
||||
!tests/format/**/format.test.js
|
||||
# TODO: Remove this in 2025
|
||||
!tests/format/**/jsfmt.spec.js
|
||||
tests/integration/cli/
|
||||
test*.*
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
**/.yarn/*
|
||||
|
||||
/tests/format/**/*.*
|
||||
!/tests/format/**/jsfmt.spec.js
|
||||
!/tests/format/**/format.test.js
|
||||
/tests/integration/cli/
|
||||
/tests/integration/plugins/**/*.*
|
||||
!/tests/integration/plugins/automatic/node_modules/@prettier/plugin-foo/index.js
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ yarn test
|
||||
|
||||
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.
|
||||
|
||||
Each test directory in `tests/format` has a `jsfmt.spec.js` file that controls how exactly the rest of the files in the directory are used for tests. This file must contain one or more calls to the `runFormatTest` global function. For example, in directories with JavaScript formatting tests, `jsfmt.spec.js` generally looks like this:
|
||||
Each test directory in `tests/format` has a `format.test.js` file that controls how exactly the rest of the files in the directory are used for tests. This file must contain one or more calls to the `runFormatTest` global function. For example, in directories with JavaScript formatting tests, `format.test.js` generally looks like this:
|
||||
|
||||
```js
|
||||
runFormatTest(import.meta, ["babel", "flow", "typescript"]);
|
||||
|
||||
+1
-1
@@ -385,7 +385,7 @@
|
||||
"website/**/*",
|
||||
"tests/config/**/*",
|
||||
"tests/integration/**/*",
|
||||
"tests/format/**/jsfmt.spec.js"
|
||||
"tests/format/**/format.test.js"
|
||||
],
|
||||
"ignorePaths": [
|
||||
".git",
|
||||
|
||||
+1
-1
@@ -290,7 +290,7 @@ export default [
|
||||
{
|
||||
files: [
|
||||
"tests/config/**/*.js",
|
||||
"tests/format/**/jsfmt.spec.js",
|
||||
"tests/format/**/format.test.js",
|
||||
"tests/integration/**/*.js",
|
||||
"tests/unit/**/*.js",
|
||||
"tests/dts/unit/**/*.js",
|
||||
|
||||
@@ -65,6 +65,8 @@ const config = {
|
||||
"jest-snapshot-serializer-ansi",
|
||||
],
|
||||
testMatch: [
|
||||
"<rootDir>/tests/format/**/format.test.js",
|
||||
// TODO: Remove this in 2025
|
||||
"<rootDir>/tests/format/**/jsfmt.spec.js",
|
||||
"<rootDir>/tests/integration/__tests__/**/*.js",
|
||||
"<rootDir>/tests/unit/**/*.js",
|
||||
|
||||
@@ -6,7 +6,7 @@ const flowParser = require("flow-parser");
|
||||
const fastGlob = require("fast-glob");
|
||||
|
||||
const DEFAULT_SPEC_CONTENT = "runFormatTest(import.meta);\n";
|
||||
const SPEC_FILE_NAME = "jsfmt.spec.js";
|
||||
const SPEC_FILE_NAME = "format.test.js";
|
||||
const FLOW_TESTS_DIR = path.join(__dirname, "../tests/format/flow-repo");
|
||||
|
||||
function tryParse(file, content) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
|
||||
const legacyRunFormatTestCall = [
|
||||
"CallExpression",
|
||||
'[callee.type="Identifier"]',
|
||||
@@ -34,6 +36,7 @@ const dirnamePropertySelector = [
|
||||
const MESSAGE_ID_LEGACY_FUNCTION_NAME = "legacy-function-name";
|
||||
const MESSAGE_ID_ARGUMENT = "dirname-argument";
|
||||
const MESSAGE_ID_PROPERTY = "dirname-property";
|
||||
const MESSAGE_ID_LEGACY_FILENAME = "legacy-filename";
|
||||
|
||||
module.exports = {
|
||||
meta: {
|
||||
@@ -47,6 +50,7 @@ module.exports = {
|
||||
[MESSAGE_ID_ARGUMENT]: "Use `import.meta` instead of `__dirname`.",
|
||||
[MESSAGE_ID_PROPERTY]:
|
||||
"Use `importMeta: import.meta` instead of `dirname: __dirname`.",
|
||||
[MESSAGE_ID_LEGACY_FILENAME]: "File should be named as 'format.test.js'.",
|
||||
},
|
||||
fixable: "code",
|
||||
hasSuggestions: true,
|
||||
@@ -78,6 +82,17 @@ module.exports = {
|
||||
],
|
||||
});
|
||||
},
|
||||
Program(node) {
|
||||
const filename = path.basename(context.physicalFilename);
|
||||
if (filename !== "jsfmt.spec.js") {
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
node,
|
||||
messageId: MESSAGE_ID_LEGACY_FILENAME,
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -152,6 +152,14 @@ function runFormatTest(fixtures, parsers, options) {
|
||||
let { importMeta, snippets = [] } = fixtures.importMeta
|
||||
? fixtures
|
||||
: { importMeta: fixtures };
|
||||
|
||||
// TODO: Remove this in 2025
|
||||
// Prevent the old files `jsfmt.spec.js` get merged by accident
|
||||
const filename = path.basename(new URL(importMeta.url).pathname);
|
||||
if (filename !== "format.test.js") {
|
||||
throw new Error(`'${filename}' has been renamed as 'format.test.js'.`);
|
||||
}
|
||||
|
||||
const dirname = path.dirname(url.fileURLToPath(importMeta.url));
|
||||
|
||||
// `IS_PARSER_INFERENCE_TESTS` mean to test `inferParser` on `standalone`
|
||||
@@ -199,7 +207,7 @@ function runFormatTest(fixtures, parsers, options) {
|
||||
path.extname(basename) === ".snap" ||
|
||||
!file.isFile() ||
|
||||
basename[0] === "." ||
|
||||
basename === "jsfmt.spec.js" ||
|
||||
basename === "format.test.js" ||
|
||||
// VSCode creates this file sometime https://github.com/microsoft/vscode/issues/105191
|
||||
basename === "debug.log"
|
||||
) {
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loaded 100 of 2475 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user