/
remote.spec.ts
246 lines (211 loc) · 6.87 KB
/
remote.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import {
getProjects,
readProjectConfiguration,
readWorkspaceConfiguration,
} from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import host from '../host/host';
import remote from './remote';
import { E2eTestRunner } from '@nrwl/angular/src/utils/test-runners';
describe('MF Remote App Generator', () => {
it('should generate a remote mf app with no host', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
// ACT
await remote(tree, {
name: 'test',
port: 4201,
});
// ASSERT
expect(tree.read('apps/test/webpack.config.js', 'utf-8')).toMatchSnapshot();
});
it('should generate a remote mf app with a host', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
await host(tree, {
name: 'host',
});
// ACT
await remote(tree, {
name: 'test',
host: 'host',
});
// ASSERT
expect(tree.read('apps/host/webpack.config.js', 'utf-8')).toMatchSnapshot();
expect(tree.read('apps/test/webpack.config.js', 'utf-8')).toMatchSnapshot();
});
it('should error when a remote app is attempted to be generated with an incorrect host', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
// ACT
try {
await remote(tree, {
name: 'test',
host: 'host',
});
} catch (error) {
// ASSERT
expect(error.message).toEqual(
'The name of the application to be used as the host app does not exist. (host)'
);
}
});
it('should generate a remote mf app and automatically find the next port available', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
await remote(tree, {
name: 'existing',
port: 4201,
});
// ACT
await remote(tree, {
name: 'test',
});
// ASSERT
const project = readProjectConfiguration(tree, 'test');
expect(project.targets.serve.options.port).toEqual(4202);
});
it('should generate a remote mf app and automatically find the next port available even when there are no other targets', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
// ACT
await remote(tree, {
name: 'test',
});
// ASSERT
const project = readProjectConfiguration(tree, 'test');
expect(project.targets.serve.options.port).toEqual(4201);
});
it('should not set the remote as the default project', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
// ACT
await remote(tree, {
name: 'test',
port: 4201,
});
// ASSERT
const { defaultProject } = readWorkspaceConfiguration(tree);
expect(defaultProject).toBeUndefined();
});
it('should generate the a remote setup for standalone components', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
// ACT
await remote(tree, {
name: 'test',
standalone: true,
});
// ASSERT
expect(tree.exists(`apps/test/src/app/app.module.ts`)).toBeFalsy();
expect(tree.exists(`apps/test/src/app/app.component.ts`)).toBeFalsy();
expect(
tree.exists(`apps/test/src/app/remote-entry/entry.module.ts`)
).toBeFalsy();
expect(tree.read(`apps/test/src/bootstrap.ts`, 'utf-8')).toMatchSnapshot();
expect(
tree.read(`apps/test/module-federation.config.js`, 'utf-8')
).toMatchSnapshot();
expect(
tree.read(`apps/test/src/app/remote-entry/entry.component.ts`, 'utf-8')
).toMatchSnapshot();
expect(
tree.read(`apps/test/src/app/app.routes.ts`, 'utf-8')
).toMatchSnapshot();
expect(
tree.read(`apps/test/src/app/remote-entry/entry.routes.ts`, 'utf-8')
).toMatchSnapshot();
});
it('should not generate an e2e project when e2eTestRunner is none', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
// ACT
await remote(tree, {
name: 'remote1',
e2eTestRunner: E2eTestRunner.None,
});
// ASSERT
const projects = getProjects(tree);
expect(projects.has('remote1-e2e')).toBeFalsy();
});
it('should generate a correct app component when inline template is used', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
// ACT
await remote(tree, {
name: 'test',
inlineTemplate: true,
});
// ASSERT
expect(tree.read('apps/test/src/app/app.component.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"import { Component } from '@angular/core';
@Component({
selector: 'proj-root',
template: '<router-outlet></router-outlet>'
})
export class AppComponent {}"
`);
});
it('should update the index.html to use the remote entry component selector for root when standalone', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
// ACT
await remote(tree, {
name: 'test',
standalone: true,
});
// ASSERT
expect(tree.read('apps/test/src/index.html', 'utf-8')).not.toContain(
'proj-root'
);
expect(tree.read('apps/test/src/index.html', 'utf-8')).toContain(
'proj-test-entry'
);
});
describe('--ssr', () => {
it('should generate the correct files', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
// ACT
await remote(tree, {
name: 'test',
ssr: true,
});
// ASSERT
const project = readProjectConfiguration(tree, 'test');
expect(
tree.exists(`apps/test/src/app/remote-entry/entry.module.ts`)
).toBeTruthy();
expect(
tree.read(`apps/test/src/app/app.module.ts`, 'utf-8')
).toMatchSnapshot();
expect(
tree.read(`apps/test/src/bootstrap.ts`, 'utf-8')
).toMatchSnapshot();
expect(
tree.read(`apps/test/src/bootstrap.server.ts`, 'utf-8')
).toMatchSnapshot();
expect(
tree.read(`apps/test/src/main.server.ts`, 'utf-8')
).toMatchSnapshot();
expect(tree.read(`apps/test/server.ts`, 'utf-8')).toMatchSnapshot();
expect(
tree.read(`apps/test/module-federation.config.js`, 'utf-8')
).toMatchSnapshot();
expect(
tree.read(`apps/test/webpack.server.config.js`, 'utf-8')
).toMatchSnapshot();
expect(
tree.read(`apps/test/src/app/remote-entry/entry.component.ts`, 'utf-8')
).toMatchSnapshot();
expect(
tree.read(`apps/test/src/app/app.routes.ts`, 'utf-8')
).toMatchSnapshot();
expect(
tree.read(`apps/test/src/app/remote-entry/entry.routes.ts`, 'utf-8')
).toMatchSnapshot();
expect(project.targets.server).toMatchSnapshot();
});
});
});