1 | const JavascriptParserFactory = require('../../parsers/jsParser/JavascriptParserFactory');
|
2 | const StyleParserFactory = require('../../parsers/styleParser/StyleParserFactory');
|
3 | const path = require('path');
|
4 | const fs = require('fs');
|
5 | const prettifyXml = require('prettify-xml');
|
6 |
|
7 | async function run(relativePath, platform, ext) {
|
8 | const basePath = path.resolve(__dirname, '../cases', `${relativePath}.js`);
|
9 | const expectPath = path.resolve(__dirname, `../expects/${platform}`, `${relativePath}.${ext}`);
|
10 | const parser = JavascriptParserFactory.create({
|
11 | platform,
|
12 | filepath: basePath
|
13 | });
|
14 | await parser.parse();
|
15 | const expectCode = fs.readFileSync(expectPath, 'utf-8');
|
16 | const result = parser.getExtraFiles().find(file => {
|
17 | let type = 'html';
|
18 | if (platform === 'quick') {
|
19 | type = 'ux';
|
20 | }
|
21 | if (file.type === type) {
|
22 | return true;
|
23 | }
|
24 | return false;
|
25 | });
|
26 | expect(prettifyXml(result.code)).toMatch(
|
27 | prettifyXml(expectCode)
|
28 | );
|
29 | }
|
30 |
|
31 | async function runStyle(relativePath, platform, type) {
|
32 | const basePath = path.resolve(__dirname, '../cases', `${relativePath}.${type}`);
|
33 | const expectPath = path.resolve(__dirname, `../expects/${platform}`, `${relativePath}.css`);
|
34 | const parser = StyleParserFactory.create({
|
35 | platform,
|
36 | type,
|
37 | filepath: basePath
|
38 | });
|
39 | await parser.parse();
|
40 | const expectCode = fs.readFileSync(expectPath, 'utf-8');
|
41 | const result = parser.getExtraFiles().find(file => {
|
42 | if (file.type === 'css') {
|
43 | return true;
|
44 | }
|
45 | return false;
|
46 | });
|
47 | expect(prettifyXml(result.code)).toMatch(
|
48 | prettifyXml(expectCode)
|
49 | );
|
50 | }
|
51 |
|
52 | module.exports = {
|
53 | run,
|
54 | runStyle
|
55 | }; |
\ | No newline at end of file |