-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
78 lines (60 loc) · 2.62 KB
/
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
import path from 'node:path';
import {writeFile} from 'node:fs/promises';
import {fileURLToPath} from 'node:url';
import t from 'libtap';
import {testBrowser, grabImage} from '@cfware/tap-selenium-manager';
import {FastifyTestHelper, globToCustomGetters} from '@cfware/fastify-test-helper';
const cwd = path.resolve(path.dirname(fileURLToPath(import.meta.url)));
const imageFile = fullname => path.join(
cwd,
'tap-snapshots',
fullname.replaceAll(/[^\w.-]+/gu, '-')
);
const processImage = async (t, element, imageID) => {
const image64 = await grabImage(element);
t.matchSnapshot(image64, imageID);
await writeFile(imageFile(`${t.fullname}-${imageID}.png`), image64);
};
const pages = {
async 'nav-menu.html'(t, selenium) {
const element = await selenium.findElement({id: 'test'});
await processImage(t, element, 'initial');
await selenium.executeScript(element => element.update(), element);
await processImage(t, element, 'updated');
const section1 = await selenium.findElement({id: 'section1'});
await section1.click();
await processImage(t, element, 'clicked');
await selenium.executeScript(() => {
document.querySelector('#item1a').hidden = true;
});
await processImage(t, element, 'hidden-1');
await selenium.executeScript(() => {
document.querySelector('#item1a').hidden = false;
document.querySelector('#item2a').hidden = true;
});
await processImage(t, element, 'hidden-2');
},
async 'nav-empty.html'(t, selenium) {
/* Cannot screen capture a completely empty nav-menu. */
const container = await selenium.findElement({id: 'container'});
const element = await selenium.findElement({id: 'test'});
await processImage(t, container, 'initial');
await selenium.executeScript(element => element.update(), element);
await processImage(t, container, 'updated');
},
async 'nav-no-hrefs.html'(t, selenium) {
const element = await selenium.findElement({id: 'test'});
await processImage(t, element, 'initial');
await selenium.executeScript(element => element.update(), element);
await processImage(t, element, 'updated');
await selenium.executeScript(element => element.update(), element);
await processImage(t, element, 'updated2');
}
};
const daemon = new FastifyTestHelper({
customGetters: globToCustomGetters('nav-*.js', {cwd})
});
t.test('browsers', async t => {
await testBrowser(t, 'firefox', daemon, pages);
await testBrowser(t, 'chrome', daemon, pages);
});