forked from microsoft/BotFramework-WebChat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml2-test-transformer.js
More file actions
28 lines (24 loc) · 837 Bytes
/
html2-test-transformer.js
File metadata and controls
28 lines (24 loc) · 837 Bytes
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
const { relative, resolve } = require('path');
const fs = require('fs');
const testRoot = resolve(__dirname, './__tests__/html2/');
const extractTitle = htmlPath => {
// eslint-disable-next-line security/detect-non-literal-fs-filename
const contents = fs.readFileSync(htmlPath, 'utf8');
const match = contents.match(/<title>(.*?)<\/title>/u);
return match ? match[1] : '';
};
module.exports = {
process: (_, sourcePath) => {
const html = relative(testRoot, sourcePath);
const shouldSkip = sourcePath.endsWith('.skip.html');
const title = extractTitle(sourcePath);
return {
code: `
describe(${JSON.stringify(title)}, () => {
test${shouldSkip ? '.skip' : ''}(${JSON.stringify(html)}, () =>
runHTML(${JSON.stringify(`/__tests__/html2/${html}`)}));
});
`
};
}
};