Skip to content

Commit ab36a22

Browse files
chore: more e2e migration snapshots filters: contributors and line numbers (#1148)
## PR Checklist - [x] Addresses an existing open issue: fixes #1142 (again) - [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 Resets the all-contributors count in the snapshot too. So there's much less diff noise around it. In doing so, indicates that the snapshot file _might_ be changed. ANd that's ok.
1 parent b12dcc1 commit ab36a22

File tree

2 files changed

+72
-20
lines changed

2 files changed

+72
-20
lines changed

script/__snapshots__/migrate-test-e2e.js.snap

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`expected file changes > .eslintignore 1`] = `
44
"--- a/.eslintignore
55
+++ b/.eslintignore
6-
@@ -1,5 +1,5 @@
6+
@@ ... @@
77
!.*
88
-coverage*
99
+coverage
@@ -15,7 +15,7 @@ exports[`expected file changes > .eslintignore 1`] = `
1515
exports[`expected file changes > .eslintrc.cjs 1`] = `
1616
"--- a/.eslintrc.cjs
1717
+++ b/.eslintrc.cjs
18-
@@ -1,13 +1,3 @@
18+
@@ ... @@
1919
-/*
2020
-👋 Hi! This ESLint configuration contains a lot more stuff than many repos'!
2121
-You can read from it to see all sorts of linting goodness, but don't worry -
@@ -29,7 +29,7 @@ exports[`expected file changes > .eslintrc.cjs 1`] = `
2929
/** @type {import("@types/eslint").Linter.Config} */
3030
module.exports = {
3131
env: {
32-
@@ -76,18 +66,6 @@ module.exports = {
32+
@@ ... @@ module.exports = {
3333
rules: {
3434
// These off-by-default rules work well for this repo and we like them on.
3535
"deprecation/deprecation": "error",
@@ -53,7 +53,7 @@ exports[`expected file changes > .eslintrc.cjs 1`] = `
5353
exports[`expected file changes > .github/DEVELOPMENT.md 1`] = `
5454
"--- a/.github/DEVELOPMENT.md
5555
+++ b/.github/DEVELOPMENT.md
56-
@@ -99,7 +99,6 @@ Add \`--watch\` to keep the type checker running in a watch mode that updates the
56+
@@ ... @@ Add \`--watch\` to keep the type checker running in a watch mode that updates the
5757
\`\`\`shell
5858
pnpm tsc --watch
5959
\`\`\`
@@ -66,7 +66,7 @@ exports[`expected file changes > .github/DEVELOPMENT.md 1`] = `
6666
exports[`expected file changes > .github/workflows/lint-knip.yml 1`] = `
6767
"--- a/.github/workflows/lint-knip.yml
6868
+++ b/.github/workflows/lint-knip.yml
69-
@@ -4,7 +4,6 @@ jobs:
69+
@@ ... @@ jobs:
7070
steps:
7171
- uses: actions/checkout@v4
7272
- uses: ./.github/actions/prepare
@@ -79,7 +79,7 @@ exports[`expected file changes > .github/workflows/lint-knip.yml 1`] = `
7979
exports[`expected file changes > .github/workflows/test.yml 1`] = `
8080
"--- a/.github/workflows/test.yml
8181
+++ b/.github/workflows/test.yml
82-
@@ -7,14 +7,6 @@ jobs:
82+
@@ ... @@ jobs:
8383
- run: pnpm run test --coverage
8484
- name: Codecov
8585
uses: codecov/codecov-action@v3
@@ -99,7 +99,7 @@ exports[`expected file changes > .github/workflows/test.yml 1`] = `
9999
exports[`expected file changes > .gitignore 1`] = `
100100
"--- a/.gitignore
101101
+++ b/.gitignore
102-
@@ -1,3 +1,3 @@
102+
@@ ... @@
103103
-coverage*/
104104
+coverage/
105105
lib/
@@ -109,7 +109,7 @@ exports[`expected file changes > .gitignore 1`] = `
109109
exports[`expected file changes > .prettierignore 1`] = `
110110
"--- a/.prettierignore
111111
+++ b/.prettierignore
112-
@@ -1,4 +1,4 @@
112+
@@ ... @@
113113
.all-contributorsrc
114114
-coverage*/
115115
+coverage/
@@ -120,7 +120,7 @@ exports[`expected file changes > .prettierignore 1`] = `
120120
exports[`expected file changes > README.md 1`] = `
121121
"--- a/README.md
122122
+++ b/README.md
123-
@@ -5,57 +5,20 @@
123+
@@ ... @@
124124
<p align="center">
125125
<!-- prettier-ignore-start -->
126126
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
@@ -186,7 +186,7 @@ exports[`expected file changes > README.md 1`] = `
186186
## Development
187187
188188
See [\`.github/CONTRIBUTING.md\`](./.github/CONTRIBUTING.md), then [\`.github/DEVELOPMENT.md\`](./.github/DEVELOPMENT.md).
189-
@@ -128,3 +91,7 @@ Thanks! 💖
189+
@@ ... @@ Thanks! 💖
190190
191191
<!-- ALL-CONTRIBUTORS-LIST:END -->
192192
<!-- spellchecker: enable -->
@@ -199,7 +199,7 @@ exports[`expected file changes > README.md 1`] = `
199199
exports[`expected file changes > cspell.json 1`] = `
200200
"--- a/cspell.json
201201
+++ b/cspell.json
202-
@@ -1,40 +1,27 @@
202+
@@ ... @@
203203
{
204204
"dictionaries": ["typescript"],
205205
"ignorePaths": [
@@ -247,7 +247,7 @@ exports[`expected file changes > cspell.json 1`] = `
247247
exports[`expected file changes > knip.jsonc 1`] = `
248248
"--- a/knip.jsonc
249249
+++ b/knip.jsonc
250-
@@ -1,17 +1,6 @@
250+
@@ ... @@
251251
{
252252
"$schema": "https://unpkg.com/knip@latest/schema.json",
253253
- "entry": [
@@ -273,23 +273,23 @@ exports[`expected file changes > knip.jsonc 1`] = `
273273
exports[`expected file changes > package.json 1`] = `
274274
"--- a/package.json
275275
+++ b/package.json
276-
@@ -15,7 +15,6 @@
276+
@@ ... @@
277277
"main": "./lib/index.js",
278278
"bin": "./bin/index.js",
279279
"files": [
280280
- "bin/",
281281
"lib/",
282282
"package.json",
283283
"LICENSE.md",
284-
@@ -24,7 +23,6 @@
284+
@@ ... @@
285285
"scripts": {
286286
"build": "tsup",
287287
"format": "prettier \\"**/*\\" --ignore-unknown",
288288
- "initialize": "tsx ./src/bin/index.js --mode initialize",
289289
"lint": "eslint . .*js --max-warnings 0",
290290
"lint:knip": "knip",
291291
"lint:md": "markdownlint \\"**/*.md\\" \\".github/**/*.md\\" --rules sentences-per-line",
292-
@@ -34,9 +32,6 @@
292+
@@ ... @@
293293
"prepare": "husky install",
294294
"should-semantic-release": "should-semantic-release --verbose",
295295
"test": "vitest",
@@ -299,7 +299,7 @@ exports[`expected file changes > package.json 1`] = `
299299
"tsc": "tsc"
300300
},
301301
"lint-staged": {
302-
@@ -107,7 +102,7 @@
302+
@@ ... @@
303303
"vitest": "^1.0.2",
304304
"yaml-eslint-parser": "^1.2.2"
305305
},

script/migrate-test-e2e.js

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { assert, describe, expect, test } from "vitest";
55

66
import packageData from "../package.json" assert { type: "json" };
77

8-
const filesExpectedToBeChanged = new Set([
8+
const filesExpectedToBeChanged = [
99
"README.md",
1010
"knip.jsonc",
1111
"package.json",
@@ -17,6 +17,11 @@ const filesExpectedToBeChanged = new Set([
1717
".gitignore",
1818
".prettierignore",
1919
"cspell.json",
20+
];
21+
22+
const filesThatMightBeChanged = new Set([
23+
...filesExpectedToBeChanged,
24+
"script/__snapshots__/migrate-test-e2e.js.snap",
2025
]);
2126

2227
const {
@@ -36,6 +41,12 @@ const originalDevelopment = (
3641
await fs.readFile(".github/DEVELOPMENT.md")
3742
).toString();
3843

44+
const originalReadme = (await fs.readFile("README.md")).toString();
45+
46+
const originalSnapshots = (
47+
await fs.readFile("script/__snapshots__/migrate-test-e2e.js.snap")
48+
).toString();
49+
3950
await $({
4051
stdio: "inherit",
4152
})`c8 -o ./coverage -r html -r lcov --src src node ${bin} --base everything --author ${authorName} --mode migrate --bin ${bin} --description ${description} --email-github ${emailGithub} --email-npm ${emailNpm} --guide ${guide} --guide-title ${guideTitle} --owner ${owner} --title ${title} --repository ${repository} --skip-all-contributors-api --skip-github-api --skip-install`;
@@ -57,10 +68,51 @@ await fs.appendFile(
5768
originalDevelopment.slice(originalDevelopment.indexOf("## Setup Scripts")),
5869
);
5970

71+
// Ignore changes to the README.md all-contributor count and contributors table...
72+
const updatedReadme = (await fs.readFile("README.md")).toString();
73+
await fs.writeFile(
74+
"README.md",
75+
[
76+
updatedReadme.slice(0, updatedReadme.indexOf("## Contributors")) +
77+
originalReadme.slice(
78+
originalReadme.indexOf("## Contributors"),
79+
originalReadme.indexOf("<!-- markdownlint-restore -->"),
80+
),
81+
updatedReadme.slice(updatedReadme.indexOf("<!-- markdownlint-restore -->")),
82+
]
83+
.join("")
84+
.replaceAll(
85+
/All Contributors: \d+/g,
86+
originalReadme.match(/All Contributors: \d+/)[0],
87+
)
88+
.replaceAll(
89+
/all_contributors-\d+/g,
90+
originalReadme.match(/all_contributors-\d+/)[0],
91+
),
92+
);
93+
94+
// ...and even to the snapshot file, so diffs don't mind it.
95+
await fs.writeFile(
96+
"script/__snapshots__/migrate-test-e2e.js.snap",
97+
originalSnapshots
98+
.replaceAll(
99+
/All Contributors: \d+/g,
100+
originalReadme.match(/All Contributors: \d+/)[0],
101+
)
102+
.replaceAll(
103+
/all_contributors-\d+/g,
104+
originalReadme.match(/all_contributors-\d+/)[0],
105+
),
106+
);
107+
60108
describe("expected file changes", () => {
61-
test.each([...filesExpectedToBeChanged])("%s", async (file) => {
109+
test.each(filesExpectedToBeChanged)("%s", async (file) => {
62110
const { stdout } = await execaCommand(`git diff HEAD -- ${file}`);
63-
const contentsAfterGitMarkers = stdout.split("\n").slice(2).join("\n");
111+
const contentsAfterGitMarkers = stdout
112+
.split("\n")
113+
.slice(2)
114+
.join("\n")
115+
.replaceAll(/@@ -\d+,\d+ \+\d+,\d+ @@/g, "@@ ... @@");
64116

65117
assert(
66118
stdout,
@@ -88,7 +140,7 @@ test("unexpected file changes", async () => {
88140
.slice(indexOfUnstagedFilesMessage)
89141
.match(/modified: {3}(\S+)\n/g)
90142
.map((match) => match.split(/\s+/g)[1])
91-
.filter((filePath) => !filesExpectedToBeChanged.has(filePath));
143+
.filter((filePath) => !filesThatMightBeChanged.has(filePath));
92144

93145
console.log("Unexpected modified files are:", unstagedModifiedFiles);
94146

0 commit comments

Comments
 (0)