Skip to content

Commit 3f350c8

Browse files
committed
Additional tests, test all config types
1 parent f323ebc commit 3f350c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+433
-48
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
</p>
5656

5757
> [!IMPORTANT]
58-
> **Extension Migration:** This extension is being moved from `esbenp.prettier-vscode` to [`prettier.prettier-vscode`](https://marketplace.visualstudio.com/items?itemName=prettier.prettier-vscode). Version 12+ is only published to the new for now as it is a major change. Once it is stable, we will publish v12 to both extensions and deprecate the `esbenp.prettier-vscode` extension. **Version 12.x is currently not stable, use with caution in production environments.**
58+
> **Extension Migration:** This extension is being moved from `esbenp.prettier-vscode` to [`prettier.prettier-vscode`](https://marketplace.visualstudio.com/items?itemName=prettier.prettier-vscode). Version 12+ is only published to the new for now as it is a major change. Once it is stable, we will publish v12 to both extensions and deprecate the `esbenp.prettier-vscode` extension. **Version 12.x is currently not stable, use with caution in production environments.**
5959
6060
## Installation
6161

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
},
114114
"dependencies": {
115115
"find-up": "5.0.0",
116-
"prettier": "3.7.1",
116+
"prettier": "3.7.3",
117117
"resolve": "1.22.11",
118118
"semver": "7.7.3",
119119
"vscode-nls": "5.2.0"

src/test/suite/config.test.ts

Lines changed: 119 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,152 @@ describe("Test configurations", () => {
2222
before(() => moveRootPrettierRC());
2323
after(() => putBackPrettierRC());
2424

25+
// .prettierrc (JSON without extension)
2526
it(
2627
"it uses config from .prettierrc file and does not inherit VS Code settings ",
27-
/* cspell: disable-next-line */
2828
// Use retry for first test as extension may need time after root .prettierrc is moved
2929
testConfig("rcfile/test.js", "rcfile/test.result.js", true),
3030
);
31+
32+
// .prettierrc.json
3133
it(
32-
"it uses config from prettier.config.js file ",
33-
/* cspell: disable-next-line */
34-
testConfig("jsconfigfile/test.js", "jsconfigfile/test.result.js"),
34+
"it uses config from .prettierrc.json file",
35+
testConfig("jsonfile/test.js", "jsonfile/test.result.js"),
36+
);
37+
38+
// .prettierrc.json5
39+
it(
40+
"it uses config from .prettierrc.json5 file",
41+
testConfig("json5file/test.js", "json5file/test.result.js"),
42+
);
43+
44+
// .prettierrc.yaml
45+
it(
46+
"it uses config from .prettierrc.yaml file",
47+
testConfig("yamlfile/test.js", "yamlfile/test.result.js"),
3548
);
49+
50+
// .prettierrc.yml
51+
it(
52+
"it uses config from .prettierrc.yml file",
53+
testConfig("ymlfile/test.js", "ymlfile/test.result.js"),
54+
);
55+
56+
// .prettierrc.toml
57+
it(
58+
"it uses config from .prettierrc.toml file",
59+
testConfig("tomlfile/test.js", "tomlfile/test.result.js"),
60+
);
61+
62+
// .prettierrc.js (CommonJS)
3663
it(
37-
"it uses config from .prettierrc.js file ",
38-
/* cspell: disable-next-line */
64+
"it uses config from .prettierrc.js file",
3965
testConfig("jsfile/test.js", "jsfile/test.result.js"),
4066
);
67+
68+
// .prettierrc.cjs (CommonJS explicit)
69+
it(
70+
"it uses config from .prettierrc.cjs file",
71+
testConfig("cjsfile/test.js", "cjsfile/test.result.js"),
72+
);
73+
74+
// .prettierrc.mjs (ESM)
75+
it(
76+
"it uses config from .prettierrc.mjs file",
77+
testConfig("mjsfile/test.js", "mjsfile/test.result.js"),
78+
);
79+
80+
// prettier.config.js (CommonJS)
81+
it(
82+
"it uses config from prettier.config.js file",
83+
testConfig("jsconfigfile/test.js", "jsconfigfile/test.result.js"),
84+
);
85+
86+
// prettier.config.cjs (CommonJS explicit)
87+
it(
88+
"it uses config from prettier.config.cjs file",
89+
testConfig("cjsconfigfile/test.js", "cjsconfigfile/test.result.js"),
90+
);
91+
92+
// prettier.config.mjs (ESM)
93+
it(
94+
"it uses config from prettier.config.mjs file",
95+
testConfig("mjsconfigfile/test.js", "mjsconfigfile/test.result.js"),
96+
);
97+
98+
// package.json with "prettier" key
99+
it(
100+
"it uses config from package.json prettier key",
101+
testConfig("pkgjson/test.js", "pkgjson/test.result.js"),
102+
);
103+
104+
// .prettierrc.js for handlebars files
41105
it(
42106
"it uses config from .prettierrc.js file for hbs files",
43-
/* cspell: disable-next-line */
44107
testConfig("hbsfile/test.hbs", "hbsfile/test.result.hbs"),
45108
);
109+
110+
// .editorconfig
46111
it(
47-
"it uses config from .editorconfig file ",
112+
"it uses config from .editorconfig file",
48113
testConfig("editorconfig/test.js", "editorconfig/test.result.js"),
49114
);
115+
116+
// VS Code settings
50117
it(
51-
"it uses config from vscode settings ",
52-
/* cspell: disable-next-line */
118+
"it uses config from vscode settings",
53119
testConfig("vscodeconfig/test.js", "vscodeconfig/test.result.js"),
54120
);
121+
122+
// VS Code settings with language overridables
55123
it(
56-
"it uses config from vscode settings with language overridables ",
57-
/* cspell: disable-next-line */
124+
"it uses config from vscode settings with language overridables",
58125
testConfig(
59126
"vscodeconfig-language-overridable/test.ts",
60127
"vscodeconfig-language-overridable/test.result.ts",
61128
),
62129
);
130+
131+
// Custom file extension
63132
it(
64-
"it formats custom file extension ",
65-
/* cspell: disable-next-line */
133+
"it formats custom file extension",
66134
testConfig("customextension/test.abc", "customextension/test.result.abc"),
67135
);
136+
137+
// prettier.config.ts (TypeScript) - requires Prettier >= 3.5.0
138+
// This fixture has its own package.json with local Prettier for TS config support
139+
it(
140+
"it uses config from prettier.config.ts file",
141+
testConfig("tsconfigfile/test.js", "tsconfigfile/test.result.js"),
142+
);
143+
144+
// .prettierrc.ts (TypeScript ESM) - requires Prettier >= 3.5.0
145+
it(
146+
"it uses config from .prettierrc.ts file",
147+
testConfig("prettierrctsfile/test.js", "prettierrctsfile/test.result.js"),
148+
);
149+
150+
// .prettierrc.cts (TypeScript CommonJS) - requires Prettier >= 3.5.0
151+
it(
152+
"it uses config from .prettierrc.cts file",
153+
testConfig("prettierrccts/test.js", "prettierrccts/test.result.js"),
154+
);
155+
156+
// .prettierrc.mts (TypeScript ESM explicit) - requires Prettier >= 3.5.0
157+
it(
158+
"it uses config from .prettierrc.mts file",
159+
testConfig("prettierrcmts/test.js", "prettierrcmts/test.result.js"),
160+
);
161+
162+
// prettier.config.cts (TypeScript CommonJS) - requires Prettier >= 3.5.0
163+
it(
164+
"it uses config from prettier.config.cts file",
165+
testConfig("configcts/test.js", "configcts/test.result.js"),
166+
);
167+
168+
// prettier.config.mts (TypeScript ESM explicit) - requires Prettier >= 3.5.0
169+
it(
170+
"it uses config from prettier.config.mts file",
171+
testConfig("configmts/test.js", "configmts/test.result.js"),
172+
);
68173
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as assert from "node:assert";
2+
import { format, getText } from "./format.test";
3+
4+
/**
5+
* Test for GitHub issue https://github.com/prettier/prettier/issues/18353
6+
*
7+
* This tests that when a monorepo subfolder has its own Prettier installation
8+
* and plugins, the plugin resolution works correctly. In Prettier 3.7.0+,
9+
* there was a regression where plugins would be resolved from the wrong
10+
* directory, causing errors like:
11+
*
12+
* "Cannot find package 'prettier-plugin-xxx' imported from /path/to/root/noop.js"
13+
*/
14+
describe("Test monorepo subfolder plugin resolution (issue #18353)", () => {
15+
// This test verifies the subfolder works when opened as its own workspace
16+
it("formats with plugins in a monorepo subfolder (opened directly)", async () => {
17+
const { actual } = await format(
18+
"subfolder",
19+
"index.xml",
20+
/* shouldRetry */ true,
21+
);
22+
const expected = await getText("subfolder", "index.result.xml");
23+
assert.equal(actual, expected);
24+
});
25+
26+
// This test reproduces the actual issue - when the parent folder is opened
27+
// and we try to format a file in a nested subfolder that has its own Prettier
28+
it("formats with plugins when opened from parent folder", async () => {
29+
const { actual } = await format(
30+
"monorepo-subfolder",
31+
"subfolder/index.xml",
32+
/* shouldRetry */ true,
33+
);
34+
const expected = await getText(
35+
"monorepo-subfolder",
36+
"subfolder/index.result.xml",
37+
);
38+
assert.equal(actual, expected);
39+
});
40+
});

src/test/suite/ts-config.test.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// CommonJS config file
2+
module.exports = {
3+
tabWidth: 5
4+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function foo() {
2+
console.log("test")
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function foo() {
2+
console.log("test");
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// CommonJS config file
2+
module.exports = {
3+
tabWidth: 5
4+
};

0 commit comments

Comments
 (0)