|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | + |
| 3 | +import { Options } from "../../../../shared/types.js"; |
| 4 | +import { createDevelopment } from "./createDevelopment.js"; |
| 5 | + |
| 6 | +const options = { |
| 7 | + author: "Test Author", |
| 8 | + base: "everything", |
| 9 | + createRepository: false, |
| 10 | + description: "Test description.", |
| 11 | + |
| 12 | + excludeCompliance: undefined, |
| 13 | + excludeContributors: undefined, |
| 14 | + excludeLintJson: undefined, |
| 15 | + excludeLintKnip: undefined, |
| 16 | + excludeLintMd: undefined, |
| 17 | + excludeLintPackageJson: undefined, |
| 18 | + excludeLintPackages: undefined, |
| 19 | + excludeLintPerfectionist: undefined, |
| 20 | + excludeLintSpelling: undefined, |
| 21 | + excludeLintYml: undefined, |
| 22 | + excludeReleases: undefined, |
| 23 | + excludeRenovate: undefined, |
| 24 | + excludeTests: undefined, |
| 25 | + funding: undefined, |
| 26 | + owner: "TestOwner", |
| 27 | + repository: "test-repository", |
| 28 | + skipGitHubApi: false, |
| 29 | + skipInstall: true, |
| 30 | + skipRemoval: false, |
| 31 | + skipRestore: false, |
| 32 | + skipUninstall: false, |
| 33 | + title: "Test Title", |
| 34 | +} satisfies Options; |
| 35 | + |
| 36 | +describe("createDevelopment", () => { |
| 37 | + it("creates a file with no extra linters when options exclude them", () => { |
| 38 | + const actual = createDevelopment({ |
| 39 | + ...options, |
| 40 | + excludeLintKnip: false, |
| 41 | + excludeLintMd: false, |
| 42 | + excludeLintPackageJson: false, |
| 43 | + excludeLintPackages: false, |
| 44 | + excludeLintSpelling: false, |
| 45 | + }); |
| 46 | + |
| 47 | + expect(actual).toMatchInlineSnapshot(` |
| 48 | + "# Development |
| 49 | +
|
| 50 | + After [forking the repo from GitHub](https://help.github.com/articles/fork-a-repo) and [installing pnpm](https://pnpm.io/installation): |
| 51 | +
|
| 52 | + \`\`\`shell |
| 53 | + git clone https://github.com/<your-name-here>/test-repository |
| 54 | + cd test-repository |
| 55 | + pnpm install |
| 56 | + \`\`\` |
| 57 | +
|
| 58 | + > This repository includes a list of suggested VS Code extensions. |
| 59 | + > It's a good idea to use [VS Code](https://code.visualstudio.com) and accept its suggestion to install them, as they'll help with development. |
| 60 | +
|
| 61 | + ## Building |
| 62 | +
|
| 63 | + Run [TypeScript](https://typescriptlang.org) locally to type check and build source files from \`src/\` into output files in \`lib/\`: |
| 64 | +
|
| 65 | + \`\`\`shell |
| 66 | + pnpm build --watch |
| 67 | + \`\`\` |
| 68 | +
|
| 69 | + You should also see suggestions from TypeScript in your editor. |
| 70 | +
|
| 71 | + ## Formatting |
| 72 | +
|
| 73 | + [Prettier](https://prettier.io) is used to format code. |
| 74 | + It should be applied automatically when you save files in VS Code or make a Git commit. |
| 75 | +
|
| 76 | + To manually reformat all files, you can run: |
| 77 | +
|
| 78 | + \`\`\`shell |
| 79 | + pnpm format:write |
| 80 | + \`\`\` |
| 81 | +
|
| 82 | + ## Linting |
| 83 | +
|
| 84 | + This package includes several forms of linting to enforce consistent code quality and styling. |
| 85 | + Each should be shown in VS Code, and can be run manually on the command-line: |
| 86 | +
|
| 87 | + - \`pnpm lint\` ([ESLint](https://eslint.org) with [typescript-eslint](https://typescript-eslint.io)): Lints JavaScript and TypeScript source files |
| 88 | + - \`pnpm lint:knip\` ([knip](https://github.com/webpro/knip)): Detects unused files, dependencies, and code exports |
| 89 | + - \`pnpm lint:md\` ([Markdownlint](https://github.com/DavidAnson/markdownlint)): Checks Markdown source files |
| 90 | + - \`pnpm lint:package-json\` ([npm-package-json-lint](https://npmpackagejsonlint.org/)): Lints the \`package.json\` file |
| 91 | + - \`pnpm lint:packages\` ([pnpm dedupe --check](https://pnpm.io/cli/dedupe)): Checks for unnecessarily duplicated packages in the \`pnpm-lock.yml\` file |
| 92 | + - \`pnpm lint:spelling\` ([cspell](https://cspell.org)): Spell checks across all source files |
| 93 | +
|
| 94 | + Read the individual documentation for each linter to understand how it can be configured and used best. |
| 95 | +
|
| 96 | + For example, ESLint can be run with \`--fix\` to auto-fix some lint rule complaints: |
| 97 | +
|
| 98 | + \`\`\`shell |
| 99 | + pnpm run lint --fix |
| 100 | + \`\`\` |
| 101 | +
|
| 102 | + ## Testing |
| 103 | +
|
| 104 | + [Vitest](https://vitest.dev) is used for tests. |
| 105 | + You can run it locally on the command-line: |
| 106 | +
|
| 107 | + \`\`\`shell |
| 108 | + pnpm run test |
| 109 | + \`\`\` |
| 110 | +
|
| 111 | + Add the \`--coverage\` flag to compute test coverage and place reports in the \`coverage/\` directory: |
| 112 | +
|
| 113 | + \`\`\`shell |
| 114 | + pnpm run test --coverage |
| 115 | + \`\`\` |
| 116 | +
|
| 117 | + Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs. |
| 118 | + Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail. |
| 119 | +
|
| 120 | + ### Debugging Tests |
| 121 | +
|
| 122 | + This repository includes a [VS Code launch configuration](https://code.visualstudio.com/docs/editor/debugging) for debugging unit tests. |
| 123 | + To launch it, open a test file, then run _Debug Current Test File_ from the VS Code Debug panel (or press F5). |
| 124 | +
|
| 125 | + " |
| 126 | + `); |
| 127 | + }); |
| 128 | + |
| 129 | + it("creates a file with all extra linters when options include them", () => { |
| 130 | + const actual = createDevelopment({ |
| 131 | + ...options, |
| 132 | + excludeLintKnip: true, |
| 133 | + excludeLintMd: true, |
| 134 | + excludeLintPackageJson: true, |
| 135 | + excludeLintPackages: true, |
| 136 | + excludeLintSpelling: true, |
| 137 | + }); |
| 138 | + |
| 139 | + expect(actual).toMatchInlineSnapshot(` |
| 140 | + "# Development |
| 141 | +
|
| 142 | + After [forking the repo from GitHub](https://help.github.com/articles/fork-a-repo) and [installing pnpm](https://pnpm.io/installation): |
| 143 | +
|
| 144 | + \`\`\`shell |
| 145 | + git clone https://github.com/<your-name-here>/test-repository |
| 146 | + cd test-repository |
| 147 | + pnpm install |
| 148 | + \`\`\` |
| 149 | +
|
| 150 | + > This repository includes a list of suggested VS Code extensions. |
| 151 | + > It's a good idea to use [VS Code](https://code.visualstudio.com) and accept its suggestion to install them, as they'll help with development. |
| 152 | +
|
| 153 | + ## Building |
| 154 | +
|
| 155 | + Run [TypeScript](https://typescriptlang.org) locally to type check and build source files from \`src/\` into output files in \`lib/\`: |
| 156 | +
|
| 157 | + \`\`\`shell |
| 158 | + pnpm build --watch |
| 159 | + \`\`\` |
| 160 | +
|
| 161 | + You should also see suggestions from TypeScript in your editor. |
| 162 | +
|
| 163 | + ## Formatting |
| 164 | +
|
| 165 | + [Prettier](https://prettier.io) is used to format code. |
| 166 | + It should be applied automatically when you save files in VS Code or make a Git commit. |
| 167 | +
|
| 168 | + To manually reformat all files, you can run: |
| 169 | +
|
| 170 | + \`\`\`shell |
| 171 | + pnpm format:write |
| 172 | + \`\`\` |
| 173 | +
|
| 174 | + ## Linting |
| 175 | +
|
| 176 | + [ESLint](https://eslint.org) is used with with [typescript-eslint](https://typescript-eslint.io)) to lint JavaScript and TypeScript source files. |
| 177 | + You can run it locally on the command-line: |
| 178 | +
|
| 179 | + \`\`\`shell |
| 180 | + pnpm run lint |
| 181 | + \`\`\` |
| 182 | +
|
| 183 | + ESLint can be run with \`--fix\` to auto-fix some lint rule complaints: |
| 184 | +
|
| 185 | + \`\`\`shell |
| 186 | + pnpm run lint --fix |
| 187 | + \`\`\` |
| 188 | +
|
| 189 | + ## Testing |
| 190 | +
|
| 191 | + [Vitest](https://vitest.dev) is used for tests. |
| 192 | + You can run it locally on the command-line: |
| 193 | +
|
| 194 | + \`\`\`shell |
| 195 | + pnpm run test |
| 196 | + \`\`\` |
| 197 | +
|
| 198 | + Add the \`--coverage\` flag to compute test coverage and place reports in the \`coverage/\` directory: |
| 199 | +
|
| 200 | + \`\`\`shell |
| 201 | + pnpm run test --coverage |
| 202 | + \`\`\` |
| 203 | +
|
| 204 | + Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs. |
| 205 | + Calls to \`console.log\`, \`console.warn\`, and other console methods will cause a test to fail. |
| 206 | +
|
| 207 | + ### Debugging Tests |
| 208 | +
|
| 209 | + This repository includes a [VS Code launch configuration](https://code.visualstudio.com/docs/editor/debugging) for debugging unit tests. |
| 210 | + To launch it, open a test file, then run _Debug Current Test File_ from the VS Code Debug panel (or press F5). |
| 211 | +
|
| 212 | + " |
| 213 | + `); |
| 214 | + }); |
| 215 | +}); |
0 commit comments