Skip to content

Commit 59b6380

Browse files
build: also track e2e test coverage (#473)
<!-- 👋 Hi, thanks for sending a PR to template-typescript-node-package! 💖. Please fill out all fields below and make sure each item is true and [x] checked. Otherwise we may not be able to review your PR. --> ## PR Checklist - [x] Addresses an existing open issue: fixes #472 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/template-typescript-node-package/blob/main/.github/CONTRIBUTING.md) were taken ## Overview Again uses the [codecov/codecov-action](https://github.com/codecov/codecov-action) to store coverage reports, this time from `coverage-hydrate` and `coverage-setup`. For convenience, all coverage reports are stored in GitHub Actions (https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts).
1 parent 4f13558 commit 59b6380

18 files changed

+343
-228
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
!.*
2-
coverage
2+
coverage*
33
lib
44
node_modules
55
pnpm-lock.yaml

.github/workflows/hydrate.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ jobs:
55
- uses: actions/checkout@v3
66
- uses: ./.github/actions/prepare
77
- run: pnpm run build
8-
- run: pnpm run setup:test
8+
- run: pnpm run hydrate:test
9+
- name: Codecov
10+
uses: codecov/codecov-action@v3
11+
with:
12+
files: coverage-hydrate/lcov.info
13+
- name: Archive code coverage results
14+
uses: actions/upload-artifact@v3
15+
with:
16+
path: coverage-hydrate
917

1018
name: Test Hydrate Script
1119

.github/workflows/setup.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ jobs:
44
steps:
55
- uses: actions/checkout@v3
66
- uses: ./.github/actions/prepare
7+
- run: pnpm run build
78
- run: pnpm run setup:test
89

910
name: Test Setup Script

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ jobs:
77
- run: pnpm run test --coverage
88
- name: Codecov
99
uses: codecov/codecov-action@v3
10+
- name: Archive code coverage results
11+
uses: actions/upload-artifact@v3
1012
with:
11-
github-token: ${{ secrets.GITHUB_TOKEN }}
13+
name: code-coverage-report
14+
path: coverage
1215

1316
name: Test
1417

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
coverage/
1+
coverage*/
22
lib/
33
node_modules/

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
coverage/
1+
coverage*/
22
lib/
33
pnpm-lock.yaml
44

knip.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"script/*e2e.js"
88
],
99
"ignoreBinaries": ["dedupe", "gh"],
10+
"ignoreDependencies": ["c8"],
1011
"project": ["src/**/*.ts!", "script/**/*.js"]
1112
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"@typescript-eslint/parser": "^5.59.5",
5353
"@vitest/coverage-istanbul": "^0.31.0",
5454
"all-contributors-cli": "^6.25.1",
55+
"c8": "^7.13.0",
5556
"console-fail-test": "^0.2.3",
5657
"cspell": "^6.31.1",
5758
"eslint": "^8.40.0",

pnpm-lock.yaml

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

script/hydrate-test-e2e.js

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import chalk from "chalk";
22
import { $ } from "execa";
33

4+
await $({
5+
stdio: "inherit",
6+
})`c8 -o ./coverage-hydrate -r html -r lcov node ./lib/hydrate/index.js`;
7+
48
const { stdout: gitStatus } = await $`git status`;
59
console.log(`Stdout from running \`git status\`:\n${gitStatus}`);
610

@@ -19,6 +23,15 @@ const filesExpectedToBeChanged = new Set([
1923
"knip.jsonc",
2024
"package.json",
2125
"pnpm-lock.yaml",
26+
".eslintignore",
27+
".eslintrc.cjs",
28+
".github/DEVELOPMENT.md",
29+
".github/workflows/release.yml",
30+
".github/workflows/test.yml",
31+
".gitignore",
32+
".prettierignore",
33+
".release-it.json",
34+
"cspell.json",
2235
]);
2336

2437
const unstagedModifiedFiles = gitStatus
@@ -27,24 +40,29 @@ const unstagedModifiedFiles = gitStatus
2740
.map((match) => match.split(/\s+/g)[1])
2841
.filter((filePath) => !filesExpectedToBeChanged.has(filePath));
2942

43+
console.log("Unexpected modified files are:", unstagedModifiedFiles);
44+
3045
if (unstagedModifiedFiles.length) {
46+
const gitDiffCommand = `git diff HEAD -- ${unstagedModifiedFiles.join(" ")}`;
3147
console.log(
32-
`Stdout from running \`git diff\`:${(await $`git diff HEAD`).stdout}`
48+
`Stdout from running \`${gitDiffCommand}\`:\n${
49+
(await $(gitDiffCommand)).stdout
50+
}`
3351
);
3452
console.error(
35-
chalk.red(
36-
[
37-
"",
38-
"Oh no! Running the hydrate script modified some files:",
39-
...unstagedModifiedFiles.map((filePath) => ` - ${filePath}`),
40-
"",
41-
"That likely indicates changes made to the repository without",
42-
"corresponding updates to templates in src/hydrate/creation.",
43-
"",
44-
"Please search for those file(s)' name(s) under src/hydrate for",
45-
"the corresponding template and update those as well.",
46-
].join("\n")
47-
)
53+
[
54+
"",
55+
"Oh no! Running the hydrate script modified some files:",
56+
...unstagedModifiedFiles.map((filePath) => ` - ${filePath}`),
57+
"",
58+
"That likely indicates changes made to the repository without",
59+
"corresponding updates to templates in src/hydrate/creation.",
60+
"",
61+
"Please search for those file(s)' name(s) under src/hydrate for",
62+
"the corresponding template and update those as well.",
63+
]
64+
.map((line) => chalk.red(line))
65+
.join("\n")
4866
);
4967
process.exitCode = 1;
5068
}

0 commit comments

Comments
 (0)