Skip to content

Commit 18ef648

Browse files
build: add coverage tracking to setup script (#496)
## PR Checklist - [x] Addresses an existing open issue: fixes #495 - [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 Uses similar tracking to the hydration script.
1 parent 6327814 commit 18ef648

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

.github/workflows/setup.yml

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

1018
name: Test Setup Script
1119

script/setup-test-e2e.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const owner = "RNR1";
99
const title = "New Title Test";
1010
const repository = "new-repository-test";
1111

12+
// First we run setup to modifies the local repo, so we can test the changes
1213
await $({
1314
stdio: "inherit",
1415
})`node ./lib/setup/index.js --description ${description} --owner ${owner} --title ${title} --repository ${repository} --skip-api --skip-restore`;
@@ -43,3 +44,13 @@ try {
4344
console.error("Error running lint:knip:", error);
4445
process.exitCode = 1;
4546
}
47+
48+
// Now that setup has passed normal steps, we reset everything,
49+
// then run again without removing files - so we can capture test coverage
50+
await $`git add -A`;
51+
await $`git reset --hard HEAD`;
52+
await $`pnpm i`;
53+
await $`pnpm run build`;
54+
await $({
55+
stdio: "inherit",
56+
})`c8 -o ./coverage-setup -r html -r lcov node ./lib/setup/index.js --description ${description} --owner ${owner} --title ${title} --repository ${repository} --skip-api --skip-removal --skip-restore`;

src/hydrate/values/hydrationInputValues.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe("ensureHydrationInputValues", () => {
1616
title: undefined,
1717
unitTests: undefined,
1818
skipApi: undefined,
19+
skipRemoval: undefined,
1920
skipRestore: undefined,
2021
skipUninstalls: undefined,
2122
})
@@ -41,6 +42,7 @@ describe("ensureHydrationInputValues", () => {
4142
title: "Test Title",
4243
unitTests: true,
4344
skipApi: undefined,
45+
skipRemoval: undefined,
4446
skipRestore: undefined,
4547
skipUninstalls: undefined,
4648
})

src/setup/setupWithInformation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ export async function setupWithInformation({
7878
successSpinnerBlock(`Finished API hydration.`);
7979
}
8080

81-
await withSpinner(removeSetupScripts, "removing setup scripts");
81+
if (values.skipRemoval) {
82+
skipSpinnerBlock(`Skipping removal of setup scripts.`);
83+
} else {
84+
await withSpinner(removeSetupScripts, "removing setup scripts");
85+
}
8286

8387
if (values.skipUninstalls) {
8488
skipSpinnerBlock(`Skipping uninstall of packages only used for setup.`);

src/shared/inputs.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface DefaultInputValues {
3333
releases: boolean | undefined;
3434
repository: string;
3535
skipApi: boolean;
36+
skipRemoval: boolean;
3637
skipRestore: boolean;
3738
skipUninstalls: boolean;
3839
title: string;
@@ -68,6 +69,7 @@ export async function getInputValuesAndOctokit(
6869
unitTests: { type: "boolean" },
6970
title: { type: "string" },
7071
"skip-api": { type: "boolean" },
72+
"skip-removal": { type: "boolean" },
7173
"skip-restore": { type: "boolean" },
7274
"skip-uninstall": { type: "boolean" },
7375
},
@@ -134,6 +136,7 @@ export async function getInputValuesAndOctokit(
134136
owner,
135137
repository,
136138
skipApi: !!values["skip-api"],
139+
skipRemoval: !!values["skip-removal"],
137140
skipRestore: !!values["skip-restore"],
138141
skipUninstalls: !!values["skip-uninstalls"],
139142
title,

0 commit comments

Comments
 (0)