|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | import { Architect } from '@angular-devkit/architect'; |
10 | | -import { getSystemPath, join, normalize, virtualFs } from '@angular-devkit/core'; |
11 | | -import express from 'express'; // eslint-disable-line import/no-extraneous-dependencies |
12 | | -import * as http from 'http'; |
13 | | -import { AddressInfo } from 'net'; |
| 10 | +import { normalize, virtualFs } from '@angular-devkit/core'; |
14 | 11 | import { createArchitect, host } from '../../testing/test-utils'; |
15 | 12 |
|
16 | 13 | describe('AppShell Builder', () => { |
@@ -160,124 +157,6 @@ describe('AppShell Builder', () => { |
160 | 157 | expect(content).toContain('app-shell works!'); |
161 | 158 | }); |
162 | 159 |
|
163 | | - it('works with route and service-worker', async () => { |
164 | | - host.writeMultipleFiles(appShellRouteFiles); |
165 | | - host.writeMultipleFiles({ |
166 | | - 'src/ngsw-config.json': ` |
167 | | - { |
168 | | - "index": "/index.html", |
169 | | - "assetGroups": [{ |
170 | | - "name": "app", |
171 | | - "installMode": "prefetch", |
172 | | - "resources": { |
173 | | - "files": [ |
174 | | - "/favicon.ico", |
175 | | - "/index.html", |
176 | | - "/*.css", |
177 | | - "/*.js" |
178 | | - ] |
179 | | - } |
180 | | - }, { |
181 | | - "name": "assets", |
182 | | - "installMode": "lazy", |
183 | | - "updateMode": "prefetch", |
184 | | - "resources": { |
185 | | - "files": [ |
186 | | - "/assets/**" |
187 | | - ] |
188 | | - } |
189 | | - }] |
190 | | - } |
191 | | - `, |
192 | | - 'src/app/app.module.ts': ` |
193 | | - import { BrowserModule } from '@angular/platform-browser'; |
194 | | - import { NgModule } from '@angular/core'; |
195 | | -
|
196 | | - import { AppRoutingModule } from './app-routing.module'; |
197 | | - import { AppComponent } from './app.component'; |
198 | | - import { ServiceWorkerModule } from '@angular/service-worker'; |
199 | | - import { environment } from '../environments/environment'; |
200 | | - import { RouterModule } from '@angular/router'; |
201 | | -
|
202 | | - @NgModule({ |
203 | | - declarations: [ |
204 | | - AppComponent |
205 | | - ], |
206 | | - imports: [ |
207 | | - BrowserModule.withServerTransition({ appId: 'serverApp' }), |
208 | | - AppRoutingModule, |
209 | | - ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production }), |
210 | | - RouterModule |
211 | | - ], |
212 | | - providers: [], |
213 | | - bootstrap: [AppComponent] |
214 | | - }) |
215 | | - export class AppModule { } |
216 | | - `, |
217 | | - 'e2e/app.e2e-spec.ts': ` |
218 | | - import { browser, by, element } from 'protractor'; |
219 | | -
|
220 | | - it('should have ngsw in normal state', () => { |
221 | | - browser.get('/'); |
222 | | - // Wait for service worker to load. |
223 | | - browser.sleep(2000); |
224 | | - browser.waitForAngularEnabled(false); |
225 | | - browser.get('/ngsw/state'); |
226 | | - // Should have updated, and be in normal state. |
227 | | - expect(element(by.css('pre')).getText()).not.toContain('Last update check: never'); |
228 | | - expect(element(by.css('pre')).getText()).toContain('Driver state: NORMAL'); |
229 | | - }); |
230 | | - `, |
231 | | - }); |
232 | | - // This should match the browser target prod config. |
233 | | - host.replaceInFile( |
234 | | - 'angular.json', |
235 | | - '"buildOptimizer": true', |
236 | | - '"buildOptimizer": true, "serviceWorker": true', |
237 | | - ); |
238 | | - |
239 | | - // We're changing the workspace file so we need to recreate the Architect instance. |
240 | | - architect = (await createArchitect(host.root())).architect; |
241 | | - |
242 | | - const overrides = { route: 'shell' }; |
243 | | - const run = await architect.scheduleTarget( |
244 | | - { ...target, configuration: 'production' }, |
245 | | - overrides, |
246 | | - ); |
247 | | - const output = await run.result; |
248 | | - await run.stop(); |
249 | | - |
250 | | - expect(output.success).toBe(true); |
251 | | - |
252 | | - // Make sure the index is pre-rendering the route. |
253 | | - const fileName = 'dist/index.html'; |
254 | | - const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(fileName))); |
255 | | - expect(content).toContain('app-shell works!'); |
256 | | - |
257 | | - // Serve the app using a simple static server. |
258 | | - const app = express(); |
259 | | - app.use('/', express.static(getSystemPath(join(host.root(), 'dist')) + '/')); |
260 | | - const server = await new Promise<http.Server>((resolve) => { |
261 | | - const innerServer = app.listen(0, 'localhost', () => resolve(innerServer)); |
262 | | - }); |
263 | | - try { |
264 | | - const serverPort = (server.address() as AddressInfo).port; |
265 | | - // Load app in protractor, then check service worker status. |
266 | | - const protractorRun = await architect.scheduleTarget( |
267 | | - { project: 'app-e2e', target: 'e2e' }, |
268 | | - { baseUrl: `http://localhost:${serverPort}/`, devServerTarget: '' }, |
269 | | - ); |
270 | | - |
271 | | - const protractorOutput = await protractorRun.result; |
272 | | - await protractorRun.stop(); |
273 | | - |
274 | | - expect(protractorOutput.success).toBe(true); |
275 | | - } finally { |
276 | | - // Close the express server. |
277 | | - await new Promise<void>((resolve) => server.close(() => resolve())); |
278 | | - } |
279 | | - }); |
280 | | - |
281 | 160 | it('critical CSS is inlined', async () => { |
282 | 161 | host.writeMultipleFiles(appShellRouteFiles); |
283 | 162 | const overrides = { |
|
0 commit comments