-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathesmTest.mjs
More file actions
61 lines (51 loc) · 1.72 KB
/
Copy pathesmTest.mjs
File metadata and controls
61 lines (51 loc) · 1.72 KB
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
import defaultExport from '../dist/index.mjs';
import { AxeBuilder } from '../dist/index.mjs';
import assert from 'assert';
import * as webdriverio from 'webdriverio';
import { pathToFileURL } from 'url';
import { join } from 'path';
import { fixturesPath } from 'axe-test-fixtures';
import { spawn } from 'child_process';
import { getFreePort, connectToChromeDriver } from './testUtils.js';
const chromedriverPath =
process.env.CHROMEDRIVER_TEST_PATH ||
(await import('chromedriver')).default.path;
const chromeBinary = process.env.CHROME_TEST_PATH;
assert(typeof defaultExport === 'function', 'default export is not a function');
assert(typeof AxeBuilder === 'function', 'named export is not a function');
assert(
defaultExport === AxeBuilder,
'default and named export are not the same'
);
async function integrationTest() {
const port = await getFreePort();
const chromedriverProcess = spawn(chromedriverPath, [
`--port=${port}`
], { stdio: 'inherit' });
await connectToChromeDriver(port);
let client;
try {
const options = {
path: '/',
hostname: 'localhost',
port,
capabilities: {
browserName: 'chrome',
'goog:chromeOptions': {
args: ['--headless', '--no-sandbox'],
...(chromeBinary ? { binary: chromeBinary } : {})
}
},
logLevel: 'error'
};
client = await webdriverio.remote(options);
await client.url(pathToFileURL(join(fixturesPath, 'index.html')).toString());
const results = await new defaultExport({ client }).analyze();
assert(results.violations.length > 0, 'could not find violations');
} finally {
await client?.deleteSession();
chromedriverProcess.kill();
}
process.exit(0);
}
integrationTest();