fix(service-worker): detect new version even if files are identical to an old one (#26006)

Previously, if an app version contained the same files as an older
version (e.g. making a change, then rolling it back), the SW would not
detect it as the latest version (and update clients).

This commit fixes it by adding a `timestamp` field in `ngsw.json`, which
makes each build unique (with sufficiently high probability).

Fixes #24338

PR Close #26006
This commit is contained in:
George Kalpakas
2019-03-05 15:24:07 +02:00
committed by Andrew Kushnir
parent 5fded9fcc8
commit 586234bb01
8 changed files with 44 additions and 7 deletions

View File

@ -10,6 +10,8 @@ import {Generator} from '../src/generator';
import {MockFilesystem} from '../testing/mock';
describe('Generator', () => {
beforeEach(() => spyOn(Date, 'now').and.returnValue(1234567890123));
it('generates a correct config', done => {
const fs = new MockFilesystem({
'/index.html': 'This is a test',
@ -70,6 +72,7 @@ describe('Generator', () => {
res.then(config => {
expect(config).toEqual({
configVersion: 1,
timestamp: 1234567890123,
appData: {
test: true,
},
@ -137,6 +140,7 @@ describe('Generator', () => {
res.then(config => {
expect(config).toEqual({
configVersion: 1,
timestamp: 1234567890123,
appData: undefined,
index: '/test/index.html',
assetGroups: [],