Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: preserve existing unknown .github/DEVELOPMENT.md sections #1173

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions script/__snapshots__/migrate-test-e2e.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@ exports[`expected file changes > cspell.json 1`] = `
"mtfoley",
"npmignore",
@@ ... @@
"packagejson",
"quickstart",
"tada",
+ "templating",
"tsup",
- "vitest"
+ "vitest",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";

import { Options } from "../../../../shared/types.js";
import { createDevelopment } from "./createDevelopment.js";
import { Options } from "../../../../../shared/types.js";
import { createDevelopment } from "./index.js";

const mockReadFileSafe = vi.fn();

vi.mock("../../../../../shared/readFileSafe.js", () => ({
get readFileSafe() {
return mockReadFileSafe;
},
}));

const options = {
access: "public",
Expand All @@ -21,8 +29,10 @@ const options = {
} satisfies Options;

describe("createDevelopment", () => {
it("creates a file with extra options turned on when options disable them", () => {
const actual = createDevelopment({
it("creates a file with extra options turned on when options disable them", async () => {
mockReadFileSafe.mockResolvedValue("");

const actual = await createDevelopment({
...options,
excludeLintKnip: false,
excludeLintMd: false,
Expand Down Expand Up @@ -77,7 +87,7 @@ describe("createDevelopment", () => {

- \`pnpm lint\` ([ESLint](https://eslint.org) with [typescript-eslint](https://typescript-eslint.io)): Lints JavaScript and TypeScript source files
- \`pnpm lint:knip\` ([knip](https://github.com/webpro/knip)): Detects unused files, dependencies, and code exports
- \`pnpm lint:md\` ([Markdownlint](https://github.com/DavidAnson/markdownlint)): Checks Markdown source files
- \`pnpm lint:md\` ([Markdownlint](https://github.com/DavidAnson/markdownlint): Checks Markdown source files
- \`pnpm lint:package-json\` ([npm-package-json-lint](https://npmpackagejsonlint.org/)): Lints the \`package.json\` file
- \`pnpm lint:packages\` ([pnpm dedupe --check](https://pnpm.io/cli/dedupe)): Checks for unnecessarily duplicated packages in the \`pnpm-lock.yml\` file
- \`pnpm lint:spelling\` ([cspell](https://cspell.org)): Spell checks across all source files
Expand Down Expand Up @@ -134,8 +144,10 @@ describe("createDevelopment", () => {
`);
});

it("creates a file with extra options turned off when options enable them", () => {
const actual = createDevelopment({
it("creates a file with extra options turned off when options enable them", async () => {
mockReadFileSafe.mockResolvedValue("");

const actual = await createDevelopment({
...options,
excludeLintKnip: true,
excludeLintMd: true,
Expand Down Expand Up @@ -192,7 +204,7 @@ describe("createDevelopment", () => {

## Linting

[ESLint](https://eslint.org) is used with with [typescript-eslint](https://typescript-eslint.io) to lint JavaScript and TypeScript source files.
[ESLint](https://eslint.org) is used with with [typescript-eslint](https://typescript-eslint.io)) to lint JavaScript and TypeScript source files.
You can run it locally on the command-line:

\`\`\`shell
Expand Down Expand Up @@ -248,4 +260,136 @@ describe("createDevelopment", () => {
"
`);
});

it("preserves existing sections when they don't match the new sections", async () => {
mockReadFileSafe.mockResolvedValue(`## Existing One

Abc 123.

## Building

Will be removed.

## Tests

Will be removed.

## Existing Two

Def 456.
`);

const actual = await createDevelopment({
...options,
excludeLintKnip: false,
excludeLintMd: false,
excludeLintPackageJson: false,
excludeLintPackages: false,
excludeLintSpelling: false,
});

expect(actual).toMatchInlineSnapshot(`
"# Development

After [forking the repo from GitHub](https://help.github.com/articles/fork-a-repo) and [installing pnpm](https://pnpm.io/installation):

\`\`\`shell
git clone https://github.com/<your-name-here>/test-repository
cd test-repository
pnpm install
\`\`\`

> This repository includes a list of suggested VS Code extensions.
> 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.

## Building

Will be removed.

## Formatting

[Prettier](https://prettier.io) is used to format code.
It should be applied automatically when you save files in VS Code or make a Git commit.

To manually reformat all files, you can run:

\`\`\`shell
pnpm format --write
\`\`\`

## Linting

This package includes several forms of linting to enforce consistent code quality and styling.
Each should be shown in VS Code, and can be run manually on the command-line:

- \`pnpm lint\` ([ESLint](https://eslint.org) with [typescript-eslint](https://typescript-eslint.io)): Lints JavaScript and TypeScript source files
- \`pnpm lint:knip\` ([knip](https://github.com/webpro/knip)): Detects unused files, dependencies, and code exports
- \`pnpm lint:md\` ([Markdownlint](https://github.com/DavidAnson/markdownlint): Checks Markdown source files
- \`pnpm lint:package-json\` ([npm-package-json-lint](https://npmpackagejsonlint.org/)): Lints the \`package.json\` file
- \`pnpm lint:packages\` ([pnpm dedupe --check](https://pnpm.io/cli/dedupe)): Checks for unnecessarily duplicated packages in the \`pnpm-lock.yml\` file
- \`pnpm lint:spelling\` ([cspell](https://cspell.org)): Spell checks across all source files

Read the individual documentation for each linter to understand how it can be configured and used best.

For example, ESLint can be run with \`--fix\` to auto-fix some lint rule complaints:

\`\`\`shell
pnpm run lint --fix
\`\`\`

Note that you'll likely need to run \`pnpm build\` before \`pnpm lint\` so that lint rules which check the file system can pick up on any built files.

## Testing

[Vitest](https://vitest.dev) is used for tests.
You can run it locally on the command-line:

\`\`\`shell
pnpm run test
\`\`\`

Add the \`--coverage\` flag to compute test coverage and place reports in the \`coverage/\` directory:

\`\`\`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.

### Debugging Tests

This repository includes a [VS Code launch configuration](https://code.visualstudio.com/docs/editor/debugging) for debugging unit tests.
To launch it, open a test file, then run _Debug Current Test File_ from the VS Code Debug panel (or press F5).

## Type Checking

You should be able to see suggestions from [TypeScript](https://typescriptlang.org) in your editor for all open files.

However, it can be useful to run the TypeScript command-line (\`tsc\`) to type check all files in \`src/\`:

\`\`\`shell
pnpm tsc
\`\`\`

Add \`--watch\` to keep the type checker running in a watch mode that updates the display as you save files:

\`\`\`shell
pnpm tsc --watch
\`\`\`

## Existing One

Abc 123.

## Tests

Will be removed.

## Existing Two

Def 456.
"
`);
});
});
Loading