refactor(pwa): simplify registerSW code, fix ESLint errors (#7579)

This commit is contained in:
Joshua Chen 2022-06-07 21:42:17 +08:00 committed by GitHub
parent bada5c11cc
commit 7869e74fd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 204 additions and 247 deletions

View file

@ -22,7 +22,7 @@ describe('getFileLastUpdate', () => {
const lastUpdateData = await getFileLastUpdate(existingFilePath);
expect(lastUpdateData).not.toBeNull();
const {author, timestamp} = lastUpdateData;
const {author, timestamp} = lastUpdateData!;
expect(author).not.toBeNull();
expect(typeof author).toBe('string');
@ -38,7 +38,7 @@ describe('getFileLastUpdate', () => {
const lastUpdateData = await getFileLastUpdate(filePathWithSpace);
expect(lastUpdateData).not.toBeNull();
const {author, timestamp} = lastUpdateData;
const {author, timestamp} = lastUpdateData!;
expect(author).not.toBeNull();
expect(typeof author).toBe('string');
@ -61,8 +61,6 @@ describe('getFileLastUpdate', () => {
expect(consoleMock).toHaveBeenLastCalledWith(
expect.stringMatching(/because the file does not exist./),
);
await expect(getFileLastUpdate(null)).resolves.toBeNull();
await expect(getFileLastUpdate(undefined)).resolves.toBeNull();
consoleMock.mockRestore();
});

View file

@ -16,7 +16,7 @@ let showedGitRequirementError = false;
let showedFileNotTrackedError = false;
export async function getFileLastUpdate(
filePath?: string,
filePath: string,
): Promise<{timestamp: number; author: string} | null> {
if (!filePath) {
return null;