Skip to content

Commit 13aed92

Browse files
fix: don't print .vscode/ files with empty contents
1 parent 7cfa475 commit 13aed92

File tree

2 files changed

+71
-20
lines changed

2 files changed

+71
-20
lines changed

src/blocks/blockVSCode.test.ts

+52-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,58 @@ describe("blockVSCode", () => {
5151
`);
5252
});
5353

54-
test("with addons", () => {
54+
test("with empty addons", () => {
55+
const creation = testBlock(blockVSCode, {
56+
addons: {
57+
debuggers: [],
58+
settings: {},
59+
tasks: [],
60+
},
61+
options: optionsBase,
62+
});
63+
64+
expect(creation).toMatchInlineSnapshot(`
65+
{
66+
"addons": [
67+
{
68+
"addons": {
69+
"hints": [
70+
"> This repository includes a list of suggested VS Code extensions.",
71+
"> It's a good idea to use [VS Code](https://code.visualstudio.com) and accept its suggestion to install them, as they'll help with development.",
72+
],
73+
"sections": {
74+
"Building": {
75+
"innerSections": [],
76+
},
77+
"Testing": {
78+
"innerSections": [
79+
{
80+
"contents": "
81+
This repository includes a [VS Code launch configuration](https://code.visualstudio.com/docs/editor/debugging) for debugging unit tests.
82+
To launch it, open a test file, then run _Debug Current Test File_ from the VS Code Debug panel (or press F5).
83+
",
84+
"heading": "Debugging Tests",
85+
},
86+
],
87+
},
88+
},
89+
},
90+
"block": [Function],
91+
},
92+
],
93+
"files": {
94+
".vscode": {
95+
"extensions.json": undefined,
96+
"launch.json": undefined,
97+
"settings.json": "{"editor.formatOnSave":true,"editor.rulers":[80]}",
98+
"tasks.json": undefined,
99+
},
100+
},
101+
}
102+
`);
103+
});
104+
105+
test("with full addons", () => {
55106
const creation = testBlock(blockVSCode, {
56107
addons: {
57108
debuggers: [

src/blocks/blockVSCode.ts

+19-19
Original file line numberDiff line numberDiff line change
@@ -71,32 +71,32 @@ To launch it, open a test file, then run _Debug Current Test File_ from the VS C
7171
],
7272
files: {
7373
".vscode": {
74-
"extensions.json":
75-
extensions &&
76-
JSON.stringify({
77-
recommendations: [...extensions].sort(),
78-
}),
79-
"launch.json":
80-
debuggers &&
81-
JSON.stringify({
82-
configurations: [...debuggers].sort((a, b) =>
83-
a.name.localeCompare(b.name),
84-
),
85-
version: "0.2.0",
86-
}),
74+
"extensions.json": extensions?.length
75+
? JSON.stringify({
76+
recommendations: [...extensions].sort(),
77+
})
78+
: undefined,
79+
"launch.json": debuggers?.length
80+
? JSON.stringify({
81+
configurations: [...debuggers].sort((a, b) =>
82+
a.name.localeCompare(b.name),
83+
),
84+
version: "0.2.0",
85+
})
86+
: undefined,
8787
"settings.json": JSON.stringify(
8888
sortKeys({
8989
"editor.formatOnSave": true,
9090
"editor.rulers": [80],
9191
...settings,
9292
}),
9393
),
94-
"tasks.json":
95-
tasks &&
96-
JSON.stringify({
97-
tasks: tasks.sort((a, b) => a.detail.localeCompare(b.detail)),
98-
version: "2.0.0",
99-
}),
94+
"tasks.json": tasks?.length
95+
? JSON.stringify({
96+
tasks: tasks.sort((a, b) => a.detail.localeCompare(b.detail)),
97+
version: "2.0.0",
98+
})
99+
: undefined,
100100
},
101101
},
102102
};

0 commit comments

Comments
 (0)