-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathupdateReadme.test.ts
64 lines (48 loc) · 1.7 KB
/
updateReadme.test.ts
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
57
58
59
60
61
62
63
64
import { describe, expect, it, vi } from "vitest";
import { updateReadme } from "./updateReadme.js";
const mockAppendFile = vi.fn();
vi.mock("node:fs/promises", () => ({
default: {
get appendFile() {
return mockAppendFile;
},
},
}));
const mockReadFileSafe = vi.fn();
vi.mock("../shared/readFileSafe.js", () => ({
get readFileSafe() {
return mockReadFileSafe;
},
}));
describe("updateReadme", () => {
it("adds a notice when the file does not contain it already", async () => {
mockReadFileSafe.mockResolvedValue("");
await updateReadme();
expect(mockAppendFile.mock.calls).toMatchInlineSnapshot(`
[
[
"./README.md",
"
<!-- You can remove this notice if you don't want it 🙂 no worries! -->
> 💙 This package was templated with [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).
",
],
]
`);
});
it("doesn't add a notice when the file contains it already", async () => {
mockReadFileSafe.mockResolvedValue(`
<!-- You can remove this notice if you don't want it 🙂 no worries! -->
> 💙 This package was templated using [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).
`);
await updateReadme();
expect(mockAppendFile.mock.calls).toMatchInlineSnapshot("[]");
});
it("doesn't add a notice when the file contains an older version of it already", async () => {
mockReadFileSafe.mockResolvedValue(`
💙 This package is based on [@JoshuaKGoldberg](https://github.com/JoshuaKGoldberg)'s [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).
`);
await updateReadme();
expect(mockAppendFile.mock.calls).toMatchInlineSnapshot("[]");
});
});