Skip to content

Commit 81708cc

Browse files
feat: allow customizing Vitest environment (#2149)
## PR Checklist - [x] Addresses an existing open issue: fixes #2146 - [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 🎁
1 parent 677af76 commit 81708cc

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/blocks/blockVitest.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ describe("blockVitest", () => {
521521
exclude: ["other"],
522522
include: ["src/"],
523523
},
524+
environment: "happy-dom",
524525
exclude: ["lib/"],
525526
flags: ["--typecheck"],
526527
},
@@ -750,6 +751,7 @@ describe("blockVitest", () => {
750751
include: ["src/"],
751752
reporter: ["html", "lcov"],
752753
},
754+
environment: "happy-dom",
753755
exclude: ["lib/","node_modules"],
754756
setupFiles: ["console-fail-test/setup"],
755757
},

src/blocks/blockVitest.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const blockVitest = base.createBlock({
4646
addons: {
4747
actionSteps: z.array(zActionStep).default([]),
4848
coverage: zCoverage.default({}),
49+
environment: z.string().optional(),
4950
exclude: zExclude.default([]),
5051
flags: z.array(z.string()).default([]),
5152
},
@@ -77,7 +78,7 @@ export const blockVitest = base.createBlock({
7778
};
7879
},
7980
produce({ addons }) {
80-
const { actionSteps, coverage, exclude = [] } = addons;
81+
const { actionSteps, coverage, environment, exclude = [] } = addons;
8182
const excludeText = JSON.stringify(
8283
Array.from(new Set(["node_modules", ...exclude])).sort(),
8384
);
@@ -243,7 +244,12 @@ export default defineConfig({
243244
: ""
244245
}include: ${JSON.stringify(coverage.include)},
245246
reporter: ["html", "lcov"],
246-
},
247+
},${
248+
environment
249+
? `
250+
environment: "${environment}",`
251+
: ""
252+
}
247253
exclude: [${excludeText.slice(1, excludeText.length - 1)}],
248254
setupFiles: ["console-fail-test/setup"],
249255
},

0 commit comments

Comments
 (0)