-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathutils_spec.ts
158 lines (123 loc) · 6.76 KB
/
utils_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
import { join } from 'path';
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import { createEmptyNsOnlyProject, createEmptySharedProject } from '../test-utils';
import { Schema as ComponentOptions } from './component/schema';
import { Schema as ModuleOptions } from './module/schema';
import { getPlatformUse } from './utils';
const project = 'leproj';
describe('Validation should trigger', () => {
const defaultComponentOptions: ComponentOptions = { name: 'fooComponent', project };
const defaultModuleOptions: ModuleOptions = { name: 'fooModule', project };
const schematicRunner = new SchematicTestRunner(
'@nativescript/schematics',
join(__dirname, '../collection.json'),
);
describe('for component schematic, when', () => {
it('both ns and web are disabled in ns-only project', async () => {
const tree = createEmptyNsOnlyProject(project);
const options = { ...defaultComponentOptions, nativescript: false, web: false };
const promise = schematicRunner.runSchematicAsync('component', options, tree)
.toPromise();
const error = 'You shouldn\'t disable both --web and --nativescript flags';
await expectAsync(promise).toBeRejectedWithError(error);
});
it('both ns and web are disabled in ns+web project', async () => {
const tree = createEmptySharedProject(project);
const options = { ...defaultComponentOptions, nativescript: false, web: false };
const promise = schematicRunner.runSchematicAsync('component', options, tree)
.toPromise();
const error = 'You shouldn\'t disable both --web and --nativescript flags';
await expectAsync(promise).toBeRejectedWithError(error);
});
it('using inline templates in ns+web project', async () => {
const tree = createEmptySharedProject(project);
const options: ComponentOptions = { ...defaultComponentOptions, inlineTemplate: true };
const promise = schematicRunner.runSchematicAsync('component', options, tree)
.toPromise();
const error = /--inlineTemplate/;
await expectAsync(promise).toBeRejectedWithError(error);
});
it('using web-only schematic in ns-only project', async () => {
const tree = createEmptyNsOnlyProject(project);
const options = { ...defaultComponentOptions, web: true, nativescript: false };
const promise = schematicRunner.runSchematicAsync('component', options, tree)
.toPromise();
const error = 'Project is not configured for Angular Web, while --nativescript is set to false';
await expectAsync(promise).toBeRejectedWithError(error);
});
});
describe('for module schematic, when', () => {
it('both ns and web are disabled in ns-only project', async () => {
const tree = createEmptyNsOnlyProject(project);
const options = { ...defaultModuleOptions, nativescript: false, web: false };
const promise = schematicRunner.runSchematicAsync('module', options, tree).toPromise();
const error = 'You shouldn\'t disable both --web and --nativescript flags';
await expectAsync(promise).toBeRejectedWithError(error);
});
it('both ns and web are disabled in ns+web project', async () => {
const tree = createEmptySharedProject(project);
const options = { ...defaultModuleOptions, nativescript: false, web: false };
const promise = schematicRunner.runSchematicAsync('module', options, tree).toPromise();
const error = 'You shouldn\'t disable both --web and --nativescript flags';
await expectAsync(promise).toBeRejectedWithError(error);
});
it('using web-only schematic in ns-only project', async () => {
const tree = createEmptyNsOnlyProject(project);
const options = { ...defaultModuleOptions, web: true, nativescript: false };
const promise = schematicRunner.runSchematicAsync('module', options, tree).toPromise();
const error = 'Project is not configured for Angular Web, while --nativescript is set to false';
await expectAsync(promise).toBeRejectedWithError(error);
});
});
});
describe('getPlatformUse', () => {
const nsOnlyProj = createEmptyNsOnlyProject(project);
const sharedProj = createEmptySharedProject(project);
const baseOpts = { name: 'foo', project: 'bar' };
describe('for ns-only project', () => {
it('should report ready only for NS', () => {
const res = getPlatformUse(nsOnlyProj, { ...baseOpts });
expect(res.webReady).toBeFalsy();
expect(res.nsReady).toBeTruthy();
expect(res.nsOnly).toBeTruthy();
});
it('should report correctly when ns:true web:true', () => {
const res = getPlatformUse(nsOnlyProj, { ...baseOpts, nativescript: true, web: true });
expect(res.useNs).toBeTruthy();
expect(res.useWeb).toBeFalsy();
});
it('should report correctly when ns:true web:false', () => {
const res = getPlatformUse(nsOnlyProj, { ...baseOpts, nativescript: true, web: false });
expect(res.useNs).toBeTruthy();
expect(res.useWeb).toBeFalsy();
});
it('should report correctly when ns:false web:true', () => {
const res = getPlatformUse(nsOnlyProj, { ...baseOpts, nativescript: false, web: true });
expect(res.useNs).toBeFalsy();
expect(res.useWeb).toBeFalsy();
});
});
describe('for ns+web project', () => {
it('should report ready for both Web and NS', () => {
const res = getPlatformUse(sharedProj, { ...baseOpts });
expect(res.webReady).toBeTruthy();
expect(res.nsReady).toBeTruthy();
expect(res.nsOnly).toBeFalsy();
});
it('should report correctly when ns:true web:true', () => {
const res = getPlatformUse(sharedProj, { ...baseOpts, nativescript: true, web: true });
expect(res.useNs).toBeTruthy();
expect(res.useWeb).toBeTruthy();
});
it('should report correctly when ns:true web:false', () => {
const res = getPlatformUse(sharedProj, { ...baseOpts, nativescript: true, web: false });
expect(res.useNs).toBeTruthy();
expect(res.useWeb).toBeFalsy();
});
it('should report correctly when ns:false web:true', () => {
const res = getPlatformUse(sharedProj, { ...baseOpts, nativescript: false, web: true });
expect(res.useNs).toBeFalsy();
expect(res.useWeb).toBeTruthy();
});
});
});