-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathreadLogo.test.ts
168 lines (136 loc) · 5.4 KB
/
readLogo.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import { describe, expect, it, vi } from "vitest";
import { readLogo } from "./readLogo.js";
const mockReadLogoSizing = vi.fn().mockResolvedValue({});
vi.mock("./readLogoSizing.js", () => ({
get readLogoSizing() {
return mockReadLogoSizing;
},
}));
describe(readLogo, () => {
describe("logo", () => {
it("resolves undefined when an image cannot be found", async () => {
const logo = await readLogo(() => Promise.resolve(`nothing.`));
expect(logo).toBeUndefined();
});
it("resolves undefined when the found image has no src", async () => {
const logo = await readLogo(() => Promise.resolve(`\n<img src=""/>`));
expect(logo).toBeUndefined();
});
it("resolves undefined when the found image is an All Contributors badge", async () => {
const logo = await readLogo(() =>
Promise.resolve(
`\n<img alt="All Contributors: 1" src="https://img.shields.io/badge/all_contributors-1-21bb42.svg" />`,
),
);
expect(logo).toBeUndefined();
});
it("resolves undefined when the found image is a shields.io badge", async () => {
const logo = await readLogo(() =>
Promise.resolve(
`\n<img alt="TypeScript: Strict" src="https://img.shields.io/badge/typescript-strict-21bb42.svg" />`,
),
);
expect(logo).toBeUndefined();
});
it("parses when found in an unquoted string", async () => {
const logo = await readLogo(() =>
Promise.resolve(`
<img src=abc/def.jpg/>`),
);
expect(logo).toEqual({
alt: "Project logo",
src: "abc/def.jpg",
});
});
it("parses when found in a single quoted string", async () => {
const logo = await readLogo(() =>
Promise.resolve(`
<img src='abc/def.jpg'/>`),
);
expect(logo).toEqual({
alt: "Project logo",
src: "abc/def.jpg",
});
});
it("parses when found in a double quoted string", async () => {
const logo = await readLogo(() =>
Promise.resolve(`
<img src="abc/def.jpg"/>`),
);
expect(logo).toEqual({
alt: "Project logo",
src: "abc/def.jpg",
});
});
it("includes alt text when it exists in double quotes", async () => {
const logo = await readLogo(() =>
Promise.resolve(`
<img alt="Project logo: a fancy circle" src="abc/def.jpg"/>`),
);
expect(logo).toEqual({
alt: "Project logo: a fancy circle",
src: "abc/def.jpg",
});
});
it("includes alt text when it exists in single quotes", async () => {
const logo = await readLogo(() =>
Promise.resolve(`
<img alt='Project logo: a fancy circle' src='abc/def.jpg'/>`),
);
expect(logo).toEqual({
alt: "Project logo: a fancy circle",
src: "abc/def.jpg",
});
});
it("includes sizing when readLogoSizing returns sizing", async () => {
const sizing = { height: 117, width: 128 };
mockReadLogoSizing.mockReturnValueOnce(sizing);
const logo = await readLogo(() =>
Promise.resolve(`
<img alt='Project logo: a fancy circle' height='117px' src='abc/def.jpg' width=' 117px'/>`),
);
expect(logo).toEqual({
alt: "Project logo: a fancy circle",
src: "abc/def.jpg",
...sizing,
});
});
it("parses when found after a badge image", async () => {
const logo = await readLogo(() =>
Promise.resolve(`
<a href="#contributors" target="_blank"><img alt="👪 All Contributors: 48" src="https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-48-21bb42.svg" /></a>
<img src=abc/def.jpg/>
`),
);
expect(logo).toEqual({
alt: "Project logo",
src: "abc/def.jpg",
});
});
it("parses when found after an h1 and many badge images", async () => {
const logo = await readLogo(() =>
Promise.resolve(`
<h1 align="center">Create TypeScript App</h1>
<p align="center">Quickstart-friendly TypeScript template with comprehensive, configurable, opinionated tooling. 🎁</p>
<p align="center">
<!-- prettier-ignore-start -->
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<a href="#contributors" target="_blank"><img alt="👪 All Contributors: 48" src="https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-48-21bb42.svg" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->
<!-- prettier-ignore-end -->
<a href="https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="🤝 Code of Conduct: Kept" src="https://img.shields.io/badge/%F0%9F%A4%9D_code_of_conduct-kept-21bb42" /></a>
<a href="https://codecov.io/gh/JoshuaKGoldberg/create-typescript-app" target="_blank"><img alt="🧪 Coverage" src="https://img.shields.io/codecov/c/github/JoshuaKGoldberg/create-typescript-app?label=%F0%9F%A7%AA%20coverage" /></a>
<a href="https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/LICENSE.md" target="_blank"><img alt="📝 License: MIT" src="https://img.shields.io/badge/%F0%9F%93%9D_license-MIT-21bb42.svg"></a>
<a href="http://npmjs.com/package/create-typescript-app"><img alt="📦 npm version" src="https://img.shields.io/npm/v/create-typescript-app?color=21bb42&label=%F0%9F%93%A6%20npm" /></a>
<img alt="💪 TypeScript: Strict" src="https://img.shields.io/badge/%F0%9F%92%AA_typescript-strict-21bb42.svg" />
</p>
<img align="right" alt="Project logo: the TypeScript blue square with rounded corners, but a plus sign instead of 'TS'" src="./docs/create-typescript-app.png">
`),
);
expect(logo).toEqual({
alt: "Project logo: the TypeScript blue square with rounded corners, but a plus sign instead of 'TS'",
src: "./docs/create-typescript-app.png",
});
});
});
});