/
index.spec.ts
169 lines (150 loc) · 6.87 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import { Tree } from '@angular-devkit/schematics';
import {
supportedPlatforms,
setTest,
jsonParse,
XplatHelpers
} from '@nstudio/xplat';
import { createEmptyWorkspace, getFileContent } from '@nstudio/xplat/testing';
import { runSchematic, runSchematicSync } from '../../utils/testing';
setTest();
describe('xplat schematic', () => {
let appTree: Tree;
const defaultOptions: XplatHelpers.Schema = {
npmScope: 'testing',
prefix: 'ft' // foo test
};
beforeEach(() => {
appTree = Tree.empty();
appTree = createEmptyWorkspace(appTree, 'angular');
});
it('should create default xplat support for web,nativescript + libs + testing support', async () => {
const options: XplatHelpers.Schema = { ...defaultOptions };
options.platforms = 'web,nativescript';
const tree = await runSchematic('xplat', options, appTree);
const files = tree.files;
// console.log(files);
expect(files.indexOf('/libs/core/index.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/libs/features/index.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/libs/scss/package.json')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/testing/karma.conf.js')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/testing/test.libs.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/testing/test.xplat.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/testing/tsconfig.libs.json')).toBeGreaterThanOrEqual(
0
);
expect(
files.indexOf('/testing/tsconfig.libs.spec.json')
).toBeGreaterThanOrEqual(0);
expect(
files.indexOf('/testing/tsconfig.xplat.json')
).toBeGreaterThanOrEqual(0);
expect(
files.indexOf('/testing/tsconfig.xplat.spec.json')
).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/xplat/web/index.ts')).toBeGreaterThanOrEqual(0);
expect(
files.indexOf('/xplat/nativescript/index.ts')
).toBeGreaterThanOrEqual(0);
});
it('should create default xplat support for web,nativescript', async () => {
const options: XplatHelpers.Schema = { ...defaultOptions };
options.platforms = 'web,nativescript';
const tree = await runSchematic('xplat', options, appTree);
const files = tree.files;
expect(files.indexOf('/xplat/web/features/items/items.module.ts')).toBe(-1);
expect(files.indexOf('/xplat/web/index.ts')).toBeGreaterThanOrEqual(0);
expect(
files.indexOf('/xplat/nativescript/index.ts')
).toBeGreaterThanOrEqual(0);
expect(
files.indexOf('/xplat/nativescript/features/items/items.module.ts')
).toBe(-1);
});
xit('should create default xplat support for ionic which should always include web as well', async () => {
const options: XplatHelpers.Schema = { ...defaultOptions };
options.platforms = 'ionic';
options.framework = 'angular';
const tree = await runSchematic('xplat', options, appTree);
const files = tree.files;
expect(files.indexOf('/xplat/web/index.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/xplat/ionic/index.ts')).toBeGreaterThanOrEqual(0);
expect(
files.indexOf('/xplat/nativescript/index.ts')
).toBeGreaterThanOrEqual(-1);
const packagePath = '/package.json';
const packageFile = jsonParse(getFileContent(tree, packagePath));
const hasScss = packageFile.dependencies[`@testing/scss`];
expect(hasScss).not.toBeUndefined();
const hasWebScss = packageFile.dependencies[`@testing/web-scss`];
expect(hasWebScss).not.toBeUndefined();
// should not include these root packages
const hasNativeScript = packageFile.dependencies[`nativescript-angular`];
expect(hasNativeScript).toBeUndefined();
});
it('should create default xplat support for electron which should always include web as well', async () => {
const options: XplatHelpers.Schema = { ...defaultOptions };
options.platforms = 'electron';
const tree = await runSchematic('xplat', options, appTree);
const files = tree.files;
expect(files.indexOf('/xplat/web/index.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/xplat/electron/index.ts')).toBeGreaterThanOrEqual(0);
expect(
files.indexOf('/xplat/nativescript/index.ts')
).toBeGreaterThanOrEqual(-1);
const packagePath = '/package.json';
const packageFile = jsonParse(getFileContent(tree, packagePath));
const hasScss = packageFile.dependencies[`@testing/scss`];
expect(hasScss).not.toBeUndefined();
// const hasWebScss = packageFile.dependencies[`@testing/web-scss`];
// expect(hasWebScss).not.toBeUndefined();
// should not include these root packages
const hasNativeScript = packageFile.dependencies[`nativescript-angular`];
expect(hasNativeScript).toBeUndefined();
const hasElectron = packageFile.devDependencies[`electron`];
expect(hasElectron).toBeDefined();
});
it('should create additional xplat support when generated with different platforms', async () => {
const options: XplatHelpers.Schema = { ...defaultOptions };
options.platforms = 'ionic,web';
options.framework = 'angular';
let tree = await runSchematic('xplat', options, appTree);
// let files = tree.files;
expect(tree.exists('/xplat/web/index.ts')).toBeTruthy();
expect(tree.exists('/xplat/ionic/index.ts')).toBeTruthy();
expect(tree.exists('/xplat/nativescript/index.ts')).toBeFalsy();
options.platforms = 'nativescript';
// let packageFile = jsonParse(getFileContent(tree, 'package.json'));
// console.log('packageFile.xplat:', packageFile.xplat);
tree = await runSchematic('xplat', options, tree);
// packageFile = jsonParse(getFileContent(tree, 'package.json'));
// console.log('after 2nd xplat run packageFile.xplat:', packageFile.xplat);
// files = tree.files;
// console.log('files:', files);
// should be unchanged
expect(tree.exists('/xplat/web/index.ts')).toBeTruthy();
expect(tree.exists('/xplat/ionic/index.ts')).toBeTruthy();
expect(tree.exists('/xplat/nativescript/index.ts')).toBeTruthy();
});
it('should NOT create xplat unless platforms are specified', () => {
const options: XplatHelpers.Schema = { ...defaultOptions };
let tree;
expect(
() => (tree = runSchematicSync('xplat', options, appTree))
).toThrowError(
`You must specify which platforms you wish to generate support for. For example: nx g @nstudio/xplat:init --prefix=foo --platforms=${supportedPlatforms.join(
','
)}`
);
});
it('should NOT create unsupported xplat option and throw', () => {
const options: XplatHelpers.Schema = { ...defaultOptions };
options.platforms = 'desktop';
let tree;
expect(
() => (tree = runSchematicSync('xplat', options, appTree))
).toThrowError(
`desktop is currently not a supported platform. Supported at the moment: ${supportedPlatforms}. Please request support for this platform if you'd like and/or submit a PR which we would greatly appreciate.`
);
});
});