/
render-test-pages.mjs
executable file
·69 lines (58 loc) · 2.04 KB
/
render-test-pages.mjs
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
#!/usr/bin/env node
import { Browser, snapshotMarkup } from '@progress/kendo-e2e';
import { createServer } from 'http-server';
import { globSync } from 'glob';
import fs from 'fs';
import path from 'path';
const PORT = 18111;
const HOST = 'localhost';
const TESTS_PATH = './packages/html/dist';
const OUTPUT_PATH = './tests';
const COMPONENT_PAGE_EXT = 'app.js';
function pathUrl(url) {
return `http://${HOST}:${PORT}/${path.dirname(url).replace('./', '')}`;
}
async function loadUrl(browser, url) {
await browser.wait(async() => {
try {
await browser.navigateTo(url);
return true;
} catch (error) {
return false;
}
}, 10000, `Failed to load ${url}`, 500);
}
const browser = new Browser();
const server = createServer({
root: './',
port: PORT
});
server.listen(PORT, HOST, async() => {
const files = globSync(`${TESTS_PATH}/!(utils)/**/${COMPONENT_PAGE_EXT}`, { dotRelative: true });
const pages = files.map(path => [ path, pathUrl(path) ]);
for (let i = 0; i < pages.length; i++) {
const [ filePath, url ] = pages[i];
await loadUrl(browser, url);
const [ /** index.html */, folderName, /** /tests */, componentName ] = filePath.split('/').reverse();
const outputPath = `${OUTPUT_PATH}/${componentName}/${folderName}.html`;
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
await snapshotMarkup(browser.driver, 'html', outputPath, {
template: (output) => `<!doctype html>${output}`,
preserveAttributes: true,
preserveCommentNodes: true,
beautifyOptions: {
/* eslint-disable camelcase */
newline_between_rules: false,
brace_style: 'collapse',
indent_size: 4,
inline: [],
extra_liners: [],
preserve_newlines: false,
end_with_newline: true
/* eslint-enable */
}
});
}
await browser.close();
server.close();
});