Enable jest/prefer-strict-equal rule (#18714)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-01-22 23:53:24 +08:00
1 parent 598e198831
commit b5a3bf3d6e
27 files changed
+132 -124

No files matched your search

+1
View File
@@ -361,6 +361,7 @@ const configs = [
},
],
"jest/prefer-to-be": "error",
"jest/prefer-strict-equal": "error",
},
},
{
+8 -10
View File
@@ -411,15 +411,13 @@ async function runTest({
}
// Make sure output has consistent EOL
expect(formatResult.eolVisualizedOutput).toEqual(
expect(formatResult.eolVisualizedOutput).toBe(
visualizeEndOfLine(consistentEndOfLine(formatResult.outputWithCursor)),
);
// The result is assert to equals to `output`
if (typeof output === "string") {
expect(formatResult.eolVisualizedOutput).toEqual(
visualizeEndOfLine(output),
);
expect(formatResult.eolVisualizedOutput).toBe(visualizeEndOfLine(output));
return;
}
@@ -456,9 +454,9 @@ async function runTest({
// 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(firstOutput);
expect(secondOutput).not.toBe(firstOutput);
} else {
expect(secondOutput).toEqual(firstOutput);
expect(secondOutput).toBe(firstOutput);
}
}
@@ -469,9 +467,9 @@ async function runTest({
const originalAst = await parse(input, formatOptions);
const formattedAst = await parse(output, formatOptions);
if (isAstUnstableTest) {
expect(formattedAst).not.toEqual(originalAst);
expect(formattedAst).not.toStrictEqual(originalAst);
} else {
expect(formattedAst).toEqual(originalAst);
expect(formattedAst).toStrictEqual(originalAst);
}
}
@@ -489,7 +487,7 @@ async function runTest({
formatResult.outputWithCursor.replace(/\n/g, eol),
)
: formatResult.eolVisualizedOutput;
expect(output).toEqual(expected);
expect(output).toBe(expected);
}
}
@@ -499,7 +497,7 @@ async function runTest({
formatOptions,
);
const expected = BOM + formatResult.eolVisualizedOutput;
expect(output).toEqual(expected);
expect(output).toBe(expected);
}
}
@@ -1,3 +1,6 @@
/**
@param {string} text
*/
function visualizeEndOfLine(text) {
return text.replace(/\r\n?|\n/g, (endOfLine) => {
switch (endOfLine) {
+1 -1
View File
@@ -30,7 +30,7 @@ describe("Unit tests for dts files", () => {
/** @type {import("typescript").Diagnostic[]} */
const diagnostics = ts.getPreEmitDiagnostics(program);
expect(diagnostics.map(formatDiagnostic)).toEqual([]);
expect(diagnostics.map(formatDiagnostic)).toStrictEqual([]);
});
});
+4 -4
View File
@@ -217,24 +217,24 @@ test("Commonjs version", () => {
path.join(distDirectory, "index.cjs"),
);
expect(Object.keys(prettierCommonjsVersion).sort()).toEqual(
expect(Object.keys(prettierCommonjsVersion).sort()).toStrictEqual(
Object.keys(prettier)
.filter((key) => key !== "default" && key !== "__internal")
.sort(),
);
expect(typeof prettierCommonjsVersion.format).toBe("function");
expect(Object.keys(prettierCommonjsVersion.doc)).toEqual(
expect(Object.keys(prettierCommonjsVersion.doc)).toStrictEqual(
Object.keys(prettier.doc).filter((key) => key !== "default"),
);
expect(typeof prettierCommonjsVersion.doc.builders.fill).toBe("function");
expect(Object.keys(prettierCommonjsVersion.util)).toEqual(
expect(Object.keys(prettierCommonjsVersion.util)).toStrictEqual(
Object.keys(prettier.util),
);
expect(typeof prettierCommonjsVersion.util.getStringWidth).toBe("function");
expect(Object.keys(prettierCommonjsVersion.__debug).sort()).toEqual(
expect(Object.keys(prettierCommonjsVersion.__debug).sort()).toStrictEqual(
Object.keys(prettier.__debug)
.filter((key) => key !== "mockable")
.sort(),
+26 -26
View File
@@ -112,7 +112,7 @@ describe("--cache option", () => {
"--cache-location",
directoryNameAsCacheFile,
]);
expect(stderr.trim()).toEqual(
expect(stderr.trim()).toStrictEqual(
expect.stringMatching(
/\[error\] Resolved --cache-location '.+' is a directory/,
),
@@ -142,7 +142,7 @@ describe("--cache option", () => {
"metadata",
"*.js",
]);
expect(firstStdout.split("\n")).toEqual(
expect(firstStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\)$/),
@@ -156,7 +156,7 @@ describe("--cache option", () => {
"metadata",
"*.js",
]);
expect(secondStdout.split("\n")).toEqual(
expect(secondStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms \(unchanged\) \(cached\)$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/),
@@ -176,7 +176,7 @@ describe("--cache option", () => {
dir,
cliArguments,
);
expect(firstStdout.split("\n")).toEqual(
expect(firstStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\)$/),
@@ -190,7 +190,7 @@ describe("--cache option", () => {
dir,
cliArguments,
);
expect(secondStdout.split("\n")).toEqual(
expect(secondStdout.split("\n")).toStrictEqual(
// the cache of `b.js` is only available.
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
@@ -211,7 +211,7 @@ describe("--cache option", () => {
dir,
cliArguments,
);
expect(firstStdout.split("\n")).toEqual(
expect(firstStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\)$/),
@@ -226,7 +226,7 @@ describe("--cache option", () => {
dir,
cliArguments,
);
expect(secondStdout.split("\n")).toEqual(
expect(secondStdout.split("\n")).toStrictEqual(
// the cache of `b.js` is only available.
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
@@ -243,7 +243,7 @@ describe("--cache option", () => {
"metadata",
"*.js",
]);
expect(firstStdout.split("\n")).toEqual(
expect(firstStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\)$/),
@@ -259,7 +259,7 @@ describe("--cache option", () => {
"all",
"*.js",
]);
expect(secondStdout.split("\n")).toEqual(
expect(secondStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\)$/),
@@ -282,7 +282,7 @@ describe("--cache option", () => {
"metadata",
"*.js",
]);
expect(secondStdout.split("\n")).toEqual(
expect(secondStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/),
@@ -318,7 +318,7 @@ describe("--cache option", () => {
dir,
cliArguments,
);
expect(thirdStdout.split("\n")).toEqual(
expect(thirdStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/),
@@ -345,7 +345,7 @@ describe("--cache option", () => {
'[error] Unable to write file "a.js":\n' +
"[error] EACCES: permission denied. (mocked error)",
);
expect(firstStdout.split("\n")).toEqual(
expect(firstStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\)$/),
@@ -403,7 +403,7 @@ describe("--cache option", () => {
dir,
cliArguments,
);
expect(firstStdout.split("\n")).toEqual(
expect(firstStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\)$/),
@@ -414,7 +414,7 @@ describe("--cache option", () => {
dir,
cliArguments,
);
expect(secondStdout.split("\n")).toEqual(
expect(secondStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms \(unchanged\) \(cached\)$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/),
@@ -434,7 +434,7 @@ describe("--cache option", () => {
dir,
cliArguments,
);
expect(firstStdout.split("\n")).toEqual(
expect(firstStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\)$/),
@@ -448,7 +448,7 @@ describe("--cache option", () => {
dir,
cliArguments,
);
expect(secondStdout.split("\n")).toEqual(
expect(secondStdout.split("\n")).toStrictEqual(
// the cache of `b.js` is only available.
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
@@ -469,7 +469,7 @@ describe("--cache option", () => {
dir,
cliArguments,
);
expect(firstStdout.split("\n")).toEqual(
expect(firstStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\)$/),
@@ -484,7 +484,7 @@ describe("--cache option", () => {
dir,
cliArguments,
);
expect(secondStdout.split("\n")).toEqual(
expect(secondStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms \(unchanged\) \(cached\)$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/),
@@ -500,7 +500,7 @@ describe("--cache option", () => {
"--write",
"*.js",
]);
expect(firstStdout.split("\n")).toEqual(
expect(firstStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\)$/),
@@ -516,7 +516,7 @@ describe("--cache option", () => {
"all",
"*.js",
]);
expect(secondStdout.split("\n")).toEqual(
expect(secondStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\)$/),
@@ -539,7 +539,7 @@ describe("--cache option", () => {
"content",
"*.js",
]);
expect(secondStdout.split("\n")).toEqual(
expect(secondStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/),
@@ -575,7 +575,7 @@ describe("--cache option", () => {
dir,
cliArguments,
);
expect(thirdStdout.split("\n")).toEqual(
expect(thirdStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/),
@@ -602,7 +602,7 @@ describe("--cache option", () => {
'[error] Unable to write file "a.js":\n' +
"[error] EACCES: permission denied. (mocked error)",
);
expect(firstStdout.split("\n")).toEqual(
expect(firstStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\)$/),
@@ -652,7 +652,7 @@ describe("--cache option", () => {
"a.js",
"*.js",
]);
expect(stderr.trim()).toEqual(
expect(stderr.trim()).toStrictEqual(
expect.stringMatching(/\[error\] '.+' isn't a valid JSON file/),
);
});
@@ -684,7 +684,7 @@ describe("--cache option", () => {
dir,
cliArguments,
);
expect(firstStdout.split("\n")).toEqual(
expect(firstStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\)$/),
@@ -695,7 +695,7 @@ describe("--cache option", () => {
dir,
cliArguments,
);
expect(secondStdout.split("\n")).toEqual(
expect(secondStdout.split("\n")).toStrictEqual(
expect.arrayContaining([
expect.stringMatching(/^a\.js .+ms \(unchanged\) \(cached\)$/),
expect.stringMatching(/^b\.js .+ms \(unchanged\) \(cached\)$/),
+1 -1
View File
@@ -41,7 +41,7 @@ describe("--checks works in CI just as in a non-TTY mode", () => {
});
test("Should have same stdout", async () => {
expect(await result0.stdout).toEqual(await result1.stdout);
expect(await result0.stdout).toBe(await result1.stdout);
});
});
@@ -7,12 +7,12 @@ test("resolves configuration from external files and overrides by extname", asyn
prettier.resolveConfig(
new URL("../cli/config/external-overrides/file.js", import.meta.url),
),
).resolves.toEqual({ tabWidth: 3, semi: false });
).resolves.toStrictEqual({ tabWidth: 3, semi: false });
await expect(
prettier.resolveConfig(
new URL("../cli/config/external-overrides/file.ts", import.meta.url),
),
).resolves.toEqual({ tabWidth: 3, semi: true });
).resolves.toStrictEqual({ tabWidth: 3, semi: true });
});
describe("accepts configuration from --config", () => {
@@ -90,7 +90,7 @@ describe("prints error message when no file found with --find-config-path", () =
});
test("API resolveConfig with no args", async () => {
await expect(prettier.resolveConfig()).resolves.toEqual({});
await expect(prettier.resolveConfig()).resolves.toStrictEqual({});
});
test("API resolveConfig with file arg", async () => {
@@ -225,7 +225,7 @@ test("API resolveConfig overrides excludeFiles", async () => {
test("API resolveConfig removes $schema option", async () => {
const file = new URL("../cli/config/$schema/index.js", import.meta.url);
await expect(prettier.resolveConfig(file)).resolves.toEqual({
await expect(prettier.resolveConfig(file)).resolves.toStrictEqual({
tabWidth: 42,
});
});
@@ -252,7 +252,7 @@ test("API resolveConfig de-references to an external module", async () => {
import.meta.url,
),
),
).resolves.toEqual(config);
).resolves.toStrictEqual(config);
await expect(
prettier.resolveConfig(
new URL(
@@ -260,7 +260,7 @@ test("API resolveConfig de-references to an external module", async () => {
import.meta.url,
),
),
).resolves.toEqual(config);
).resolves.toStrictEqual(config);
await expect(
prettier.resolveConfig(
new URL(
@@ -268,7 +268,7 @@ test("API resolveConfig de-references to an external module", async () => {
import.meta.url,
),
),
).resolves.toEqual(config);
).resolves.toStrictEqual(config);
});
test(".js config file", async () => {
@@ -474,6 +474,6 @@ test("'config' option should accept `URL` and `string`", async () => {
]) {
await expect(
prettier.resolveConfig(file, { config: configFile }),
).resolves.toEqual({ tabWidth: 7 });
).resolves.toStrictEqual({ tabWidth: 7 });
}
});
+1 -1
View File
@@ -71,6 +71,6 @@ describe("doc builders", () => {
},
],
])("%s", (_, doc, expected) => {
expect(doc).toEqual(expected);
expect(doc).toStrictEqual(expected);
});
});
@@ -26,6 +26,6 @@ describe("markAsRoot", () => {
const result = printDocToString(doc, { printWidth: 80, tabWidth: 2 });
expect(result).toBeDefined();
expect(result.formatted).toEqual(expected);
expect(result.formatted).toBe(expected);
});
});
+1 -1
View File
@@ -48,6 +48,6 @@ describe("trim", () => {
const result = printDocToString(doc, { printWidth: 12, tabWidth: 2 });
expect(result).toBeDefined();
expect(result.formatted).toEqual(expected);
expect(result.formatted).toBe(expected);
});
});
@@ -60,6 +60,6 @@ describe("cleanDoc", () => {
])("%s", (_, doc, expected) => {
const result = cleanDoc(doc);
expect(result).toEqual(expected);
expect(result).toStrictEqual(expected);
});
});
+40 -36
View File
@@ -124,13 +124,13 @@ test("API getFileInfo with no args", async () => {
});
test("API getFileInfo with filepath only", async () => {
await expect(prettier.getFileInfo("README")).resolves.toEqual({
await expect(prettier.getFileInfo("README")).resolves.toStrictEqual({
ignored: false,
inferredParser: "markdown",
});
await expect(
prettier.getFileInfo("tsconfig.json", { resolveConfig: false }),
).resolves.toEqual({
).resolves.toStrictEqual({
ignored: false,
inferredParser: "json",
});
@@ -144,19 +144,19 @@ describe("API getFileInfo resolveConfig", () => {
]),
);
test("{resolveConfig: undefined}", async () => {
await expect(prettier.getFileInfo(files.foo)).resolves.toEqual({
await expect(prettier.getFileInfo(files.foo)).resolves.toStrictEqual({
ignored: false,
inferredParser: "foo-parser",
});
await expect(prettier.getFileInfo(files.js)).resolves.toEqual({
await expect(prettier.getFileInfo(files.js)).resolves.toStrictEqual({
ignored: false,
inferredParser: "override-js-parser",
});
await expect(prettier.getFileInfo(files.bar)).resolves.toEqual({
await expect(prettier.getFileInfo(files.bar)).resolves.toStrictEqual({
ignored: false,
inferredParser: null,
});
await expect(prettier.getFileInfo(files.css)).resolves.toEqual({
await expect(prettier.getFileInfo(files.css)).resolves.toStrictEqual({
ignored: false,
inferredParser: "css",
});
@@ -164,25 +164,25 @@ describe("API getFileInfo resolveConfig", () => {
test("{resolveConfig: true}", async () => {
await expect(
prettier.getFileInfo(files.foo, { resolveConfig: true }),
).resolves.toEqual({
).resolves.toStrictEqual({
ignored: false,
inferredParser: "foo-parser",
});
await expect(
prettier.getFileInfo(files.js, { resolveConfig: true }),
).resolves.toEqual({
).resolves.toStrictEqual({
ignored: false,
inferredParser: "override-js-parser",
});
await expect(
prettier.getFileInfo(files.bar, { resolveConfig: true }),
).resolves.toEqual({
).resolves.toStrictEqual({
ignored: false,
inferredParser: null,
});
await expect(
prettier.getFileInfo(files.css, { resolveConfig: true }),
).resolves.toEqual({
).resolves.toStrictEqual({
ignored: false,
inferredParser: "css",
});
@@ -197,11 +197,11 @@ describe("API getFileInfo resolveConfig when no config is present", () => {
]),
);
test("{resolveConfig: undefined}", async () => {
await expect(prettier.getFileInfo(files.foo)).resolves.toEqual({
await expect(prettier.getFileInfo(files.foo)).resolves.toStrictEqual({
ignored: false,
inferredParser: null,
});
await expect(prettier.getFileInfo(files.js)).resolves.toEqual({
await expect(prettier.getFileInfo(files.js)).resolves.toStrictEqual({
ignored: false,
inferredParser: "babel",
});
@@ -209,13 +209,13 @@ describe("API getFileInfo resolveConfig when no config is present", () => {
test("{resolveConfig: true}", async () => {
await expect(
prettier.getFileInfo(files.foo, { resolveConfig: true }),
).resolves.toEqual({
).resolves.toStrictEqual({
ignored: false,
inferredParser: null,
});
await expect(
prettier.getFileInfo(files.js, { resolveConfig: true }),
).resolves.toEqual({
).resolves.toStrictEqual({
ignored: false,
inferredParser: "babel",
});
@@ -232,12 +232,14 @@ test("API getFileInfo with ignorePath", async () => {
import.meta.url,
);
await expect(prettier.getFileInfo(file)).resolves.toEqual({
await expect(prettier.getFileInfo(file)).resolves.toStrictEqual({
ignored: false,
inferredParser: "babel",
});
await expect(prettier.getFileInfo(file, { ignorePath })).resolves.toEqual({
await expect(
prettier.getFileInfo(file, { ignorePath }),
).resolves.toStrictEqual({
ignored: true,
inferredParser: null,
});
@@ -253,12 +255,14 @@ test("API getFileInfo with ignorePath containing relative paths", async () => {
import.meta.url,
);
await expect(prettier.getFileInfo(file)).resolves.toEqual({
await expect(prettier.getFileInfo(file)).resolves.toStrictEqual({
ignored: false,
inferredParser: "babel",
});
await expect(prettier.getFileInfo(file, { ignorePath })).resolves.toEqual({
await expect(
prettier.getFileInfo(file, { ignorePath }),
).resolves.toStrictEqual({
ignored: true,
inferredParser: null,
});
@@ -303,7 +307,7 @@ test("API getFileInfo with withNodeModules", async () => {
"../cli/with-node-modules/node_modules/file.js",
import.meta.url,
);
await expect(prettier.getFileInfo(file)).resolves.toEqual({
await expect(prettier.getFileInfo(file)).resolves.toStrictEqual({
ignored: true,
inferredParser: null,
});
@@ -311,7 +315,7 @@ test("API getFileInfo with withNodeModules", async () => {
prettier.getFileInfo(file, {
withNodeModules: true,
}),
).resolves.toEqual({
).resolves.toStrictEqual({
ignored: false,
inferredParser: "babel",
});
@@ -320,7 +324,7 @@ test("API getFileInfo with withNodeModules", async () => {
test("extracts file-info for a JS file with no extension but a standard shebang", async () => {
await expect(
prettier.getFileInfo("tests/integration/cli/shebang/node-shebang"),
).resolves.toEqual({
).resolves.toStrictEqual({
ignored: false,
inferredParser: "babel",
});
@@ -329,7 +333,7 @@ test("extracts file-info for a JS file with no extension but a standard shebang"
test("extracts file-info for a JS file with no extension but an env-based shebang", async () => {
await expect(
prettier.getFileInfo("tests/integration/cli/shebang/env-node-shebang"),
).resolves.toEqual({
).resolves.toStrictEqual({
ignored: false,
inferredParser: "babel",
});
@@ -338,7 +342,7 @@ test("extracts file-info for a JS file with no extension but an env-based sheban
test("returns null parser for unknown shebang", async () => {
await expect(
prettier.getFileInfo("tests/integration/cli/shebang/nonsense-shebang"),
).resolves.toEqual({
).resolves.toStrictEqual({
ignored: false,
inferredParser: null,
});
@@ -352,7 +356,7 @@ test("API getFileInfo with hand-picked plugins", async () => {
"../plugins/automatic/node_modules/@prettier/plugin-foo/index.js",
),
);
await expect(prettier.getFileInfo(file)).resolves.toEqual({
await expect(prettier.getFileInfo(file)).resolves.toStrictEqual({
ignored: false,
inferredParser: null,
});
@@ -360,7 +364,7 @@ test("API getFileInfo with hand-picked plugins", async () => {
prettier.getFileInfo(file, {
plugins: [pluginPath],
}),
).resolves.toEqual({
).resolves.toStrictEqual({
ignored: false,
inferredParser: "foo",
});
@@ -375,7 +379,7 @@ test("API getFileInfo with ignorePath and resolveConfig should infer parser with
ignorePath,
};
await expect(prettier.getFileInfo(file, options)).resolves.toEqual({
await expect(prettier.getFileInfo(file, options)).resolves.toStrictEqual({
ignored: false,
inferredParser: "parser-for-config-dir",
});
@@ -391,10 +395,10 @@ test("API getFileInfo accepts path or URL", async () => {
const resultByRelativePath = await prettier.getFileInfo(
path.relative(process.cwd(), url.fileURLToPath(fileUrl)),
);
expect(resultByUrl).toEqual(expectedResult);
expect(resultByUrlHref).toEqual(expectedResult);
expect(resultByPath).toEqual(expectedResult);
expect(resultByRelativePath).toEqual(expectedResult);
expect(resultByUrl).toStrictEqual(expectedResult);
expect(resultByUrlHref).toStrictEqual(expectedResult);
expect(resultByPath).toStrictEqual(expectedResult);
expect(resultByRelativePath).toStrictEqual(expectedResult);
});
test("getFileInfo should support `parser` and `plugins` in options", async () => {
@@ -478,10 +482,10 @@ test("API getFileInfo accepts path or URL as ignorePath", async () => {
const resultByPathArray = await prettier.getFileInfo(file, {
ignorePath: [url.fileURLToPath(ignoreFileUrl)],
});
expect(resultByUrl).toEqual(expectedResult);
expect(resultByUrlArray).toEqual(expectedResult);
expect(resultByUrlHref).toEqual(expectedResult);
expect(resultByUrlHrefArray).toEqual(expectedResult);
expect(resultByPath).toEqual(expectedResult);
expect(resultByPathArray).toEqual(expectedResult);
expect(resultByUrl).toStrictEqual(expectedResult);
expect(resultByUrlArray).toStrictEqual(expectedResult);
expect(resultByUrlHref).toStrictEqual(expectedResult);
expect(resultByUrlHrefArray).toStrictEqual(expectedResult);
expect(resultByPath).toStrictEqual(expectedResult);
expect(resultByPathArray).toStrictEqual(expectedResult);
});
+6 -6
View File
@@ -30,20 +30,20 @@ const getUnformattedFiles = async (args) => {
};
test("custom ignore path", async () => {
expect(await getUnformattedFiles(["--ignore-path", ".customignore"])).toEqual(
["ignored-by-gitignore.js", "ignored-by-prettierignore.js"],
);
expect(
await getUnformattedFiles(["--ignore-path", ".customignore"]),
).toStrictEqual(["ignored-by-gitignore.js", "ignored-by-prettierignore.js"]);
});
test("ignore files by .prettierignore and .gitignore by default", async () => {
expect(
await getUnformattedFiles(["--ignore-path", ".non-exists-ignore-file"]),
).toEqual([
).toStrictEqual([
"ignored-by-customignore.js",
"ignored-by-gitignore.js",
"ignored-by-prettierignore.js",
]);
expect(await getUnformattedFiles([])).toEqual([]);
expect(await getUnformattedFiles([])).toStrictEqual([]);
});
describe("ignore file when using --debug-check", () => {
@@ -72,5 +72,5 @@ test("multiple `--ignore-path`", async () => {
"--ignore-path",
".non-exists-ignore-file",
]),
).toEqual(["ignored-by-gitignore.js"]);
).toStrictEqual(["ignored-by-gitignore.js"]);
});
@@ -41,6 +41,6 @@ describe("--list-different works in CI just as in a non-TTY mode", () => {
});
test("Should be the same", async () => {
expect(await result0.stdout).toEqual(await result1.stdout);
expect(await result0.stdout).toBe(await result1.stdout);
});
});
+1 -1
View File
@@ -74,7 +74,7 @@ describe("log-level should not effect information print", () => {
argv: ["--file-info", "any-js-file.js"],
assertOptions: {
stdout(value) {
expect(JSON.parse(value)).toEqual({
expect(JSON.parse(value)).toStrictEqual({
ignored: false,
inferredParser: "babel",
});
+6 -6
View File
@@ -20,7 +20,7 @@ describe("output with --check + unformatted differs when piped", () => {
const result1 = await cli1;
expect(result0.stdout.length).toBeGreaterThan(result1.stdout.length);
expect(result0.write).toEqual(result1.write);
expect(result0.write).toStrictEqual(result1.write);
});
});
@@ -45,9 +45,9 @@ describe("no file diffs with --check + formatted file", () => {
const result0 = await cli0;
const result1 = await cli1;
expect(result0.stdout).not.toEqual(result1.stdout);
expect(result0.stdout).not.toBe(result1.stdout);
expect(result0.stdout.length).toBeGreaterThan(result1.stdout.length);
expect(result0.write).toEqual(result1.write);
expect(result0.write).toStrictEqual(result1.write);
});
});
@@ -73,7 +73,7 @@ describe("output with --list-different + unformatted differs when piped", () =>
const result1 = await cli1;
expect(result0.stdout.length).toBeGreaterThan(result1.stdout.length);
expect(result0.write).toEqual(result1.write);
expect(result0.write).toStrictEqual(result1.write);
});
});
@@ -98,8 +98,8 @@ describe("no file diffs with --list-different + formatted file", () => {
const result0 = await cli0;
const result1 = await cli1;
expect(result0.stdout).not.toEqual(result1.stdout);
expect(result0.stdout).not.toBe(result1.stdout);
expect(result0.stdout.length).toBeGreaterThan(result1.stdout.length);
expect(result0.write).toEqual(result1.write);
expect(result0.write).toStrictEqual(result1.write);
});
});
+1 -1
View File
@@ -17,5 +17,5 @@ test("Plugin instance should not cached", async () => {
],
parser: "baz",
}),
]).toEqual(["1", "2"]);
]).toStrictEqual(["1", "2"]);
});
+3 -3
View File
@@ -15,18 +15,18 @@ test("plugins", async () => {
parser: "uppercase-rocks",
plugins: [pluginUrl],
}),
).resolves.toEqual(expectedOutput);
).resolves.toBe(expectedOutput);
await expect(
prettier.format(input, {
parser: "uppercase-rocks",
plugins: [pluginUrl.href],
}),
).resolves.toEqual(expectedOutput);
).resolves.toBe(expectedOutput);
await expect(
prettier.format(input, {
parser: "uppercase-rocks",
plugins: [url.fileURLToPath(pluginUrl)],
}),
).resolves.toEqual(expectedOutput);
).resolves.toBe(expectedOutput);
});
@@ -23,7 +23,7 @@ test("Should use printer and parser from the same plugin", async () => {
const result = JSON.parse(
await prettier.format("_", { plugins: [pluginA, pluginB], parser: "foo" }),
);
expect(result).toEqual({ parsedBy: "plugin B", printedBy: "plugin B" });
expect(result).toStrictEqual({ parsedBy: "plugin B", printedBy: "plugin B" });
});
test("Should not apply default options from unused plugin", async () => {
@@ -41,5 +41,5 @@ test("Should not apply default options from unused plugin", async () => {
const result = JSON.parse(
await prettier.format("_", { plugins: [pluginA, pluginB], parser: "foo" }),
);
expect(result).toEqual({ tabWidth: 2 });
expect(result).toStrictEqual({ tabWidth: 2 });
});
@@ -3,7 +3,7 @@ import prettier from "../../config/prettier-entry.js";
test("API resolveConfigFile", async () => {
const result = await prettier.resolveConfigFile();
expect(result).toEqual(
expect(result).toBe(
url.fileURLToPath(new URL("../../../prettier.config.js", import.meta.url)),
);
});
@@ -19,7 +19,7 @@ test("API resolveConfigFile accepts path or URL", async () => {
const resultByPath = await prettier.resolveConfigFile(
url.fileURLToPath(fileUrl),
);
expect(resultByUrl).toEqual(expectedConfigFilePath);
expect(resultByUrlHref).toEqual(expectedConfigFilePath);
expect(resultByPath).toEqual(expectedConfigFilePath);
expect(resultByUrl).toBe(expectedConfigFilePath);
expect(resultByUrlHref).toBe(expectedConfigFilePath);
expect(resultByPath).toBe(expectedConfigFilePath);
});
+1 -1
View File
@@ -196,7 +196,7 @@ function runCli(dir, args = [], options = {}) {
} else if (typeof testOptions[name] === "function") {
testOptions[name](value);
} else {
expect(value).toEqual(testOptions[name]);
expect(value).toStrictEqual(testOptions[name]);
}
} else {
snapshot = snapshot ?? {};
+4 -2
View File
@@ -55,7 +55,7 @@ describe("AstPath", () => {
{
const called = [];
path.each(() => called.push(path.getValue()), "children");
expect(called).toEqual(ast.children);
expect(called).toStrictEqual(ast.children);
}
{
@@ -76,7 +76,9 @@ describe("AstPath", () => {
test("AstPath#map()", () => {
const path = new AstPath(ast);
expect(path.map(() => path.getValue(), "children")).toEqual(ast.children);
expect(path.map(() => path.getValue(), "children")).toStrictEqual(
ast.children,
);
{
let result;
+1 -1
View File
@@ -25,5 +25,5 @@ test("massageAst", () => {
expect(result.ignored).toBeUndefined();
expect(result.nonNodeObject).toBe(nonNodeObject);
expect(result.nodeObject).not.toBe(nodeObject);
expect(result.nodeObject).toEqual(nodeObject);
expect(result.nodeObject).toStrictEqual(nodeObject);
});
+1 -1
View File
@@ -22,7 +22,7 @@ test("Should properly trim with cursor", () => {
["123", cursor, "Prettier \t", cursor, "\t \t", hardline],
options,
),
).toEqual({
).toStrictEqual({
formatted: "123Prettier\n",
cursorNodeStart: 3,
cursorNodeText: "Prettier",
+4 -4
View File
@@ -13,7 +13,7 @@ test("traverse", () => {
visited.push(doc);
});
expect(visited).toEqual([doc, doc[0], doc[0][0], doc[0][1]]);
expect(visited).toStrictEqual([doc, doc[0], doc[0][0], doc[0][1]]);
}
{
@@ -24,7 +24,7 @@ test("traverse", () => {
});
// Should skip children
expect(visited).toEqual([doc]);
expect(visited).toStrictEqual([doc]);
}
{
@@ -37,7 +37,7 @@ test("traverse", () => {
});
// Still visiting siblings
expect(visited).toEqual([doc, doc[0], doc[0][0], doc[0][1]]);
expect(visited).toStrictEqual([doc, doc[0], doc[0][0], doc[0][1]]);
}
{
@@ -50,7 +50,7 @@ test("traverse", () => {
});
// Should stop visiting siblings when found
expect(visited).toEqual([doc, doc[0], doc[0][0]]);
expect(visited).toStrictEqual([doc, doc[0], doc[0][0]]);
}
});
+1 -1
View File
@@ -111,7 +111,7 @@ describe("split", () => {
" a a a ",
]) {
it(JSON.stringify(string), () => {
expect(utils.split(string)).toEqual(string.split(/ +/));
expect(utils.split(string)).toStrictEqual(string.split(/ +/));
});
}
});