|
7 | 7 | */
|
8 | 8 | import { Architect } from '@angular-devkit/architect';
|
9 | 9 | import { normalize, virtualFs } from '@angular-devkit/core';
|
| 10 | +import { debounceTime, take, tap } from 'rxjs/operators'; |
10 | 11 | import { createArchitect, host } from '../../test-utils';
|
11 | 12 |
|
| 13 | +// tslint:disable-next-line: no-big-function |
12 | 14 | describe('Browser Builder service worker', () => {
|
13 | 15 | const manifest = {
|
14 | 16 | index: '/index.html',
|
@@ -124,6 +126,60 @@ describe('Browser Builder service worker', () => {
|
124 | 126 | await run.stop();
|
125 | 127 | });
|
126 | 128 |
|
| 129 | + it('works in watch mode', async () => { |
| 130 | + host.writeMultipleFiles({ |
| 131 | + 'src/ngsw-config.json': JSON.stringify(manifest), |
| 132 | + 'src/assets/folder-asset.txt': 'folder-asset.txt', |
| 133 | + 'src/styles.css': `body { background: url(./spectrum.png); }`, |
| 134 | + }); |
| 135 | + |
| 136 | + const overrides = { serviceWorker: true, watch: true }; |
| 137 | + const run = await architect.scheduleTarget(target, overrides); |
| 138 | + let buildNumber = 0; |
| 139 | + |
| 140 | + await run.output |
| 141 | + .pipe( |
| 142 | + debounceTime(3000), |
| 143 | + tap(buildEvent => { |
| 144 | + expect(buildEvent.success).toBeTrue(); |
| 145 | + |
| 146 | + const ngswJsonPath = normalize('dist/ngsw.json'); |
| 147 | + expect(host.scopedSync().exists(ngswJsonPath)).toBeTrue(); |
| 148 | + const ngswJson = JSON.parse(virtualFs.fileBufferToString(host.scopedSync().read(ngswJsonPath))); |
| 149 | + |
| 150 | + const hashTableEntries = Object.keys(ngswJson.hashTable); |
| 151 | + |
| 152 | + buildNumber += 1; |
| 153 | + switch (buildNumber) { |
| 154 | + case 1: |
| 155 | + expect(hashTableEntries).toEqual([ |
| 156 | + '/assets/folder-asset.txt', |
| 157 | + '/favicon.ico', |
| 158 | + '/index.html', |
| 159 | + '/spectrum.png', |
| 160 | + ]); |
| 161 | + |
| 162 | + host.copyFile('src/assets/folder-asset.txt', 'src/assets/folder-new-asset.txt'); |
| 163 | + break; |
| 164 | + |
| 165 | + case 2: |
| 166 | + expect(hashTableEntries).toEqual([ |
| 167 | + '/assets/folder-asset.txt', |
| 168 | + '/assets/folder-new-asset.txt', |
| 169 | + '/favicon.ico', |
| 170 | + '/index.html', |
| 171 | + '/spectrum.png', |
| 172 | + ]); |
| 173 | + break; |
| 174 | + } |
| 175 | + }), |
| 176 | + take(2), |
| 177 | + ) |
| 178 | + .toPromise(); |
| 179 | + |
| 180 | + await run.stop(); |
| 181 | + }); |
| 182 | + |
127 | 183 | it('works with service worker and baseHref', async () => {
|
128 | 184 | host.writeMultipleFiles({
|
129 | 185 | 'src/ngsw-config.json': JSON.stringify(manifest),
|
|
0 commit comments