Skip to content

Commit 2984cef

Browse files
Copilotntotten
andauthored
Add test for .prettierrc with string reference to ESM config package (#3868)
* Initial plan * Add test fixture for string ESM config issue Co-authored-by: ntotten <[email protected]> * Update test comment to address code review Co-authored-by: ntotten <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: ntotten <[email protected]>
1 parent c5f79f4 commit 2984cef

File tree

8 files changed

+61
-0
lines changed

8 files changed

+61
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as assert from "assert";
2+
import { format, getText } from "./formatTestUtils.js";
3+
import { ensureExtensionActivated } from "./testUtils.js";
4+
5+
describe("String ESM Config Support", () => {
6+
before(async () => {
7+
await ensureExtensionActivated();
8+
});
9+
10+
// This test validates that .prettierrc with a string reference to an ESM config package works
11+
// Reproduces issue where extension fails with "Invalid prettier configuration file detected"
12+
// when .prettierrc contains a string pointing to an ESM prettier config package
13+
it("it formats with .prettierrc containing string reference to ESM config package", async () => {
14+
const { actual } = await format("string-esm-config", "test.js");
15+
const expected = await getText("string-esm-config", "test.result.js");
16+
assert.equal(actual, expected);
17+
});
18+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"test-prettier-config-esm"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "string-esm-config",
3+
"version": "1.0.0",
4+
"description": "Test folder for .prettierrc with string reference to ESM config package",
5+
"private": true,
6+
"type": "module",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"author": "Prettier",
11+
"license": "MIT",
12+
"devDependencies": {
13+
"prettier": "^3.4.2",
14+
"test-prettier-config-esm": "file:./test-prettier-config-esm"
15+
}
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// ESM Prettier config package
2+
const config = {
3+
semi: true,
4+
singleQuote: false,
5+
tabWidth: 2,
6+
trailingComma: "es5",
7+
};
8+
9+
export default config;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "test-prettier-config-esm",
3+
"version": "1.0.0",
4+
"description": "ESM Prettier config package for testing",
5+
"type": "module",
6+
"main": "index.js",
7+
"exports": {
8+
".": "./index.js"
9+
},
10+
"author": "Prettier",
11+
"license": "MIT"
12+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const foo={bar:1,baz:2};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const foo = { bar: 1, baz: 2 };

test-fixtures/test.code-workspace

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
{
5858
"path": "esm-plugin-import"
5959
},
60+
{
61+
"path": "string-esm-config"
62+
},
6063
{
6164
"path": "monorepo-subfolder/subfolder"
6265
},

0 commit comments

Comments
 (0)