Skip to content

Commit

Permalink
fix: remove redundant coverage.exclude: lib from vitest.config.ts (#1818
Browse files Browse the repository at this point in the history
)

## 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.

💖
  • Loading branch information
JoshuaKGoldberg authored Dec 31, 2024
1 parent 65315f4 commit 1fb4791
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 30 deletions.
16 changes: 10 additions & 6 deletions src/next/blocks/blockTypeScript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ describe("blockTypeScript", () => {
},
{
"addons": {
"coverage": {
"include": [
"src",
],
},
"exclude": [
"lib",
],
"include": [
"src",
],
},
"block": [Function],
},
Expand Down Expand Up @@ -266,12 +268,14 @@ describe("blockTypeScript", () => {
},
{
"addons": {
"coverage": {
"include": [
"src",
],
},
"exclude": [
"lib",
],
"include": [
"src",
],
},
"block": [Function],
},
Expand Down
5 changes: 1 addition & 4 deletions src/next/blocks/blockTypeScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ export * from "./types.js";
},
},
}),
blockVitest({
exclude: ["lib"],
include: ["src"],
}),
blockVitest({ coverage: { include: ["src"] }, exclude: ["lib"] }),
blockVSCode({
debuggers: options.bin
? [
Expand Down
11 changes: 5 additions & 6 deletions src/next/blocks/blockVitest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ describe("blockVitest", () => {
clearMocks: true,
coverage: {
all: true,
exclude: [],
include: [],
include: undefined,
reporter: ["html", "lcov"],
},
exclude: [, "node_modules"],
Expand Down Expand Up @@ -488,8 +487,7 @@ describe("blockVitest", () => {
clearMocks: true,
coverage: {
all: true,
exclude: [],
include: [],
include: undefined,
reporter: ["html", "lcov"],
},
exclude: [, "node_modules"],
Expand All @@ -515,10 +513,11 @@ describe("blockVitest", () => {
addons: {
coverage: {
directory: "coverage*",
exclude: ["other"],
flags: "unit",
include: ["src/"],
},
exclude: ["lib/"],
include: ["src/"],
},
options: optionsBase,
});
Expand Down Expand Up @@ -755,7 +754,7 @@ describe("blockVitest", () => {
clearMocks: true,
coverage: {
all: true,
exclude: ["lib/"],
exclude: ["other"],
include: ["src/"],
reporter: ["html", "lcov"],
},
Expand Down
32 changes: 20 additions & 12 deletions src/next/blocks/blockVitest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ export const blockVitest = base.createBlock({
addons: {
coverage: z
.object({
directory: z.string(),
directory: z.string().optional(),
exclude: z.array(z.string()).optional(),
flags: z.string().optional(),
include: z.array(z.string()).optional(),
})
.default({ directory: "coverage" }),
.default({}),
env: z.record(z.string(), z.string()).default({}),
exclude: z.array(z.string()).default([]),
include: z.array(z.string()).default([]),
flags: z.array(z.string()).default([]),
},
migrate() {
return {
Expand All @@ -42,14 +45,14 @@ export const blockVitest = base.createBlock({
};
},
produce({ addons }) {
const { coverage, exclude = [], include = [] } = addons;
const { coverage, env, exclude = [], flags } = addons;
const coverageDirectory = coverage.directory ?? "coverage";
const excludeText = JSON.stringify(exclude);
const includeText = JSON.stringify(include);

return {
addons: [
blockCSpell({
ignores: [coverage.directory],
ignores: [coverageDirectory],
}),
blockDevelopmentDocs({
sections: {
Expand Down Expand Up @@ -90,7 +93,7 @@ Calls to \`console.log\`, \`console.warn\`, and other console methods will cause
],
},
],
ignores: [coverage.directory, "**/*.snap"],
ignores: [coverageDirectory, "**/*.snap"],
imports: [{ source: "@vitest/eslint-plugin", specifier: "vitest" }],
}),
blockExampleFiles({
Expand Down Expand Up @@ -143,7 +146,7 @@ describe("greet", () => {
},
}),
blockGitignore({
ignores: [`/${coverage.directory}`],
ignores: [`/${coverageDirectory}`],
}),
blockGitHubActionsCI({
jobs: [
Expand All @@ -152,6 +155,7 @@ describe("greet", () => {
steps: [
{ run: "pnpm run test --coverage" },
{
...(Object.keys(env).length && { env }),
if: "always()",
uses: "codecov/codecov-action@v3",
...(coverage.flags && { with: { flags: coverage.flags } }),
Expand All @@ -177,12 +181,12 @@ describe("greet", () => {
"vitest",
),
scripts: {
test: "vitest",
test: `vitest ${flags.join(" ")}`.trim(),
},
},
}),
blockPrettier({
ignores: [`/${coverage.directory}`],
ignores: [`/${coverageDirectory}`],
}),
blockTSup({
entry: ["!src/**/*.test.*"],
Expand Down Expand Up @@ -212,8 +216,12 @@ export default defineConfig({
clearMocks: true,
coverage: {
all: true,
exclude: ${excludeText},
include: ${includeText},
${
coverage.exclude?.length
? `exclude: ${JSON.stringify(coverage.exclude)},
`
: ""
}include: ${JSON.stringify(coverage.include)},
reporter: ["html", "lcov"],
},
exclude: [${excludeText.slice(1, excludeText.length - 1)}, "node_modules"],
Expand Down
1 change: 0 additions & 1 deletion src/steps/writing/creation/rootFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ export default defineConfig({
clearMocks: true,
coverage: {
all: true,
exclude: ["lib"],
include: ["src"],
reporter: ["html", "lcov"],
},
Expand Down
1 change: 0 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export default defineConfig({
clearMocks: true,
coverage: {
all: true,
exclude: ["lib"],
include: ["src"],
reporter: ["html", "lcov"],
},
Expand Down

0 comments on commit 1fb4791

Please sign in to comment.