feat(service-worker): include ServiceWorker version in debug info (#42622)

This commit includes the ServiceWorker version in the debug info shown
at `/ngsw/state` to make it easier to know what version of the
ServiceWorker script is controlling the page.

PR Close #42622
This commit is contained in:
George Kalpakas 2021-06-23 15:27:50 +03:00 committed by Jessica Janiuk
parent 4962ef5330
commit 53fe557da7
3 changed files with 7 additions and 4 deletions

View File

@ -171,6 +171,7 @@ is `ngsw/state`. Here is an example of this debug page's contents:
``` ```
NGSW Debug Info: NGSW Debug Info:
Driver version: 13.3.7
Driver state: NORMAL ((nominal)) Driver state: NORMAL ((nominal))
Latest manifest hash: eea7f5f464f90789b621170af5a569d6be077e5c Latest manifest hash: eea7f5f464f90789b621170af5a569d6be077e5c
Last update check: never Last update check: never

View File

@ -9,6 +9,7 @@
import {Adapter} from './adapter'; import {Adapter} from './adapter';
import {Debuggable, DebugLogger} from './api'; import {Debuggable, DebugLogger} from './api';
const SW_VERSION = '0.0.0-PLACEHOLDER';
const DEBUG_LOG_BUFFER_SIZE = 100; const DEBUG_LOG_BUFFER_SIZE = 100;
interface DebugMessage { interface DebugMessage {
@ -37,6 +38,7 @@ export class DebugHandler implements DebugLogger {
const msgState = `NGSW Debug Info: const msgState = `NGSW Debug Info:
Driver version: ${SW_VERSION}
Driver state: ${state.state} (${state.why}) Driver state: ${state.state} (${state.why})
Latest manifest hash: ${state.latestHash || 'none'} Latest manifest hash: ${state.latestHash || 'none'}
Last update check: ${this.since(state.lastUpdateCheck)}`; Last update check: ${this.since(state.lastUpdateCheck)}`;

View File

@ -1237,19 +1237,19 @@ describe('Driver', () => {
describe('serving ngsw/state', () => { describe('serving ngsw/state', () => {
it('should show debug info (when in NORMAL state)', async () => { it('should show debug info (when in NORMAL state)', async () => {
expect(await makeRequest(scope, '/ngsw/state')) expect(await makeRequest(scope, '/ngsw/state'))
.toMatch(/^NGSW Debug Info:\n\nDriver state: NORMAL/); .toMatch(/^NGSW Debug Info:\n\nDriver version: .+\nDriver state: NORMAL/);
}); });
it('should show debug info (when in EXISTING_CLIENTS_ONLY state)', async () => { it('should show debug info (when in EXISTING_CLIENTS_ONLY state)', async () => {
driver.state = DriverReadyState.EXISTING_CLIENTS_ONLY; driver.state = DriverReadyState.EXISTING_CLIENTS_ONLY;
expect(await makeRequest(scope, '/ngsw/state')) expect(await makeRequest(scope, '/ngsw/state'))
.toMatch(/^NGSW Debug Info:\n\nDriver state: EXISTING_CLIENTS_ONLY/); .toMatch(/^NGSW Debug Info:\n\nDriver version: .+\nDriver state: EXISTING_CLIENTS_ONLY/);
}); });
it('should show debug info (when in SAFE_MODE state)', async () => { it('should show debug info (when in SAFE_MODE state)', async () => {
driver.state = DriverReadyState.SAFE_MODE; driver.state = DriverReadyState.SAFE_MODE;
expect(await makeRequest(scope, '/ngsw/state')) expect(await makeRequest(scope, '/ngsw/state'))
.toMatch(/^NGSW Debug Info:\n\nDriver state: SAFE_MODE/); .toMatch(/^NGSW Debug Info:\n\nDriver version: .+\nDriver state: SAFE_MODE/);
}); });
it('should show debug info when the scope is not root', async () => { it('should show debug info when the scope is not root', async () => {
@ -1258,7 +1258,7 @@ describe('Driver', () => {
new Driver(newScope, newScope, new CacheDatabase(newScope, newScope)); new Driver(newScope, newScope, new CacheDatabase(newScope, newScope));
expect(await makeRequest(newScope, '/foo/bar/ngsw/state')) expect(await makeRequest(newScope, '/foo/bar/ngsw/state'))
.toMatch(/^NGSW Debug Info:\n\nDriver state: NORMAL/); .toMatch(/^NGSW Debug Info:\n\nDriver version: .+\nDriver state: NORMAL/);
}); });
}); });