-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.test.js
170 lines (162 loc) · 9.2 KB
/
index.test.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
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
169
import {test, expect} from 'vitest';
import {Window} from 'happy-dom';
import shortenUrl, {applyToLink} from './index.js';
const currentLocation = 'https://github.com/fregante/shorten-repo-url/issue/1';
globalThis.document = new Window({url: currentLocation}).document;
expect.addSnapshotSerializer({
serialize(value) {
return value;
},
test(value) {
return value;
},
});
const urls = [
'https://github.com/fregante/shorten-repo-url/',
'https://github.com/fregante/shorten-repo-url/?tab=readme-ov-file',
'https://github.com/fregante/shorten-repo-url/tree/v0.12',
'https://github.com/fregante/shorten-repo-url/tree/d71718db6aa4feb8dc10edbad1134472468e971a',
'https://github.com/nodejs/node/',
'https://github.com/nodejs/shorten-repo-url/',
'https://github.com/nodejs/node/tree/v0.12',
'https://github.com/nodejs/node/tree/d71718db6aa4feb8dc10edbad1134472468e971a',
'https://github.com/fregante/shorten-repo-url/tree/master/doc',
'https://github.com/fregante/shorten-repo-url/tree/v0.12/doc',
'https://github.com/fregante/shorten-repo-url/tree/d71718db6aa4feb8dc10edbad1134472468e971a/doc',
'https://github.com/nodejs/node/tree/master/doc',
'https://github.com/nodejs/node/tree/v0.12/doc',
'https://github.com/nodejs/node/tree/d71718db6aa4feb8dc10edbad1134472468e971a/doc',
'https://github.com/fregante/shorten-repo-url/blob/master/.gitignore',
'https://github.com/fregante/shorten-repo-url/blob/v0.12/.gitignore',
'https://github.com/fregante/shorten-repo-url/blob/cc8fc46/.gitignore',
'https://github.com/fregante/shorten-repo-url/blob/main/한글.txt',
'https://github.com/nodejs/node/blob/master/.gitignore',
'https://github.com/nodejs/node/blob/v0.12/.gitignore',
'https://github.com/nodejs/node/blob/cc8fc46/.gitignore',
'https://github.com/fregante/shorten-repo-url/blame/master/.gitignore',
'https://github.com/fregante/shorten-repo-url/blame/v0.12/.gitignore',
'https://github.com/fregante/shorten-repo-url/blame/cc8fc46/.gitignore',
'https://github.com/nodejs/node/blame/master/.gitignore',
'https://github.com/nodejs/node/blame/v0.12/.gitignore',
'https://github.com/nodejs/node/blame/cc8fc46/.gitignore',
'https://github.com/fregante/shorten-repo-url/commits/master/.gitignore',
'https://github.com/fregante/shorten-repo-url/commits/v0.12/.gitignore',
'https://github.com/fregante/shorten-repo-url/commits/cc8fc46/.gitignore',
'https://github.com/nodejs/node/commits/master/.gitignore',
'https://github.com/nodejs/node/commits/v0.12/.gitignore',
'https://github.com/nodejs/node/commits/cc8fc46/.gitignore',
'https://github.com/fregante/shorten-repo-url/commit/cc8fc46.diff',
'https://github.com/fregante/shorten-repo-url/commit/cc8fc46.patch',
'https://github.com/nodejs/node/commit/cc8fc46.diff',
'https://github.com/nodejs/node/commit/cc8fc46.patch',
'https://github.com/fregante/shorten-repo-url/releases/tag/v0.12.0',
'https://github.com/nodejs/node/releases/tag/v0.12.0',
'https://github.com/fregante/shorten-repo-url/milestone/25',
'https://github.com/fregante/shorten-repo-url/compare/d71718db6aa4feb8dc10edbad1134472468e971a',
'https://github.com/fregante/shorten-repo-url/compare/master',
'https://github.com/fregante/shorten-repo-url/compare/master...master',
'https://github.com/nodejs/node/compare/d71718db6aa4feb8dc10edbad1134472468e971a',
'https://github.com/nodejs/node/compare/master',
'https://github.com/nodejs/node/compare/master...master',
'https://github.com/nodejs/node/milestone/25',
'https://github.com/fregante/shorten-repo-url/labels/npm',
'https://github.com/nodejs/node/labels/npm',
'https://github.com/nodejs/node/labels/Please%21%20♥',
'https://github.com/refined-github/refined-github/labels/Please%21%20♥%EF%B8%8E',
'https://github.com/fregante/shorten-repo-url/archive/6.4.1.zip',
'https://github.com/fregante/shorten-repo-url/releases/download/6.4.1/now-macos',
'https://github.com/zeit/now-cli/archive/6.4.1.zip',
'https://github.com/zeit/now-cli/releases/download/6.4.1/now-macos',
'https://github.com/bfred-it/shorten-repo-url/network/dependents',
'https://github.com/bfred-it/shorten-repo-url/network/dependencies',
'https://github.com/network/dependencies',
'https://github.com/bfred-it/shorten-repo-url/wiki',
'https://github.com/fregante/shorten-repo-url/pulse',
'https://github.com/fregante/shorten-repo-url/labels',
'https://github.com/fregante/shorten-repo-url/compare',
'https://github.com/fregante/shorten-repo-url/network',
'https://github.com/fregante/shorten-repo-url/projects',
'https://github.com/fregante/shorten-repo-url/releases',
'https://github.com/fregante/shorten-repo-url/milestones',
'https://github.com/fregante/shorten-repo-url/contributors',
'https://github.com/fregante/shorten-repo-url/pull/123/files',
'https://github.com/nodejs/node/pull/123/files',
'https://github.com/fregante/shorten-repo-url/pull/123/commits',
'https://github.com/fregante/shorten-repo-url/pull/123/checks',
'https://github.com/nodejs/node/wiki',
'https://github.com/nodejs/node/pulse',
'https://github.com/nodejs/node/labels',
'https://github.com/nodejs/node/compare',
'https://github.com/nodejs/node/network',
'https://github.com/nodejs/node/projects',
'https://github.com/nodejs/node/releases',
'https://github.com/nodejs/node/milestones',
'https://github.com/nodejs/node/contributors',
'https://github.com/nodejs/node/graphs/commit-activity',
'https://rawgit.com/fregante/shorten-repo-url/master/.gitignore',
'https://cdn.rawgit.com/fregante/shorten-repo-url/v0.12/.gitignore',
'https://cdn.rawgit.com/fregante/shorten-repo-url/d71718db/.gitignore',
'https://raw.githubusercontent.com/fregante/shorten-repo-url/master/.gitignore',
'https://raw.githubusercontent.com/fregante/shorten-repo-url/v0.12/.gitignore',
'https://raw.githubusercontent.com/fregante/shorten-repo-url/d71718db/.gitignore',
'https://rawgit.com/nodejs/node/master/.gitignore',
'https://cdn.rawgit.com/nodejs/node/v0.12/.gitignore',
'https://cdn.rawgit.com/nodejs/node/d71718db/.gitignore',
'https://raw.githubusercontent.com/nodejs/node/master/.gitignore',
'https://raw.githubusercontent.com/nodejs/node/v0.12/.gitignore',
'https://raw.githubusercontent.com/nodejs/node/d71718db/.gitignore',
'https://github.com/sindresorhus',
'https://github.com/nodejs',
'https://github.com/pulls',
'https://github.com/issues',
'https://github.com/trending',
'https://github.com/features',
'https://github.com/marketplace',
'https://github.com/trending/developers',
'https://github.com/settings/profile',
'https://github.com/',
'https://github.com/fregante/shorten-repo-url/issues',
'https://github.com/fregante/shorten-repo-url/issues?q=wow',
'https://github.com/fregante/shorten-repo-url/issues?q=is%3Aissue++is%3Aopen+sort%3Aupdated-desc+&unrelated=true',
'https://github.com/issues?q=is%3Aissue++is%3Aopen+sort%3Aupdated-desc+&unrelated=true',
'https://github.com/pulls?q=is%3Apr++is%3Aopen+sort%3Aupdated-desc+&unrelated=true',
'https://github.com/sindresorhus/notifier-for-github/pull/253/files/6b4489d417c9425dc27c5fb8d6b4a8518debd035..60cdcf3c3646164441bf8f037cef620479cdec59',
'https://togithub.com/fregante/shorten-repo-url/issues/25',
'https://togithub.com/fregante/shorten-repo-url/issues/28#issue-850900171',
'https://togithub.com/fregante/shorten-repo-url/pull/32',
'https://togithub.com/fregante/shorten-repo-url/pull/32/files',
'https://togithub.com/fregante/shorten-repo-url/pull/33#pullrequestreview-801229042',
'https://togithub.com/fregante/shorten-repo-url/pull/33#discussion_r750069394',
'https://togithub.com/nodejs/node/pull/123',
'https://togithub.com/nodejs/node/pull/123/files',
'https://togithub.com/fregante/shorten-repo-url/commit/98c6175b0cbd4caca71d24e68e57b942b0dfb549',
'https://togithub.com/refined-github/refined-github/commit/4f270c4f50e0a2a20085a6e92095117f10340322',
'https://togithub.com/refined-github/refined-github/commit/e81a9646b448d90c7e02ab41332cab0507dccbbd#commitcomment-60089354',
'https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22#3-it-doesnt-require-options',
'https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22#',
'https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22',
'https://github.com/fregante/shorten-repo-url/wiki/%22Can-you-add-this-feature%3F%22',
'https://github.com/scarf005/hangul-test/wiki/한글-위키-페이지',
'https://github.com/scarf005/hangul-test/wiki/한글-위키-페이지#한글-헤딩',
'https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement#parameters',
'https://www.google.com/',
'https://wwww.google.com/',
'http://www.google.com/',
'https://www.npmjs.com/',
'https://www.npmjs.com/packaasdge/node',
'https://example.com/nodejs/node/blob/cc8fc46/.gitignore',
'https://example.site/한글로-된-URL',
'https://한글로-된-경로.com/하위경로#한글-해시',
];
test.each(urls)('%s', url => {
const shortened = shortenUrl(url, currentLocation);
expect(shortened).toMatchSnapshot();
const a = document.createElement('a');
a.href = url;
// The URL might contain CJK characters, but after it's passed to a.href it's encoded
const correctlyEncodedUrl = a.href;
a.textContent = url;
applyToLink(a, currentLocation);
expect(a.href, 'applyToLink should not alter the href').toBe(correctlyEncodedUrl);
expect(a.innerHTML).toBe(shortened);
});