-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserscripts.test.js
More file actions
192 lines (169 loc) · 9.08 KB
/
Copy pathuserscripts.test.js
File metadata and controls
192 lines (169 loc) · 9.08 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import { readFile } from 'node:fs/promises';
import test from 'node:test';
import assert from 'node:assert/strict';
const workflowPath = new URL('../.github/workflows/check.yml', import.meta.url);
const readmePath = new URL('../README.md', import.meta.url);
const scriptPath = new URL('../scripts/ttyd-osc52-clipboard/ttyd-osc52-clipboard.user.js', import.meta.url);
const freePressScriptPath = new URL('../thefp.js', import.meta.url);
const makefilePath = new URL('../Makefile', import.meta.url);
const abookScriptPath = new URL('../scripts/abook-nzb-helpers/abook-nzb-helpers.user.js', import.meta.url);
const nzbkingScriptPath = new URL(
'../scripts/nzbking-named-downloader/nzbking-named-downloader.user.js',
import.meta.url,
);
const userscripts = [
{
name: 'Free Press Audio Downloader',
path: 'thefp.js',
url: freePressScriptPath,
version: '0.0.6',
},
{
name: 'Abook NZB Helpers',
path: 'scripts/abook-nzb-helpers/abook-nzb-helpers.user.js',
url: abookScriptPath,
version: '1.0.2',
},
{
name: 'NZBKing Named Downloader',
path: 'scripts/nzbking-named-downloader/nzbking-named-downloader.user.js',
url: nzbkingScriptPath,
version: '1.0.2',
},
{
name: 'ttyd OSC52 Clipboard',
path: 'scripts/ttyd-osc52-clipboard/ttyd-osc52-clipboard.user.js',
url: scriptPath,
version: '0.1.1',
},
];
async function readScript() {
return readFile(scriptPath, 'utf8');
}
test('userscript metadata is public and installable', async () => {
const source = await readScript();
assert.match(source, /\/\/ ==UserScript==/);
assert.match(source, /@name\s+ttyd OSC52 Clipboard/);
assert.match(source, /@version\s+0\.1\.1/);
assert.match(source, /@description\s+Copy tmux OSC52 clipboard sequences from ttyd\/xterm\.js/);
assert.match(source, /@author\s+jeeftor/);
assert.match(source, /@downloadURL\s+https:\/\/raw\.githubusercontent\.com\/jeeftor\/userScripts\/master\/scripts\/ttyd-osc52-clipboard\/ttyd-osc52-clipboard\.user\.js/);
assert.match(source, /@updateURL\s+https:\/\/raw\.githubusercontent\.com\/jeeftor\/userScripts\/master\/scripts\/ttyd-osc52-clipboard\/ttyd-osc52-clipboard\.user\.js/);
assert.match(source, /@match\s+http:\/\/\*\/\*/);
assert.match(source, /@match\s+https:\/\/\*\/\*/);
assert.match(source, /@grant\s+GM_setClipboard/);
assert.match(source, /@grant\s+GM_getValue/);
assert.match(source, /@grant\s+GM_setValue/);
assert.match(source, /@grant\s+GM_registerMenuCommand/);
assert.doesNotMatch(source, /vookie|terminal\.example\.com|ssh\.example\.org/i);
});
test('personal hosts and debug state are stored outside git', async () => {
const source = await readScript();
assert.match(source, /GM_getValue\('allowedHosts', \[\]\)/);
assert.match(source, /GM_setValue\('allowedHosts'/);
assert.match(source, /GM_getValue\('debug', false\)/);
assert.match(source, /GM_setValue\('debug'/);
assert.match(source, /GM_registerMenuCommand\('Allow this host'/);
assert.match(source, /GM_registerMenuCommand\('Toggle debug'/);
assert.match(source, /getAllowedHosts\(\)\.includes\(location\.hostname\)/);
});
test('OSC52 handling copies decoded payloads and suppresses unsupported input', async () => {
const source = await readScript();
assert.match(source, /registerOscHandler\(52/);
assert.match(source, /return true;/);
assert.match(source, /payload === '\?'/);
assert.match(source, /GM_setClipboard\(text, 'text'\)/);
assert.match(source, /new TextDecoder\(\)\.decode\(bytes\)/);
assert.match(source, /setInterval/);
assert.match(source, /attempts >= 60/);
});
test('existing Free Press script is preserved at the root update URL path', async () => {
const source = await readFile(freePressScriptPath, 'utf8');
assert.match(source, /@name\s+Free Press Audio Downloader/);
assert.match(source, /@author\s+jeeftor/);
assert.match(source, /@match\s+https:\/\/www\.thefp\.com\/\*/);
assert.match(source, /@match\s+https:\/\/\*\.substack\.com\/\*/);
assert.match(source, /@version\s+0\.0\.6/);
assert.match(source, /@grant\s+GM_setClipboard/);
assert.match(source, /GM_setClipboard\(src, 'text'\)/);
assert.match(source, /@updateURL\s+https:\/\/raw\.githubusercontent\.com\/jeeftor\/userScripts\/master\/thefp\.js/);
});
test('Abook NZB Helpers is tracked as an installable userscript', async () => {
const source = await readFile(abookScriptPath, 'utf8');
assert.match(source, /@name\s+Abook NZB Helpers/);
assert.match(source, /@version\s+1\.0\.2/);
assert.match(source, /@description\s+Add NZB search, NZBDonkey, and copy helpers to Abook topic pages\./);
assert.match(source, /@author\s+jeeftor/);
assert.match(source, /@downloadURL\s+https:\/\/raw\.githubusercontent\.com\/jeeftor\/userScripts\/master\/scripts\/abook-nzb-helpers\/abook-nzb-helpers\.user\.js/);
assert.match(source, /@updateURL\s+https:\/\/raw\.githubusercontent\.com\/jeeftor\/userScripts\/master\/scripts\/abook-nzb-helpers\/abook-nzb-helpers\.user\.js/);
assert.match(source, /@grant\s+GM_setClipboard/);
assert.match(source, /@match\s+https:\/\/abook\.link\/book\/index\.php\?topic=\*/);
assert.match(source, /@noframes/);
assert.match(source, /const NZBLNK_ICON_SRC = 'data:image\/svg\+xml/);
assert.match(source, /function textContentOf/);
assert.match(source, /function parsePostTimestamp/);
assert.match(source, /if \(typeof saythanks !== 'undefined'/);
assert.match(source, /function inject_nzbdonkey/);
assert.match(source, /function inject_search/);
assert.match(source, /https:\/\/nzbking\.com\/search\/\?q=/);
});
test('NZBKing Named Downloader is tracked as an installable userscript', async () => {
const source = await readFile(nzbkingScriptPath, 'utf8');
assert.match(source, /@name\s+NZBKing Named Downloader/);
assert.match(source, /@version\s+1\.0\.2/);
assert.match(source, /@description\s+Download NZBKing NZB files with useful filenames from URL, clipboard, or page data\./);
assert.match(source, /@author\s+jeeftor/);
assert.match(source, /@downloadURL\s+https:\/\/raw\.githubusercontent\.com\/jeeftor\/userScripts\/master\/scripts\/nzbking-named-downloader\/nzbking-named-downloader\.user\.js/);
assert.match(source, /@updateURL\s+https:\/\/raw\.githubusercontent\.com\/jeeftor\/userScripts\/master\/scripts\/nzbking-named-downloader\/nzbking-named-downloader\.user\.js/);
assert.match(source, /@match\s+https:\/\/nzbking\.com\/\*/);
assert.match(source, /@noframes/);
assert.match(source, /const DEBUG = false/);
assert.match(source, /async function getClipboardText/);
assert.match(source, /function sanitizeFilename/);
assert.match(source, /function scanForNzbLinks/);
assert.match(source, /new MutationObserver/);
assert.match(source, /querySelectorAll\('a\[href\^="\/nzb:"\]'\)/);
});
test('Makefile can bump versions for changed userscripts or all userscripts', async () => {
const source = await readFile(makefilePath, 'utf8');
assert.match(source, /check/);
assert.match(source, /changed-versions/);
assert.match(source, /all-versions/);
assert.match(source, /scripts\/bump-userscript-versions\.mjs --changed/);
assert.match(source, /scripts\/bump-userscript-versions\.mjs --all/);
assert.match(source, /scripts\/check-userscript-version-bumps\.mjs/);
assert.match(source, /node --check/);
});
test('every userscript has required update metadata', async () => {
for (const userscript of userscripts) {
const source = await readFile(userscript.url, 'utf8');
const rawUrl = `https://raw.githubusercontent.com/jeeftor/userScripts/master/${userscript.path}`;
assert.match(source, /\/\/ ==UserScript==/, userscript.path);
assert.match(source, /@name\s+\S+/, userscript.path);
assert.match(source, /@description\s+\S+/, userscript.path);
assert.match(source, /@author\s+jeeftor/, userscript.path);
assert.match(source, new RegExp(`@version\\s+${userscript.version.replaceAll('.', '\\.')}`), userscript.path);
assert.match(source, /@match\s+\S+/, userscript.path);
assert.match(source, new RegExp(`@downloadURL\\s+${rawUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`), userscript.path);
assert.match(source, new RegExp(`@updateURL\\s+${rawUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`), userscript.path);
}
});
test('README exposes raw install links for each userscript', async () => {
const source = await readFile(readmePath, 'utf8');
for (const userscript of userscripts) {
const rawUrl = `https://raw.githubusercontent.com/jeeftor/userScripts/master/${userscript.path}`;
assert.match(source, new RegExp(`\\[${userscript.name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\]`), userscript.name);
assert.match(source, new RegExp(rawUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')), userscript.name);
}
});
test('GitHub Actions runs the repository check target', async () => {
const source = await readFile(workflowPath, 'utf8');
assert.match(source, /name: Check/);
assert.match(source, /on:/);
assert.match(source, /pull_request:/);
assert.match(source, /push:/);
assert.match(source, /npm test/);
assert.match(source, /make check/);
assert.match(source, /Check userscript version bumps/);
assert.match(source, /scripts\/check-userscript-version-bumps\.mjs/);
});