Skip to content

Commit

Permalink
renaming jsfmt.spec.js to format.test.js (#16244)
Browse files Browse the repository at this point in the history
Co-authored-by: fisker <lionkay@gmail.com>
  • Loading branch information
Janther and fisker committed May 6, 2024
1 parent 1663d59 commit 16449ce
Show file tree
Hide file tree
Showing 2,475 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -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 changes: 2 additions & 0 deletions .eslintignore
Expand Up @@ -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*.*
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -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"]);
Expand Down
2 changes: 1 addition & 1 deletion cspell.json
Expand Up @@ -385,7 +385,7 @@
"website/**/*",
"tests/config/**/*",
"tests/integration/**/*",
"tests/format/**/jsfmt.spec.js"
"tests/format/**/format.test.js"
],
"ignorePaths": [
".git",
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.js
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions jest.config.js
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion scripts/sync-flow-tests.cjs
Expand Up @@ -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) {
Expand Down
@@ -1,5 +1,7 @@
"use strict";

const path = require("path");

const legacyRunFormatTestCall = [
"CallExpression",
'[callee.type="Identifier"]',
Expand Down Expand Up @@ -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: {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
});
},
};
},
};
10 changes: 9 additions & 1 deletion tests/config/run-format-test.js
Expand Up @@ -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`
Expand Down Expand Up @@ -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"
) {
Expand Down
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.

0 comments on commit 16449ce

Please sign in to comment.