-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
116 lines (98 loc) · 2.55 KB
/
index.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
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
/**
* can't get module augmentation to work
* @type {any}
*/
const expect = require("expect");
const path = require("path");
const playwright = require("playwright");
const {
awaitNvdaRecording,
createSpeechRecorder,
} = require("screen-reader-testing-library");
/**
* @param {object} config
* @param {import('playwright').Browser} config.browser
* @param {string} config.logFilePath
*/
async function run(config) {
const { browser, logFilePath } = config;
const context = await browser.newContext();
const page = await context.newPage();
const recorder = createSpeechRecorder(logFilePath);
expect.extend({
/**
* @param {() => Promise<void>} fn
* @param {string[]} expectedLines
*/
async toCreateSpeech(fn, expectedLines) {
// move to end
await recorder.start();
await fn();
const actualLines = await recorder.stop();
expect(actualLines).toEqual(expectedLines);
return { pass: true };
},
});
await page.goto("https://5f6a0f0de73ecc00085cbbe4--material-ui.netlify.app/");
// Without bringing it to front the adress bar will still be focused.
// NVDA wouldn't record any page actions
await page.bringToFront();
await awaitNvdaRecording();
await expect(async () => {
await page.keyboard.press("s");
}).toCreateSpeech([
["banner landmark"],
[
"Search",
"combo box",
"expanded",
"has auto complete",
"editable",
"Search…",
"blank",
],
]);
await expect(async () => {
await page.keyboard.type("Rating");
}).toCreateSpeech([]);
await expect(async () => {
await page.keyboard.press("ArrowDown");
}).toCreateSpeech([["list"], ["Link to the result", "1 of 5"]]);
}
/**
* @param {object} config
* @param {"chromium" | "firefox" | "webkit"} config.browserType
*/
async function setup(config) {
const { browserType } = config;
const [browser] = await Promise.all([
playwright[browserType].launch({ headless: false }),
]);
async function tearDown() {
console.log("teardown");
return Promise.allSettled([browser.close()]);
}
return { browser: browser, tearDown };
}
async function main() {
const browserType = "chromium";
const [logFilePath] = process.argv.slice(2);
if (typeof logFilePath !== "string") {
throw new TypeError("No path to logfile given!");
}
if (!path.isAbsolute(logFilePath)) {
throw new TypeError("The path to the logfile must be absolute!");
}
const { browser, tearDown } = await setup({
browserType,
});
try {
await run({ browser, logFilePath });
} finally {
tearDown();
}
}
main().catch((error) => {
console.error(error);
process.exit(error.code || 1);
});