summaryrefslogtreecommitdiff
path: root/source/github-helpers/selectors.test.ts
blob: 060e5352f10178f5b8717ade61231b72e8e8027b (plain) (blame)
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
import mem from 'mem';
import {test, assert, describe} from 'vitest';
import {JSDOM} from 'jsdom';

import * as exports from './selectors.js';

const fetchDocument = mem(async (url: string): Promise<JSDOM> => JSDOM.fromURL(url));

describe.concurrent('selectors', () => {
	// Exclude URL arrays
	const selectors: Array<[name: string, selector: string]> = [];
	for (const [name, selector] of Object.entries(exports)) {
		if (!Array.isArray(selector)) {
			selectors.push([name, selector]);
		}
	}

	test.each(selectors)('%s', async (name, selector) => {
		// @ts-expect-error Index signature bs
		const urls = exports[name + '_'] as string[];

		assert.isArray(urls, `No URLs defined for "${name}"`);
		await Promise.all(urls.map(async url => {
			const {window} = await fetchDocument(url);
			assert.isDefined(window.document.querySelector(selector));
		}));
	});
});