From c5bf3eaeb53f4f4bed2453473721e1251e146f58 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 4 Dec 2025 15:55:06 -0500 Subject: [PATCH 1/3] feat: split out block for console-fail-test --- src/blocks/blockConsoleFailTest.test.ts | 55 +++++++++++++++++++++++++ src/blocks/blockConsoleFailTest.ts | 25 +++++++++++ src/blocks/blockVitest.test.ts | 36 ++-------------- src/blocks/blockVitest.ts | 30 ++++++++++---- src/blocks/index.ts | 3 ++ src/presets/everything.ts | 2 + 6 files changed, 112 insertions(+), 39 deletions(-) create mode 100644 src/blocks/blockConsoleFailTest.test.ts create mode 100644 src/blocks/blockConsoleFailTest.ts diff --git a/src/blocks/blockConsoleFailTest.test.ts b/src/blocks/blockConsoleFailTest.test.ts new file mode 100644 index 000000000..1153c4edd --- /dev/null +++ b/src/blocks/blockConsoleFailTest.test.ts @@ -0,0 +1,55 @@ +import { testBlock } from "bingo-stratum-testers"; +import { describe, expect, test } from "vitest"; + +import { blockConsoleFailTest } from "./blockConsoleFailTest.js"; +import { optionsBase } from "./options.fakes.js"; + +describe("blockConsoleFailTest", () => { + test("production", () => { + const creation = testBlock(blockConsoleFailTest, { + options: optionsBase, + }); + + expect(creation).toMatchInlineSnapshot(` + { + "addons": [ + { + "addons": { + "sections": { + "Testing": { + "contents": { + "after": [ + " + Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs. + Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail. + ", + ], + }, + }, + }, + }, + "block": [Function], + }, + { + "addons": { + "properties": { + "devDependencies": { + "console-fail-test": "0.6.1", + }, + }, + }, + "block": [Function], + }, + { + "addons": { + "setupFiles": [ + "console-fail-test/setup", + ], + }, + "block": [Function], + }, + ], + } + `); + }); +}); diff --git a/src/blocks/blockConsoleFailTest.ts b/src/blocks/blockConsoleFailTest.ts new file mode 100644 index 000000000..4f8a34bae --- /dev/null +++ b/src/blocks/blockConsoleFailTest.ts @@ -0,0 +1,25 @@ +import { base } from "../base.js"; +import { getPackageDependencies } from "../data/packageData.js"; +import { blockPackageJson } from "./blockPackageJson.js"; +import { blockVitest } from "./blockVitest.js"; + +export const blockConsoleFailTest = base.createBlock({ + produce() { + return { + addons: [ + blockPackageJson({ + properties: { + devDependencies: getPackageDependencies("console-fail-test"), + }, + }), + blockVitest({ + additionalDocs: ` +Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs. +Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail. +`, + setupFiles: ["console-fail-test/setup"], + }), + ], + }; + }, +}); diff --git a/src/blocks/blockVitest.test.ts b/src/blocks/blockVitest.test.ts index 642ee380c..06d349ef1 100644 --- a/src/blocks/blockVitest.test.ts +++ b/src/blocks/blockVitest.test.ts @@ -42,12 +42,7 @@ describe("blockVitest", () => { \`\`\`shell pnpm run test --coverage \`\`\` - - Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs. - Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail. - - - ", + ", }, }, }, @@ -179,7 +174,6 @@ describe("blockVitest", () => { "devDependencies": { "@vitest/coverage-v8": "4.0.15", "@vitest/eslint-plugin": "1.5.1", - "console-fail-test": "0.6.1", "vitest": "4.0.15", }, "scripts": { @@ -244,7 +238,6 @@ describe("blockVitest", () => { reporter: ["html", "lcov"], }, exclude: ["node_modules"], - setupFiles: ["console-fail-test/setup"], }, }); ", @@ -287,12 +280,7 @@ describe("blockVitest", () => { \`\`\`shell pnpm run test --coverage \`\`\` - - Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs. - Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail. - - - ", + ", }, }, }, @@ -424,7 +412,6 @@ describe("blockVitest", () => { "devDependencies": { "@vitest/coverage-v8": "4.0.15", "@vitest/eslint-plugin": "1.5.1", - "console-fail-test": "0.6.1", "vitest": "4.0.15", }, "scripts": { @@ -519,7 +506,6 @@ describe("blockVitest", () => { reporter: ["html", "lcov"], }, exclude: ["node_modules"], - setupFiles: ["console-fail-test/setup"], }, }); ", @@ -570,12 +556,7 @@ describe("blockVitest", () => { \`\`\`shell pnpm run test --coverage \`\`\` - - Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs. - Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail. - - - ", + ", }, }, }, @@ -707,7 +688,6 @@ describe("blockVitest", () => { "devDependencies": { "@vitest/coverage-v8": "4.0.15", "@vitest/eslint-plugin": "1.5.1", - "console-fail-test": "0.6.1", "vitest": "4.0.15", }, "scripts": { @@ -774,7 +754,6 @@ describe("blockVitest", () => { }, environment: "happy-dom", exclude: ["lib/","node_modules"], - setupFiles: ["console-fail-test/setup"], }, }); ", @@ -824,12 +803,7 @@ describe("blockVitest", () => { \`\`\`shell pnpm run test --coverage \`\`\` - - Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs. - Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail. - - - ", + ", }, }, }, @@ -961,7 +935,6 @@ describe("blockVitest", () => { "devDependencies": { "@vitest/coverage-v8": "4.0.15", "@vitest/eslint-plugin": "1.5.1", - "console-fail-test": "0.6.1", "vitest": "4.0.15", }, "scripts": { @@ -1027,7 +1000,6 @@ describe("blockVitest", () => { reporter: ["html", "lcov"], }, exclude: ["lib/","node_modules"], - setupFiles: ["console-fail-test/setup"], }, }); ", diff --git a/src/blocks/blockVitest.ts b/src/blocks/blockVitest.ts index 3c41b06d0..2371db59a 100644 --- a/src/blocks/blockVitest.ts +++ b/src/blocks/blockVitest.ts @@ -61,10 +61,12 @@ export const blockVitest = base.createBlock({ }, addons: { actionSteps: z.array(zActionStep).default([]), + additionalDocs: z.string().default(""), coverage: zCoverage.default({}), environment: zEnvironment.optional(), exclude: zExclude.default([]), flags: z.array(z.string()).default([]), + setupFiles: z.array(z.string()).default([]), }, intake({ files, options }) { return { @@ -75,7 +77,14 @@ export const blockVitest = base.createBlock({ }; }, produce({ addons }) { - const { actionSteps, coverage, environment, exclude = [] } = addons; + const { + actionSteps, + additionalDocs, + coverage, + environment, + exclude = [], + setupFiles, + } = addons; const excludeText = JSON.stringify( Array.from(new Set(["node_modules", ...exclude])).sort(), ); @@ -101,11 +110,15 @@ Add the \`--coverage\` flag to compute test coverage and place reports in the \` \`\`\`shell pnpm run test --coverage \`\`\` +${ + additionalDocs + ? ` -Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs. -Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail. - +${additionalDocs} +` + : "" +} `, }, }, @@ -198,7 +211,6 @@ describe(greet, () => { devDependencies: getPackageDependencies( "@vitest/coverage-v8", "@vitest/eslint-plugin", - "console-fail-test", "vitest", ), scripts: { @@ -249,8 +261,12 @@ export default defineConfig({ environment: "${environment}",` : "" } - exclude: [${excludeText.slice(1, excludeText.length - 1)}], - setupFiles: ["console-fail-test/setup"], + exclude: [${excludeText.slice(1, excludeText.length - 1)}],${ + setupFiles?.length + ? ` + setupFiles: ${JSON.stringify(setupFiles)},` + : "" + } }, }); `, diff --git a/src/blocks/index.ts b/src/blocks/index.ts index 9bd3a2aa8..78442c82c 100644 --- a/src/blocks/index.ts +++ b/src/blocks/index.ts @@ -1,6 +1,7 @@ import { blockAllContributors } from "./blockAllContributors.js"; import { blockAreTheTypesWrong } from "./blockAreTheTypesWrong.js"; import { blockCodecov } from "./blockCodecov.js"; +import { blockConsoleFailTest } from "./blockConsoleFailTest.js"; import { blockContributingDocs } from "./blockContributingDocs.js"; import { blockContributorCovenant } from "./blockContributorCovenant.js"; import { blockCSpell } from "./blockCSpell.js"; @@ -51,6 +52,7 @@ export const blocks = { blockAllContributors, blockAreTheTypesWrong, blockCodecov, + blockConsoleFailTest, blockContributingDocs, blockContributorCovenant, blockCSpell, @@ -101,6 +103,7 @@ export const blocks = { export { blockAllContributors } from "./blockAllContributors.js"; export { blockAreTheTypesWrong } from "./blockAreTheTypesWrong.js"; export { blockCodecov } from "./blockCodecov.js"; +export { blockConsoleFailTest } from "./blockConsoleFailTest.js"; export { blockContributingDocs } from "./blockContributingDocs.js"; export { blockContributorCovenant } from "./blockContributorCovenant.js"; export { blockCSpell } from "./blockCSpell.js"; diff --git a/src/presets/everything.ts b/src/presets/everything.ts index 2661f724b..f631e05d2 100644 --- a/src/presets/everything.ts +++ b/src/presets/everything.ts @@ -1,4 +1,5 @@ import { base } from "../base.js"; +import { blockConsoleFailTest } from "../blocks/blockConsoleFailTest.js"; import { blockCSpell } from "../blocks/blockCSpell.js"; import { blockESLintComments } from "../blocks/blockESLintComments.js"; import { blockESLintJSDoc } from "../blocks/blockESLintJSDoc.js"; @@ -30,6 +31,7 @@ export const presetEverything = base.createPreset({ }, blocks: [ ...presetCommon.blocks, + blockConsoleFailTest, blockCSpell, blockESLintComments, blockESLintJSDoc, From e20469431808d66e072b5aa68962598b720a5302 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 4 Dec 2025 15:56:22 -0500 Subject: [PATCH 2/3] snapshots --- src/blocks/blockConsoleFailTest.test.ts | 21 ++++----------------- src/blocks/blockVitest.test.ts | 12 ++++++++---- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/blocks/blockConsoleFailTest.test.ts b/src/blocks/blockConsoleFailTest.test.ts index 1153c4edd..6588ebf44 100644 --- a/src/blocks/blockConsoleFailTest.test.ts +++ b/src/blocks/blockConsoleFailTest.test.ts @@ -13,23 +13,6 @@ describe("blockConsoleFailTest", () => { expect(creation).toMatchInlineSnapshot(` { "addons": [ - { - "addons": { - "sections": { - "Testing": { - "contents": { - "after": [ - " - Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs. - Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail. - ", - ], - }, - }, - }, - }, - "block": [Function], - }, { "addons": { "properties": { @@ -42,6 +25,10 @@ describe("blockConsoleFailTest", () => { }, { "addons": { + "additionalDocs": " + Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs. + Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail. + ", "setupFiles": [ "console-fail-test/setup", ], diff --git a/src/blocks/blockVitest.test.ts b/src/blocks/blockVitest.test.ts index 06d349ef1..829336bf0 100644 --- a/src/blocks/blockVitest.test.ts +++ b/src/blocks/blockVitest.test.ts @@ -42,7 +42,8 @@ describe("blockVitest", () => { \`\`\`shell pnpm run test --coverage \`\`\` - ", + + ", }, }, }, @@ -280,7 +281,8 @@ describe("blockVitest", () => { \`\`\`shell pnpm run test --coverage \`\`\` - ", + + ", }, }, }, @@ -556,7 +558,8 @@ describe("blockVitest", () => { \`\`\`shell pnpm run test --coverage \`\`\` - ", + + ", }, }, }, @@ -803,7 +806,8 @@ describe("blockVitest", () => { \`\`\`shell pnpm run test --coverage \`\`\` - ", + + ", }, }, }, From d4e760a2ca34b9df618dc25a4a2f3bf7191dd798 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 4 Dec 2025 15:58:24 -0500 Subject: [PATCH 3/3] setupFiles? --- src/blocks/blockVitest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blocks/blockVitest.ts b/src/blocks/blockVitest.ts index 2371db59a..249127a39 100644 --- a/src/blocks/blockVitest.ts +++ b/src/blocks/blockVitest.ts @@ -262,7 +262,7 @@ export default defineConfig({ : "" } exclude: [${excludeText.slice(1, excludeText.length - 1)}],${ - setupFiles?.length + setupFiles.length ? ` setupFiles: ${JSON.stringify(setupFiles)},` : ""