Skip to content

Commit c5bf3ea

Browse files
feat: split out block for console-fail-test
1 parent f693847 commit c5bf3ea

File tree

6 files changed

+112
-39
lines changed

6 files changed

+112
-39
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { testBlock } from "bingo-stratum-testers";
2+
import { describe, expect, test } from "vitest";
3+
4+
import { blockConsoleFailTest } from "./blockConsoleFailTest.js";
5+
import { optionsBase } from "./options.fakes.js";
6+
7+
describe("blockConsoleFailTest", () => {
8+
test("production", () => {
9+
const creation = testBlock(blockConsoleFailTest, {
10+
options: optionsBase,
11+
});
12+
13+
expect(creation).toMatchInlineSnapshot(`
14+
{
15+
"addons": [
16+
{
17+
"addons": {
18+
"sections": {
19+
"Testing": {
20+
"contents": {
21+
"after": [
22+
"
23+
Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs.
24+
Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail.
25+
",
26+
],
27+
},
28+
},
29+
},
30+
},
31+
"block": [Function],
32+
},
33+
{
34+
"addons": {
35+
"properties": {
36+
"devDependencies": {
37+
"console-fail-test": "0.6.1",
38+
},
39+
},
40+
},
41+
"block": [Function],
42+
},
43+
{
44+
"addons": {
45+
"setupFiles": [
46+
"console-fail-test/setup",
47+
],
48+
},
49+
"block": [Function],
50+
},
51+
],
52+
}
53+
`);
54+
});
55+
});

src/blocks/blockConsoleFailTest.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { base } from "../base.js";
2+
import { getPackageDependencies } from "../data/packageData.js";
3+
import { blockPackageJson } from "./blockPackageJson.js";
4+
import { blockVitest } from "./blockVitest.js";
5+
6+
export const blockConsoleFailTest = base.createBlock({
7+
produce() {
8+
return {
9+
addons: [
10+
blockPackageJson({
11+
properties: {
12+
devDependencies: getPackageDependencies("console-fail-test"),
13+
},
14+
}),
15+
blockVitest({
16+
additionalDocs: `
17+
Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs.
18+
Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail.
19+
`,
20+
setupFiles: ["console-fail-test/setup"],
21+
}),
22+
],
23+
};
24+
},
25+
});

src/blocks/blockVitest.test.ts

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@ describe("blockVitest", () => {
4242
\`\`\`shell
4343
pnpm run test --coverage
4444
\`\`\`
45-
46-
Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs.
47-
Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail.
48-
49-
50-
",
45+
",
5146
},
5247
},
5348
},
@@ -179,7 +174,6 @@ describe("blockVitest", () => {
179174
"devDependencies": {
180175
"@vitest/coverage-v8": "4.0.15",
181176
"@vitest/eslint-plugin": "1.5.1",
182-
"console-fail-test": "0.6.1",
183177
"vitest": "4.0.15",
184178
},
185179
"scripts": {
@@ -244,7 +238,6 @@ describe("blockVitest", () => {
244238
reporter: ["html", "lcov"],
245239
},
246240
exclude: ["node_modules"],
247-
setupFiles: ["console-fail-test/setup"],
248241
},
249242
});
250243
",
@@ -287,12 +280,7 @@ describe("blockVitest", () => {
287280
\`\`\`shell
288281
pnpm run test --coverage
289282
\`\`\`
290-
291-
Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs.
292-
Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail.
293-
294-
295-
",
283+
",
296284
},
297285
},
298286
},
@@ -424,7 +412,6 @@ describe("blockVitest", () => {
424412
"devDependencies": {
425413
"@vitest/coverage-v8": "4.0.15",
426414
"@vitest/eslint-plugin": "1.5.1",
427-
"console-fail-test": "0.6.1",
428415
"vitest": "4.0.15",
429416
},
430417
"scripts": {
@@ -519,7 +506,6 @@ describe("blockVitest", () => {
519506
reporter: ["html", "lcov"],
520507
},
521508
exclude: ["node_modules"],
522-
setupFiles: ["console-fail-test/setup"],
523509
},
524510
});
525511
",
@@ -570,12 +556,7 @@ describe("blockVitest", () => {
570556
\`\`\`shell
571557
pnpm run test --coverage
572558
\`\`\`
573-
574-
Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs.
575-
Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail.
576-
577-
578-
",
559+
",
579560
},
580561
},
581562
},
@@ -707,7 +688,6 @@ describe("blockVitest", () => {
707688
"devDependencies": {
708689
"@vitest/coverage-v8": "4.0.15",
709690
"@vitest/eslint-plugin": "1.5.1",
710-
"console-fail-test": "0.6.1",
711691
"vitest": "4.0.15",
712692
},
713693
"scripts": {
@@ -774,7 +754,6 @@ describe("blockVitest", () => {
774754
},
775755
environment: "happy-dom",
776756
exclude: ["lib/","node_modules"],
777-
setupFiles: ["console-fail-test/setup"],
778757
},
779758
});
780759
",
@@ -824,12 +803,7 @@ describe("blockVitest", () => {
824803
\`\`\`shell
825804
pnpm run test --coverage
826805
\`\`\`
827-
828-
Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs.
829-
Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail.
830-
831-
832-
",
806+
",
833807
},
834808
},
835809
},
@@ -961,7 +935,6 @@ describe("blockVitest", () => {
961935
"devDependencies": {
962936
"@vitest/coverage-v8": "4.0.15",
963937
"@vitest/eslint-plugin": "1.5.1",
964-
"console-fail-test": "0.6.1",
965938
"vitest": "4.0.15",
966939
},
967940
"scripts": {
@@ -1027,7 +1000,6 @@ describe("blockVitest", () => {
10271000
reporter: ["html", "lcov"],
10281001
},
10291002
exclude: ["lib/","node_modules"],
1030-
setupFiles: ["console-fail-test/setup"],
10311003
},
10321004
});
10331005
",

src/blocks/blockVitest.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ export const blockVitest = base.createBlock({
6161
},
6262
addons: {
6363
actionSteps: z.array(zActionStep).default([]),
64+
additionalDocs: z.string().default(""),
6465
coverage: zCoverage.default({}),
6566
environment: zEnvironment.optional(),
6667
exclude: zExclude.default([]),
6768
flags: z.array(z.string()).default([]),
69+
setupFiles: z.array(z.string()).default([]),
6870
},
6971
intake({ files, options }) {
7072
return {
@@ -75,7 +77,14 @@ export const blockVitest = base.createBlock({
7577
};
7678
},
7779
produce({ addons }) {
78-
const { actionSteps, coverage, environment, exclude = [] } = addons;
80+
const {
81+
actionSteps,
82+
additionalDocs,
83+
coverage,
84+
environment,
85+
exclude = [],
86+
setupFiles,
87+
} = addons;
7988
const excludeText = JSON.stringify(
8089
Array.from(new Set(["node_modules", ...exclude])).sort(),
8190
);
@@ -101,11 +110,15 @@ Add the \`--coverage\` flag to compute test coverage and place reports in the \`
101110
\`\`\`shell
102111
pnpm run test --coverage
103112
\`\`\`
113+
${
114+
additionalDocs
115+
? `
104116
105-
Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs.
106-
Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail.
107-
117+
${additionalDocs}
108118
119+
`
120+
: ""
121+
}
109122
`,
110123
},
111124
},
@@ -198,7 +211,6 @@ describe(greet, () => {
198211
devDependencies: getPackageDependencies(
199212
"@vitest/coverage-v8",
200213
"@vitest/eslint-plugin",
201-
"console-fail-test",
202214
"vitest",
203215
),
204216
scripts: {
@@ -249,8 +261,12 @@ export default defineConfig({
249261
environment: "${environment}",`
250262
: ""
251263
}
252-
exclude: [${excludeText.slice(1, excludeText.length - 1)}],
253-
setupFiles: ["console-fail-test/setup"],
264+
exclude: [${excludeText.slice(1, excludeText.length - 1)}],${
265+
setupFiles?.length
266+
? `
267+
setupFiles: ${JSON.stringify(setupFiles)},`
268+
: ""
269+
}
254270
},
255271
});
256272
`,

src/blocks/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { blockAllContributors } from "./blockAllContributors.js";
22
import { blockAreTheTypesWrong } from "./blockAreTheTypesWrong.js";
33
import { blockCodecov } from "./blockCodecov.js";
4+
import { blockConsoleFailTest } from "./blockConsoleFailTest.js";
45
import { blockContributingDocs } from "./blockContributingDocs.js";
56
import { blockContributorCovenant } from "./blockContributorCovenant.js";
67
import { blockCSpell } from "./blockCSpell.js";
@@ -51,6 +52,7 @@ export const blocks = {
5152
blockAllContributors,
5253
blockAreTheTypesWrong,
5354
blockCodecov,
55+
blockConsoleFailTest,
5456
blockContributingDocs,
5557
blockContributorCovenant,
5658
blockCSpell,
@@ -101,6 +103,7 @@ export const blocks = {
101103
export { blockAllContributors } from "./blockAllContributors.js";
102104
export { blockAreTheTypesWrong } from "./blockAreTheTypesWrong.js";
103105
export { blockCodecov } from "./blockCodecov.js";
106+
export { blockConsoleFailTest } from "./blockConsoleFailTest.js";
104107
export { blockContributingDocs } from "./blockContributingDocs.js";
105108
export { blockContributorCovenant } from "./blockContributorCovenant.js";
106109
export { blockCSpell } from "./blockCSpell.js";

src/presets/everything.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { base } from "../base.js";
2+
import { blockConsoleFailTest } from "../blocks/blockConsoleFailTest.js";
23
import { blockCSpell } from "../blocks/blockCSpell.js";
34
import { blockESLintComments } from "../blocks/blockESLintComments.js";
45
import { blockESLintJSDoc } from "../blocks/blockESLintJSDoc.js";
@@ -30,6 +31,7 @@ export const presetEverything = base.createPreset({
3031
},
3132
blocks: [
3233
...presetCommon.blocks,
34+
blockConsoleFailTest,
3335
blockCSpell,
3436
blockESLintComments,
3537
blockESLintJSDoc,

0 commit comments

Comments
 (0)