-
Notifications
You must be signed in to change notification settings - Fork 16
/
browser.js
33 lines (28 loc) · 931 Bytes
/
browser.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
const path = require('node:path');
const { readFileSync } = require('node:fs');
const { Script } = require('node:vm');
const test = require('ava');
const { JSDOM, VirtualConsole } = require('jsdom');
const virtualConsole = new VirtualConsole();
virtualConsole.sendTo(console);
const script = new Script(
readFileSync(path.join(__dirname, '..', 'dist', 'url-regex-safe.min.js'))
);
const dom = new JSDOM(``, {
url: 'http://localhost:3000/',
referrer: 'http://localhost:3000/',
contentType: 'text/html',
includeNodeLocations: true,
resources: 'usable',
runScripts: 'dangerously',
virtualConsole
});
dom.runVMScript(script);
test('should work in the browser', (t) => {
t.true(typeof dom.window.urlRegexSafe === 'function');
t.true(dom.window.urlRegexSafe({ exact: true }).test('github.com'));
t.deepEqual(
'some long string with url.com in it'.match(dom.window.urlRegexSafe()),
['url.com']
);
});