Fix expect.resolves assert (Part 2) (#8756)

This commit is contained in:
fisker Cheung authored and GitHub committed 2020-07-14 21:53:45 +08:00
1 parent 4dade8b06d
commit 8a635f5bdf
5 files changed
+72 -35

No files matched your search

+6
View File
@@ -78,6 +78,12 @@ overrides:
- "{tests,tests_config,tests_integration}/**/*.js"
env:
jest: true
plugins:
- jest
rules:
jest/valid-expect:
- error
- alwaysAwait: true
- files:
- tests/**/*.js
rules:
+1
View File
@@ -99,6 +99,7 @@
"eslint-config-prettier": "6.11.0",
"eslint-formatter-friendly": "7.0.0",
"eslint-plugin-import": "2.22.0",
"eslint-plugin-jest": "23.18.0",
"eslint-plugin-react": "7.20.3",
"eslint-plugin-unicorn": "20.1.0",
"execa": "4.0.3",
@@ -232,9 +232,9 @@ test("API clearConfigCache", () => {
expect(() => prettier.clearConfigCache()).not.toThrowError();
});
test("API resolveConfig overrides work with dotfiles", () => {
test("API resolveConfig overrides work with dotfiles", async () => {
const folder = path.join(__dirname, "../cli/config/dot-overrides");
return expect(
await expect(
prettier.resolveConfig(path.join(folder, ".foo.json"))
).resolves.toMatchObject({
tabWidth: 4,
+31 -31
View File
@@ -112,8 +112,8 @@ describe("extracts file-info with inferredParser=foo when a plugin is hand-picke
});
});
test("API getFileInfo with no args", () => {
return expect(prettier.getFileInfo()).rejects.toThrow(
test("API getFileInfo with no args", async () => {
await expect(prettier.getFileInfo()).rejects.toThrow(
new TypeError("expect `filePath` to be a string, got `undefined`")
);
});
@@ -124,8 +124,8 @@ test("API getFileInfo.sync with no args", () => {
);
});
test("API getFileInfo with filepath only", () => {
expect(prettier.getFileInfo("README")).resolves.toMatchObject({
test("API getFileInfo with filepath only", async () => {
await expect(prettier.getFileInfo("README")).resolves.toMatchObject({
ignored: false,
inferredParser: "markdown",
});
@@ -147,44 +147,44 @@ describe("API getFileInfo resolveConfig", () => {
),
])
);
test("{resolveConfig: undefined}", () => {
expect(prettier.getFileInfo(files.foo)).resolves.toMatchObject({
test("{resolveConfig: undefined}", async () => {
await expect(prettier.getFileInfo(files.foo)).resolves.toMatchObject({
ignored: false,
inferredParser: null,
});
expect(prettier.getFileInfo(files.js)).resolves.toMatchObject({
await expect(prettier.getFileInfo(files.js)).resolves.toMatchObject({
ignored: false,
inferredParser: "babel",
});
expect(prettier.getFileInfo(files.bar)).resolves.toMatchObject({
await expect(prettier.getFileInfo(files.bar)).resolves.toMatchObject({
ignored: false,
inferredParser: null,
});
expect(prettier.getFileInfo(files.css)).resolves.toMatchObject({
await expect(prettier.getFileInfo(files.css)).resolves.toMatchObject({
ignored: false,
inferredParser: "css",
});
});
test("{resolveConfig: true}", () => {
expect(
test("{resolveConfig: true}", async () => {
await expect(
prettier.getFileInfo(files.foo, { resolveConfig: true })
).resolves.toMatchObject({
ignored: false,
inferredParser: "foo-parser",
});
expect(
await expect(
prettier.getFileInfo(files.js, { resolveConfig: true })
).resolves.toMatchObject({
ignored: false,
inferredParser: "override-js-parser",
});
expect(
await expect(
prettier.getFileInfo(files.bar, { resolveConfig: true })
).resolves.toMatchObject({
ignored: false,
inferredParser: null,
});
expect(
await expect(
prettier.getFileInfo(files.css, { resolveConfig: true })
).resolves.toMatchObject({
ignored: false,
@@ -252,24 +252,24 @@ describe("API getFileInfo resolveConfig when no config is present", () => {
path.resolve(path.join(__dirname, `../cli/non-exists-dir/file.${ext}`)),
])
);
test("{resolveConfig: undefined}", () => {
expect(prettier.getFileInfo(files.foo)).resolves.toMatchObject({
test("{resolveConfig: undefined}", async () => {
await expect(prettier.getFileInfo(files.foo)).resolves.toMatchObject({
ignored: false,
inferredParser: null,
});
expect(prettier.getFileInfo(files.js)).resolves.toMatchObject({
await expect(prettier.getFileInfo(files.js)).resolves.toMatchObject({
ignored: false,
inferredParser: "babel",
});
});
test("{resolveConfig: true}", () => {
expect(
test("{resolveConfig: true}", async () => {
await expect(
prettier.getFileInfo(files.foo, { resolveConfig: true })
).resolves.toMatchObject({
ignored: false,
inferredParser: null,
});
expect(
await expect(
prettier.getFileInfo(files.js, { resolveConfig: true })
).resolves.toMatchObject({
ignored: false,
@@ -404,15 +404,15 @@ describe("API getFileInfo.sync with ignorePath", () => {
});
});
test("API getFileInfo with withNodeModules", () => {
test("API getFileInfo with withNodeModules", async () => {
const file = path.resolve(
path.join(__dirname, "../cli/with-node-modules/node_modules/file.js")
);
expect(prettier.getFileInfo(file)).resolves.toMatchObject({
await expect(prettier.getFileInfo(file)).resolves.toMatchObject({
ignored: true,
inferredParser: null,
});
expect(
await expect(
prettier.getFileInfo(file, {
withNodeModules: true,
})
@@ -449,16 +449,16 @@ describe("returns null parser for unknown shebang", () => {
});
});
test("API getFileInfo with plugins loaded using pluginSearchDir", () => {
test("API getFileInfo with plugins loaded using pluginSearchDir", async () => {
const file = "file.foo";
const pluginsPath = path.resolve(
path.join(__dirname, "../plugins/automatic")
);
expect(prettier.getFileInfo(file)).resolves.toMatchObject({
await expect(prettier.getFileInfo(file)).resolves.toMatchObject({
ignored: false,
inferredParser: null,
});
expect(
await expect(
prettier.getFileInfo(file, {
pluginSearchDirs: [pluginsPath],
})
@@ -468,7 +468,7 @@ test("API getFileInfo with plugins loaded using pluginSearchDir", () => {
});
});
test("API getFileInfo with hand-picked plugins", () => {
test("API getFileInfo with hand-picked plugins", async () => {
const file = "file.foo";
const pluginPath = path.resolve(
path.join(
@@ -476,11 +476,11 @@ test("API getFileInfo with hand-picked plugins", () => {
"../plugins/automatic/node_modules/@prettier/plugin-foo"
)
);
expect(prettier.getFileInfo(file)).resolves.toMatchObject({
await expect(prettier.getFileInfo(file)).resolves.toMatchObject({
ignored: false,
inferredParser: null,
});
expect(
await expect(
prettier.getFileInfo(file, {
plugins: [pluginPath],
})
@@ -490,7 +490,7 @@ test("API getFileInfo with hand-picked plugins", () => {
});
});
test("API getFileInfo with ignorePath and resolveConfig should infer parser with correct filepath", () => {
test("API getFileInfo with ignorePath and resolveConfig should infer parser with correct filepath", async () => {
const dir = path.join(__dirname, "../cli/ignore-and-config/");
const filePath = path.join(dir, "config-dir/foo");
const ignorePath = path.join(dir, "ignore-path-dir/.prettierignore");
@@ -499,7 +499,7 @@ test("API getFileInfo with ignorePath and resolveConfig should infer parser with
ignorePath,
};
expect(prettier.getFileInfo(filePath, options)).resolves.toMatchObject({
await expect(prettier.getFileInfo(filePath, options)).resolves.toMatchObject({
ignored: false,
inferredParser: "parser-for-config-dir",
});
+32 -2
View File
@@ -1242,7 +1242,7 @@
"@types/istanbul-lib-coverage" "*"
"@types/istanbul-lib-report" "*"
"@types/json-schema@^7.0.4":
"@types/json-schema@^7.0.3", "@types/json-schema@^7.0.4":
version "7.0.5"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.5.tgz#dcce4430e64b443ba8945f0290fb564ad5bac6dd"
integrity sha512-7+2BITlgjgDhH0vvwZU/HZJVyk+2XUlvxXe8dFMedNX/aMkaOq++rMAFXc0tM7ij15QaWlbdQASBR9dihi+bDQ==
@@ -1301,11 +1301,34 @@
dependencies:
"@types/yargs-parser" "*"
"@typescript-eslint/experimental-utils@^2.5.0":
version "2.34.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.34.0.tgz#d3524b644cdb40eebceca67f8cf3e4cc9c8f980f"
integrity sha512-eS6FTkq+wuMJ+sgtuNTtcqavWXqsflWcfBnlYhg/nS4aZ1leewkXGbvBhaapn1q6qf4M71bsR1tez5JTRMuqwA==
dependencies:
"@types/json-schema" "^7.0.3"
"@typescript-eslint/typescript-estree" "2.34.0"
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"
"@typescript-eslint/types@3.6.1":
version "3.6.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-3.6.1.tgz#87600fe79a1874235d3cc1cf5c7e1a12eea69eee"
integrity sha512-NPxd5yXG63gx57WDTW1rp0cF3XlNuuFFB5G+Kc48zZ+51ZnQn9yjDEsjTPQ+aWM+V+Z0I4kuTFKjKvgcT1F7xQ==
"@typescript-eslint/typescript-estree@2.34.0":
version "2.34.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.34.0.tgz#14aeb6353b39ef0732cc7f1b8285294937cf37d5"
integrity sha512-OMAr+nJWKdlVM9LOqCqh3pQQPwxHAN7Du8DR6dmwCrAmxtiXQnhHJ6tBNtf+cggqfo51SG/FCwnKhXCIM7hnVg==
dependencies:
debug "^4.1.1"
eslint-visitor-keys "^1.1.0"
glob "^7.1.6"
is-glob "^4.0.1"
lodash "^4.17.15"
semver "^7.3.2"
tsutils "^3.17.1"
"@typescript-eslint/typescript-estree@3.6.1":
version "3.6.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.6.1.tgz#a5c91fcc5497cce7922ff86bc37d5e5891dcdefa"
@@ -3245,6 +3268,13 @@ eslint-plugin-import@2.22.0:
resolve "^1.17.0"
tsconfig-paths "^3.9.0"
eslint-plugin-jest@23.18.0:
version "23.18.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-23.18.0.tgz#4813eacb181820ed13c5505f400956d176b25af8"
integrity sha512-wLPM/Rm1SGhxrFQ2TKM/BYsYPhn7ch6ZEK92S2o/vGkAAnDXM0I4nTIo745RIX+VlCRMFgBuJEax6XfTHMdeKg==
dependencies:
"@typescript-eslint/experimental-utils" "^2.5.0"
eslint-plugin-react@7.20.3:
version "7.20.3"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.20.3.tgz#0590525e7eb83890ce71f73c2cf836284ad8c2f1"
@@ -3289,7 +3319,7 @@ eslint-scope@^4.0.3:
esrecurse "^4.1.0"
estraverse "^4.1.1"
eslint-scope@^5.1.0:
eslint-scope@^5.0.0, eslint-scope@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.0.tgz#d0f971dfe59c69e0cada684b23d49dbf82600ce5"
integrity sha512-iiGRvtxWqgtx5m8EyQUJihBloE4EnYeGE/bz1wSPwJE6tZuJUtHlhqDM4Xj2ukE8Dyy1+HCZ4hE0fzIVMzb58w==