Skip to content

Commit 1fb4791

Browse files
fix: remove redundant coverage.exclude: lib from vitest.config.ts (#1818)
## PR Checklist - [x] Addresses an existing open issue: fixes #1816 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview Also fixes #1817 while I'm in the area. 💖
1 parent 65315f4 commit 1fb4791

File tree

6 files changed

+36
-30
lines changed

6 files changed

+36
-30
lines changed

src/next/blocks/blockTypeScript.test.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ describe("blockTypeScript", () => {
117117
},
118118
{
119119
"addons": {
120+
"coverage": {
121+
"include": [
122+
"src",
123+
],
124+
},
120125
"exclude": [
121126
"lib",
122127
],
123-
"include": [
124-
"src",
125-
],
126128
},
127129
"block": [Function],
128130
},
@@ -266,12 +268,14 @@ describe("blockTypeScript", () => {
266268
},
267269
{
268270
"addons": {
271+
"coverage": {
272+
"include": [
273+
"src",
274+
],
275+
},
269276
"exclude": [
270277
"lib",
271278
],
272-
"include": [
273-
"src",
274-
],
275279
},
276280
"block": [Function],
277281
},

src/next/blocks/blockTypeScript.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ export * from "./types.js";
8383
},
8484
},
8585
}),
86-
blockVitest({
87-
exclude: ["lib"],
88-
include: ["src"],
89-
}),
86+
blockVitest({ coverage: { include: ["src"] }, exclude: ["lib"] }),
9087
blockVSCode({
9188
debuggers: options.bin
9289
? [

src/next/blocks/blockVitest.test.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ describe("blockVitest", () => {
239239
clearMocks: true,
240240
coverage: {
241241
all: true,
242-
exclude: [],
243-
include: [],
242+
include: undefined,
244243
reporter: ["html", "lcov"],
245244
},
246245
exclude: [, "node_modules"],
@@ -488,8 +487,7 @@ describe("blockVitest", () => {
488487
clearMocks: true,
489488
coverage: {
490489
all: true,
491-
exclude: [],
492-
include: [],
490+
include: undefined,
493491
reporter: ["html", "lcov"],
494492
},
495493
exclude: [, "node_modules"],
@@ -515,10 +513,11 @@ describe("blockVitest", () => {
515513
addons: {
516514
coverage: {
517515
directory: "coverage*",
516+
exclude: ["other"],
518517
flags: "unit",
518+
include: ["src/"],
519519
},
520520
exclude: ["lib/"],
521-
include: ["src/"],
522521
},
523522
options: optionsBase,
524523
});
@@ -755,7 +754,7 @@ describe("blockVitest", () => {
755754
clearMocks: true,
756755
coverage: {
757756
all: true,
758-
exclude: ["lib/"],
757+
exclude: ["other"],
759758
include: ["src/"],
760759
reporter: ["html", "lcov"],
761760
},

src/next/blocks/blockVitest.ts

+20-12
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ export const blockVitest = base.createBlock({
2222
addons: {
2323
coverage: z
2424
.object({
25-
directory: z.string(),
25+
directory: z.string().optional(),
26+
exclude: z.array(z.string()).optional(),
2627
flags: z.string().optional(),
28+
include: z.array(z.string()).optional(),
2729
})
28-
.default({ directory: "coverage" }),
30+
.default({}),
31+
env: z.record(z.string(), z.string()).default({}),
2932
exclude: z.array(z.string()).default([]),
30-
include: z.array(z.string()).default([]),
33+
flags: z.array(z.string()).default([]),
3134
},
3235
migrate() {
3336
return {
@@ -42,14 +45,14 @@ export const blockVitest = base.createBlock({
4245
};
4346
},
4447
produce({ addons }) {
45-
const { coverage, exclude = [], include = [] } = addons;
48+
const { coverage, env, exclude = [], flags } = addons;
49+
const coverageDirectory = coverage.directory ?? "coverage";
4650
const excludeText = JSON.stringify(exclude);
47-
const includeText = JSON.stringify(include);
4851

4952
return {
5053
addons: [
5154
blockCSpell({
52-
ignores: [coverage.directory],
55+
ignores: [coverageDirectory],
5356
}),
5457
blockDevelopmentDocs({
5558
sections: {
@@ -90,7 +93,7 @@ Calls to \`console.log\`, \`console.warn\`, and other console methods will cause
9093
],
9194
},
9295
],
93-
ignores: [coverage.directory, "**/*.snap"],
96+
ignores: [coverageDirectory, "**/*.snap"],
9497
imports: [{ source: "@vitest/eslint-plugin", specifier: "vitest" }],
9598
}),
9699
blockExampleFiles({
@@ -143,7 +146,7 @@ describe("greet", () => {
143146
},
144147
}),
145148
blockGitignore({
146-
ignores: [`/${coverage.directory}`],
149+
ignores: [`/${coverageDirectory}`],
147150
}),
148151
blockGitHubActionsCI({
149152
jobs: [
@@ -152,6 +155,7 @@ describe("greet", () => {
152155
steps: [
153156
{ run: "pnpm run test --coverage" },
154157
{
158+
...(Object.keys(env).length && { env }),
155159
if: "always()",
156160
uses: "codecov/codecov-action@v3",
157161
...(coverage.flags && { with: { flags: coverage.flags } }),
@@ -177,12 +181,12 @@ describe("greet", () => {
177181
"vitest",
178182
),
179183
scripts: {
180-
test: "vitest",
184+
test: `vitest ${flags.join(" ")}`.trim(),
181185
},
182186
},
183187
}),
184188
blockPrettier({
185-
ignores: [`/${coverage.directory}`],
189+
ignores: [`/${coverageDirectory}`],
186190
}),
187191
blockTSup({
188192
entry: ["!src/**/*.test.*"],
@@ -212,8 +216,12 @@ export default defineConfig({
212216
clearMocks: true,
213217
coverage: {
214218
all: true,
215-
exclude: ${excludeText},
216-
include: ${includeText},
219+
${
220+
coverage.exclude?.length
221+
? `exclude: ${JSON.stringify(coverage.exclude)},
222+
`
223+
: ""
224+
}include: ${JSON.stringify(coverage.include)},
217225
reporter: ["html", "lcov"],
218226
},
219227
exclude: [${excludeText.slice(1, excludeText.length - 1)}, "node_modules"],

src/steps/writing/creation/rootFiles.ts

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ export default defineConfig({
136136
clearMocks: true,
137137
coverage: {
138138
all: true,
139-
exclude: ["lib"],
140139
include: ["src"],
141140
reporter: ["html", "lcov"],
142141
},

vitest.config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export default defineConfig({
55
clearMocks: true,
66
coverage: {
77
all: true,
8-
exclude: ["lib"],
98
include: ["src"],
109
reporter: ["html", "lcov"],
1110
},

0 commit comments

Comments
 (0)