Recently Written · git

subread-extension

Show your own .srt over a YouTube video, in time with it. Chrome and Firefox.

git clone https://github.com/equwal/subread-extension

Log | Files | Refs


tests/more-apps.test.cjs (1932 bytes)

1 /* node --test tests/more-apps.test.cjs */
2 const test = require('node:test');
3 const assert = require('node:assert/strict');
4 const fs = require('node:fs');
5 const path = require('node:path');
6 
7 const read = (file) => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
8 
9 // The links in the "More apps" section of the popup: the name, the address and the attributes of each.
10 function moreApps() {
11   const section = read('popup.html').match(/<details id="more-apps"[^>]*>([\s\S]*?)<\/details>/);
12   assert.ok(section, 'popup.html has no More apps section');
13   return [...section[1].matchAll(/<a ([^>]*)>([^<]*)<\/a>/g)].map(([, attrs, name]) => ({
14     name,
15     attrs,
16     href: (attrs.match(/href="([^"]*)"/) || [])[1],
17   }));
18 }
19 
20 test('More apps links to the other apps with https, each in a new tab', () => {
21   const apps = moreApps();
22   assert.ok(apps.length > 1);
23   for (const app of apps) {
24     assert.match(app.href, /^https:\/\/[^?#]+$/, app.name);   // no tracking parameters
25     assert.match(app.attrs, /target="_blank"/, app.name);
26     assert.match(app.attrs, /rel="noopener"/, app.name);
27   }
28   assert.equal(new Set(apps.map((app) => app.href)).size, apps.length);
29   assert.equal(apps.at(-1).href, 'https://recentlywritten.com/projects.html');
30 });
31 
32 test('More apps does not list the add-on itself', () => {
33   for (const app of moreApps()) assert.doesNotMatch(app.href, /subread-extension/, app.name);
34 });
35 
36 test('the add-on asks for no new permission and puts no link into YouTube pages', () => {
37   const manifest = JSON.parse(read('manifest.json'));
38   assert.deepEqual(manifest.permissions, ['storage']);
39   for (const key of ['host_permissions', 'optional_permissions', 'optional_host_permissions']) {
40     assert.equal(manifest[key], undefined, key);
41   }
42   for (const script of manifest.content_scripts) {
43     for (const file of script.js) assert.doesNotMatch(read(file), /More apps|recentlywritten\.com/, file);
44   }
45 });