|
5 | 5 | * Use of this source code is governed by an MIT-style license that can be
|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 |
| - |
9 |
| -import { runTargetSpec } from '@angular-devkit/architect/testing'; |
| 8 | +import { Architect } from '@angular-devkit/architect/src/index2'; |
10 | 9 | import { normalize, virtualFs } from '@angular-devkit/core';
|
11 |
| -import { tap } from 'rxjs/operators'; |
12 |
| -import { browserTargetSpec, host } from '../utils'; |
13 |
| - |
| 10 | +import { createArchitect, host } from '../utils'; |
14 | 11 |
|
15 | 12 | describe('Browser Builder service worker', () => {
|
16 | 13 | const manifest = {
|
@@ -43,128 +40,137 @@ describe('Browser Builder service worker', () => {
|
43 | 40 | ],
|
44 | 41 | };
|
45 | 42 |
|
46 |
| - beforeEach(done => host.initialize().toPromise().then(done, done.fail)); |
47 |
| - afterEach(done => host.restore().toPromise().then(done, done.fail)); |
| 43 | + const target = { project: 'app', target: 'build' }; |
| 44 | + let architect: Architect; |
48 | 45 |
|
49 |
| - it('errors if no ngsw-config.json is present', (done) => { |
| 46 | + beforeEach(async () => { |
| 47 | + await host.initialize().toPromise(); |
| 48 | + architect = (await createArchitect(host.root())).architect; |
| 49 | + }); |
| 50 | + afterEach(async () => host.restore().toPromise()); |
| 51 | + |
| 52 | + it('errors if no ngsw-config.json is present', async () => { |
50 | 53 | const overrides = { serviceWorker: true };
|
51 | 54 |
|
52 |
| - runTargetSpec(host, browserTargetSpec, overrides) |
53 |
| - .subscribe(event => { |
54 |
| - expect(event.success).toBe(false); |
55 |
| - }, () => done(), done.fail); |
| 55 | + const run = await architect.scheduleTarget(target, overrides); |
| 56 | + |
| 57 | + await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: false })); |
| 58 | + |
| 59 | + await run.stop(); |
56 | 60 | });
|
57 | 61 |
|
58 |
| - it('works with service worker', (done) => { |
| 62 | + it('works with service worker', async () => { |
59 | 63 | host.writeMultipleFiles({
|
60 | 64 | 'src/ngsw-config.json': JSON.stringify(manifest),
|
61 | 65 | 'src/assets/folder-asset.txt': 'folder-asset.txt',
|
62 | 66 | 'src/styles.css': `body { background: url(./spectrum.png); }`,
|
63 | 67 | });
|
64 | 68 |
|
65 | 69 | const overrides = { serviceWorker: true };
|
66 |
| - runTargetSpec(host, browserTargetSpec, overrides).pipe( |
67 |
| - tap(buildEvent => { |
68 |
| - expect(buildEvent.success).toBe(true); |
69 |
| - expect(host.scopedSync().exists(normalize('dist/ngsw.json'))); |
70 |
| - const ngswJson = JSON.parse(virtualFs.fileBufferToString( |
71 |
| - host.scopedSync().read(normalize('dist/ngsw.json')))); |
72 |
| - // Verify index and assets are there. |
73 |
| - expect(ngswJson).toEqual(jasmine.objectContaining({ |
74 |
| - configVersion: 1, |
75 |
| - index: '/index.html', |
76 |
| - navigationUrls: [ |
77 |
| - { positive: true, regex: '^\\\/.*$' }, |
78 |
| - { positive: false, regex: '^\\\/(?:.+\\\/)?[^\/]*\\.[^\/]*$' }, |
79 |
| - { positive: false, regex: '^\\\/(?:.+\\\/)?[^\/]*__[^\/]*$' }, |
80 |
| - { positive: false, regex: '^\\\/(?:.+\\\/)?[^\/]*__[^\/]*\\\/.*$' }, |
| 70 | + const run = await architect.scheduleTarget(target, overrides); |
| 71 | + |
| 72 | + await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true })); |
| 73 | + |
| 74 | + expect(host.scopedSync().exists(normalize('dist/ngsw.json'))); |
| 75 | + const ngswJson = JSON.parse(virtualFs.fileBufferToString( |
| 76 | + host.scopedSync().read(normalize('dist/ngsw.json')))); |
| 77 | + // Verify index and assets are there. |
| 78 | + expect(ngswJson).toEqual(jasmine.objectContaining({ |
| 79 | + configVersion: 1, |
| 80 | + index: '/index.html', |
| 81 | + navigationUrls: [ |
| 82 | + { positive: true, regex: '^\\\/.*$' }, |
| 83 | + { positive: false, regex: '^\\\/(?:.+\\\/)?[^\/]*\\.[^\/]*$' }, |
| 84 | + { positive: false, regex: '^\\\/(?:.+\\\/)?[^\/]*__[^\/]*$' }, |
| 85 | + { positive: false, regex: '^\\\/(?:.+\\\/)?[^\/]*__[^\/]*\\\/.*$' }, |
| 86 | + ], |
| 87 | + assetGroups: [ |
| 88 | + { |
| 89 | + name: 'app', |
| 90 | + installMode: 'prefetch', |
| 91 | + updateMode: 'prefetch', |
| 92 | + urls: [ |
| 93 | + '/favicon.ico', |
| 94 | + '/index.html', |
81 | 95 | ],
|
82 |
| - assetGroups: [ |
83 |
| - { |
84 |
| - name: 'app', |
85 |
| - installMode: 'prefetch', |
86 |
| - updateMode: 'prefetch', |
87 |
| - urls: [ |
88 |
| - '/favicon.ico', |
89 |
| - '/index.html', |
90 |
| - ], |
91 |
| - patterns: [], |
92 |
| - }, |
93 |
| - { |
94 |
| - name: 'assets', |
95 |
| - installMode: 'lazy', |
96 |
| - updateMode: 'prefetch', |
97 |
| - urls: [ |
98 |
| - '/assets/folder-asset.txt', |
99 |
| - '/spectrum.png', |
100 |
| - ], |
101 |
| - patterns: [], |
102 |
| - }, |
| 96 | + patterns: [], |
| 97 | + }, |
| 98 | + { |
| 99 | + name: 'assets', |
| 100 | + installMode: 'lazy', |
| 101 | + updateMode: 'prefetch', |
| 102 | + urls: [ |
| 103 | + '/assets/folder-asset.txt', |
| 104 | + '/spectrum.png', |
103 | 105 | ],
|
104 |
| - dataGroups: [], |
105 |
| - hashTable: { |
106 |
| - '/favicon.ico': '84161b857f5c547e3699ddfbffc6d8d737542e01', |
107 |
| - '/assets/folder-asset.txt': '617f202968a6a81050aa617c2e28e1dca11ce8d4', |
108 |
| - '/index.html': '1bcafd53046ffb270ac5e6f3cab23e0442f95c4f', |
109 |
| - '/spectrum.png': '8d048ece46c0f3af4b598a95fd8e4709b631c3c0', |
110 |
| - }, |
111 |
| - })); |
112 |
| - }), |
113 |
| - ).toPromise().then(done, done.fail); |
| 106 | + patterns: [], |
| 107 | + }, |
| 108 | + ], |
| 109 | + dataGroups: [], |
| 110 | + hashTable: { |
| 111 | + '/favicon.ico': '84161b857f5c547e3699ddfbffc6d8d737542e01', |
| 112 | + '/assets/folder-asset.txt': '617f202968a6a81050aa617c2e28e1dca11ce8d4', |
| 113 | + '/index.html': '1bcafd53046ffb270ac5e6f3cab23e0442f95c4f', |
| 114 | + '/spectrum.png': '8d048ece46c0f3af4b598a95fd8e4709b631c3c0', |
| 115 | + }, |
| 116 | + })); |
| 117 | + |
| 118 | + await run.stop(); |
114 | 119 | });
|
115 | 120 |
|
116 |
| - it('works with service worker and baseHref', (done) => { |
| 121 | + it('works with service worker and baseHref', async () => { |
117 | 122 | host.writeMultipleFiles({
|
118 | 123 | 'src/ngsw-config.json': JSON.stringify(manifest),
|
119 | 124 | 'src/assets/folder-asset.txt': 'folder-asset.txt',
|
120 | 125 | });
|
121 | 126 |
|
122 | 127 | const overrides = { serviceWorker: true, baseHref: '/foo/bar' };
|
123 |
| - runTargetSpec(host, browserTargetSpec, overrides).pipe( |
124 |
| - tap(buildEvent => { |
125 |
| - expect(buildEvent.success).toBe(true); |
126 |
| - expect(host.scopedSync().exists(normalize('dist/ngsw.json'))); |
127 |
| - const ngswJson = JSON.parse(virtualFs.fileBufferToString( |
128 |
| - host.scopedSync().read(normalize('dist/ngsw.json')))); |
129 |
| - // Verify index and assets include the base href. |
130 |
| - expect(ngswJson).toEqual(jasmine.objectContaining({ |
131 |
| - configVersion: 1, |
132 |
| - index: '/foo/bar/index.html', |
133 |
| - navigationUrls: [ |
134 |
| - { positive: true, regex: '^\\\/.*$' }, |
135 |
| - { positive: false, regex: '^\\\/(?:.+\\\/)?[^\/]*\\.[^\/]*$' }, |
136 |
| - { positive: false, regex: '^\\\/(?:.+\\\/)?[^\/]*__[^\/]*$' }, |
137 |
| - { positive: false, regex: '^\\\/(?:.+\\\/)?[^\/]*__[^\/]*\\\/.*$' }, |
| 128 | + const run = await architect.scheduleTarget(target, overrides); |
| 129 | + |
| 130 | + await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true })); |
| 131 | + |
| 132 | + expect(host.scopedSync().exists(normalize('dist/ngsw.json'))); |
| 133 | + const ngswJson = JSON.parse(virtualFs.fileBufferToString( |
| 134 | + host.scopedSync().read(normalize('dist/ngsw.json')))); |
| 135 | + // Verify index and assets include the base href. |
| 136 | + expect(ngswJson).toEqual(jasmine.objectContaining({ |
| 137 | + configVersion: 1, |
| 138 | + index: '/foo/bar/index.html', |
| 139 | + navigationUrls: [ |
| 140 | + { positive: true, regex: '^\\\/.*$' }, |
| 141 | + { positive: false, regex: '^\\\/(?:.+\\\/)?[^\/]*\\.[^\/]*$' }, |
| 142 | + { positive: false, regex: '^\\\/(?:.+\\\/)?[^\/]*__[^\/]*$' }, |
| 143 | + { positive: false, regex: '^\\\/(?:.+\\\/)?[^\/]*__[^\/]*\\\/.*$' }, |
| 144 | + ], |
| 145 | + assetGroups: [ |
| 146 | + { |
| 147 | + name: 'app', |
| 148 | + installMode: 'prefetch', |
| 149 | + updateMode: 'prefetch', |
| 150 | + urls: [ |
| 151 | + '/foo/bar/favicon.ico', |
| 152 | + '/foo/bar/index.html', |
138 | 153 | ],
|
139 |
| - assetGroups: [ |
140 |
| - { |
141 |
| - name: 'app', |
142 |
| - installMode: 'prefetch', |
143 |
| - updateMode: 'prefetch', |
144 |
| - urls: [ |
145 |
| - '/foo/bar/favicon.ico', |
146 |
| - '/foo/bar/index.html', |
147 |
| - ], |
148 |
| - patterns: [], |
149 |
| - }, |
150 |
| - { |
151 |
| - name: 'assets', |
152 |
| - installMode: 'lazy', |
153 |
| - updateMode: 'prefetch', |
154 |
| - urls: [ |
155 |
| - '/foo/bar/assets/folder-asset.txt', |
156 |
| - ], |
157 |
| - patterns: [], |
158 |
| - }, |
| 154 | + patterns: [], |
| 155 | + }, |
| 156 | + { |
| 157 | + name: 'assets', |
| 158 | + installMode: 'lazy', |
| 159 | + updateMode: 'prefetch', |
| 160 | + urls: [ |
| 161 | + '/foo/bar/assets/folder-asset.txt', |
159 | 162 | ],
|
160 |
| - dataGroups: [], |
161 |
| - hashTable: { |
162 |
| - '/foo/bar/favicon.ico': '84161b857f5c547e3699ddfbffc6d8d737542e01', |
163 |
| - '/foo/bar/assets/folder-asset.txt': '617f202968a6a81050aa617c2e28e1dca11ce8d4', |
164 |
| - '/foo/bar/index.html': '925d80777b6ba64b526b0be79761d254dfe94c65', |
165 |
| - }, |
166 |
| - })); |
167 |
| - }), |
168 |
| - ).toPromise().then(done, done.fail); |
| 163 | + patterns: [], |
| 164 | + }, |
| 165 | + ], |
| 166 | + dataGroups: [], |
| 167 | + hashTable: { |
| 168 | + '/foo/bar/favicon.ico': '84161b857f5c547e3699ddfbffc6d8d737542e01', |
| 169 | + '/foo/bar/assets/folder-asset.txt': '617f202968a6a81050aa617c2e28e1dca11ce8d4', |
| 170 | + '/foo/bar/index.html': '925d80777b6ba64b526b0be79761d254dfe94c65', |
| 171 | + }, |
| 172 | + })); |
| 173 | + |
| 174 | + await run.stop(); |
169 | 175 | });
|
170 | 176 | });
|
0 commit comments