-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular-devkit/build-angular): service-worker references non-exi…
…stent named index output This commit addresses an issue where the service worker incorrectly referenced a non-existent `index.html` when utilizing the output index option. Additionally, it ensures proper resolution of the service worker configuration when the option value is set to `true`.
- Loading branch information
1 parent
31e8ad3
commit c71e954
Showing
4 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...ngular_devkit/build_angular/src/builders/application/tests/options/service-worker_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { buildApplication } from '../../index'; | ||
import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup'; | ||
|
||
describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { | ||
describe('Option: "serviceWorker"', () => { | ||
beforeEach(async () => { | ||
const manifest = { | ||
index: '/index.html', | ||
assetGroups: [ | ||
{ | ||
name: 'app', | ||
installMode: 'prefetch', | ||
resources: { | ||
files: ['/favicon.ico', '/index.html'], | ||
}, | ||
}, | ||
{ | ||
name: 'assets', | ||
installMode: 'lazy', | ||
updateMode: 'prefetch', | ||
resources: { | ||
files: [ | ||
'/assets/**', | ||
'/*.(svg|cur|jpg|jpeg|png|apng|webp|avif|gif|otf|ttf|woff|woff2)', | ||
], | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
await harness.writeFile('src/ngsw-config.json', JSON.stringify(manifest)); | ||
}); | ||
|
||
it('should not generate SW config when option is unset', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
serviceWorker: undefined, | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
harness.expectFile('dist/browser/ngsw.json').toNotExist(); | ||
}); | ||
|
||
it('should not generate SW config when option is false', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
serviceWorker: false, | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
harness.expectFile('dist/browser/ngsw.json').toNotExist(); | ||
}); | ||
|
||
it('should generate SW config when option is true', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
serviceWorker: true, | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
harness.expectFile('dist/browser/ngsw.json').toExist(); | ||
}); | ||
|
||
it('should generate SW config referencing index output', async () => { | ||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
serviceWorker: true, | ||
index: { | ||
input: 'src/index.html', | ||
output: 'index.csr.html', | ||
}, | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBe(true); | ||
|
||
const config = await harness.readFile('dist/browser/ngsw.json'); | ||
expect(JSON.parse(config)).toEqual(jasmine.objectContaining({ index: '/index.csr.html' })); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters