/
index.spec.ts
114 lines (96 loc) · 3.66 KB
/
index.spec.ts
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
import { Tree } from '@angular-devkit/schematics';
import { Schema as AppWebOptions } from '../application/schema';
import { setTest, jsonParse, IHelperSchema } from '@nstudio/xplat';
import { createXplatWithApps, getFileContent } from '@nstudio/xplat/testing';
import { runSchematic, runSchematicSync } from '../../utils/testing';
setTest();
describe('helpers schematic', () => {
let appTree: Tree;
beforeEach(() => {
appTree = Tree.empty();
appTree = createXplatWithApps(appTree);
});
it('applitools: should create all files', async () => {
// const optionsXplat: XPlatOptions = {
// npmScope: 'testing',
// prefix: 'tt',
// platforms: 'web,nativescript'
// };
// appTree = schematicRunner.runSchematic('xplat', optionsXplat, appTree);
const appOptions: AppWebOptions = {
name: 'foo',
prefix: 'tt',
e2eTestRunner: 'cypress',
useXplat: false
};
// console.log('appTree:', appTree);
appTree = await runSchematic('app', appOptions, appTree);
const cypressJsonPath = '/apps/web-foo-e2e/cypress.json';
let fileContent = getFileContent(appTree, cypressJsonPath);
let cypressJson = jsonParse(fileContent);
expect(cypressJson.supportFile).toBe(false);
const options: IHelperSchema = {
name: 'applitools',
target: 'web-foo'
};
// console.log('appTree:', appTree);
const tree = await runSchematic('helpers', options, appTree);
const files = tree.files;
// console.log(files);
expect(
files.indexOf('/apps/web-foo-e2e/src/support/index.ts')
).toBeGreaterThanOrEqual(0);
expect(
files.indexOf('/apps/web-foo-e2e/src/plugins/index.ts')
).toBeGreaterThanOrEqual(0);
// modified testing files
let filePath = '/apps/web-foo-e2e/src/support/index.ts';
fileContent = getFileContent(tree, filePath);
// console.log(fileContent);
expect(
fileContent.indexOf('@applitools/eyes-cypress/commands')
).toBeGreaterThanOrEqual(0);
filePath = '/apps/web-foo-e2e/src/plugins/index.ts';
fileContent = getFileContent(tree, filePath);
// console.log(fileContent);
expect(
fileContent.indexOf(`require('@applitools/eyes-cypress')(module);`)
).toBeGreaterThanOrEqual(0);
fileContent = getFileContent(tree, cypressJsonPath);
// console.log(fileContent);
cypressJson = jsonParse(fileContent);
expect(cypressJson.supportFile).toBe(`./src/support/index.js`);
filePath = '/apps/web-foo-e2e/src/integration/app.spec.ts';
fileContent = getFileContent(tree, filePath);
// console.log(fileContent);
expect(fileContent.indexOf(`eyesOpen`)).toBeGreaterThanOrEqual(0);
});
it('applitools: should throw if target is missing', async () => {
// const optionsXplat: XPlatOptions = {
// npmScope: 'testing',
// prefix: 'tt',
// platforms: 'web,nativescript'
// };
// appTree = schematicRunner.runSchematic('xplat', optionsXplat, appTree);
const appOptions: AppWebOptions = {
name: 'foo',
prefix: 'tt',
e2eTestRunner: 'cypress',
useXplat: false
};
// console.log('appTree:', appTree);
appTree = await runSchematic('app', appOptions, appTree);
const cypressJsonPath = '/apps/web-foo-e2e/cypress.json';
let fileContent = getFileContent(appTree, cypressJsonPath);
let cypressJson = jsonParse(fileContent);
expect(cypressJson.supportFile).toBe(false);
const options: IHelperSchema = {
name: 'applitools'
};
// console.log('appTree:', appTree);
let tree;
expect(
() => (tree = runSchematicSync('helpers', options, appTree))
).toThrowError(`The helper "applitools" requires the --target flag.`);
});
});