-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathinitialize-test-e2e.js
56 lines (48 loc) · 2.23 KB
/
initialize-test-e2e.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { $ } from "execa";
import { globby } from "globby";
import { strict as assert } from "node:assert";
import * as fs from "node:fs/promises";
const description = "New Description Test";
const owner = "RNR1";
const title = "New Title Test";
const repository = "new-repository-test";
// Fist we run with --mode initialize to modify the local repository files,
// asserting that the created package.json keeps the general description.
await $({
stdio: "inherit",
})`pnpm run initialize --base everything --mode initialize --description ${description} --owner ${owner} --title ${title} --repository ${repository} --skip-all-contributors-api --skip-github-api --skip-restore`;
const newPackageJson = JSON.parse(
(await fs.readFile("./package.json")).toString(),
);
console.log("New package JSON:", newPackageJson);
assert.equal(newPackageJson.description, description);
assert.equal(newPackageJson.name, repository);
// Assert that the initialize script used the provided values in files,
// except for the 'This package was templated with ...' attribution notice.
const files = await globby(["*.*", "**/*.*"], {
gitignore: true,
ignoreFiles: ["script/initialize-test-e2e.js"],
});
for (const search of [`/JoshuaKGoldberg/`, "create-typescript-app"]) {
const { stdout } = await $`grep -i ${search} ${files}`;
assert.equal(
stdout,
`README.md:> 💙 This package was templated with [\`create-typescript-app\`](https://github.com/JoshuaKGoldberg/create-typescript-app).`,
);
}
// Use Knip to assert that none of the template-only dependencies remain.
// They should have been removed as part of initialization.
try {
await $`pnpm run lint:knip`;
} catch (error) {
throw new Error("Error running lint:knip:", { cause: error });
}
// Now that initialize has passed normal steps, we reset everything,
// then run again without removing files - so we can capture test coverage
await $`git add -A`;
await $`git reset --hard HEAD`;
await $`pnpm i`;
await $`pnpm run build`;
await $({
stdio: "inherit",
})`c8 -o ./coverage -r html -r lcov --src src node ./bin/index.js --base everything --mode initialize --description ${description} --owner ${owner} --title ${title} --repository ${repository} --skip-all-contributors-api --skip-github-api --skip-removal --skip-restore`;