Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@
"redux-logger": "^3.0.6",
"redux-thunk": "^3.1.0",
"reselect": "^4.1.8",
"valibot": "^1.3.1",
"workbox-window": "^7.4.0"
"valibot": "^1.4.0",
"workbox-window": "^7.4.1"
},
"devDependencies": {
"@babel/core": "^7.29.0",
"@babel/eslint-parser": "^7.28.6",
"@babel/eslint-plugin": "^7.27.1",
"@babel/preset-env": "^7.29.2",
"@babel/preset-env": "^7.29.5",
"@babel/preset-react": "^7.28.5",
"@babel/preset-typescript": "^7.28.5",
"@eslint/js": "^9.39.4",
Expand All @@ -127,20 +127,20 @@
"@types/common-tags": "^1.8.4",
"@types/jest": "^30.0.0",
"@types/minimist": "^1.2.5",
"@types/node": "^22.19.17",
"@types/node": "^22.19.19",
"@types/query-string": "^6.3.0",
"@types/react": "^18.3.28",
"@types/react": "^18.3.29",
"@types/react-dom": "^18.3.1",
"@types/redux-logger": "^3.0.6",
"@types/tgwf__co2": "^0.14.2",
"@typescript-eslint/eslint-plugin": "^8.59.1",
"@typescript-eslint/parser": "^8.59.1",
"alex": "^11.0.1",
"babel-jest": "^30.3.0",
"babel-jest": "^30.4.1",
"babel-plugin-module-resolver": "^5.0.3",
"browserslist": "^4.28.2",
"browserslist-to-esbuild": "^2.1.1",
"caniuse-lite": "^1.0.30001788",
"caniuse-lite": "^1.0.30001792",
"cross-env": "^10.1.0",
"cross-spawn": "^7.0.6",
"devtools-license-check": "^0.9.0",
Expand All @@ -157,10 +157,10 @@
"eslint-plugin-testing-library": "^7.16.2",
"fake-indexeddb": "^6.2.5",
"fetch-mock": "^12.6.0",
"globals": "^17.5.0",
"globals": "^17.6.0",
"husky": "^4.3.8",
"jest": "^30.3.0",
"jest-environment-jsdom": "^30.3.0",
"jest": "^30.4.2",
"jest-environment-jsdom": "^30.4.1",
"jest-extended": "^7.0.0",
"local-web-server": "^5.4.0",
"lockfile-lint": "^5.0.0",
Expand All @@ -176,7 +176,7 @@
"stylelint-config-standard": "^40.0.0",
"typescript": "^6.0.3",
"typescript-eslint": "^8.59.1",
"workbox-cli": "^7.4.0",
"workbox-cli": "^7.4.1",
"yargs": "^18.0.0"
},
"resolutions": {
Expand Down
29 changes: 13 additions & 16 deletions src/test/components/ServiceWorkerManager.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { Provider } from 'react-redux';
import * as WorkboxModule from 'workbox-window';
import { Workbox } from 'workbox-window';

import {
render,
Expand All @@ -26,6 +26,10 @@ import { blankStore } from '../fixtures/stores';
import { getProfileFromTextSamples } from '../fixtures/profiles/processed-profile';
import { fireFullClick } from '../fixtures/utils';

jest.mock('workbox-window', () => ({
Workbox: jest.fn(),
}));

function _getSimpleProfile() {
return getProfileFromTextSamples('A').profile;
}
Expand Down Expand Up @@ -68,13 +72,7 @@ describe('app/ServiceWorkerManager', () => {
// Comment out this spy when you want to debug this test file.
jest.spyOn(console, 'log').mockImplementation(() => {});

// Due to the following jest issues, we can't put this implementation in a
// jest.mock() call and also spying on the Workbox constructor:
// https://github.com/facebook/jest/issues/7573
// https://github.com/facebook/jest/issues/10419
// But we need the constructor spy to access the instance.
// @ts-expect-error - Types don't fully conform
jest.spyOn(WorkboxModule, 'Workbox').mockImplementation(() => {
(Workbox as unknown as jest.Mock).mockImplementation(() => {
// Constructor

// We reimplement the event system so that we can dispatchEvent in tests
Expand All @@ -87,7 +85,7 @@ describe('app/ServiceWorkerManager', () => {
listeners.add(callback);
listenersMap.set(eventName, listeners);
}),
dispatchEvent: (eventName) => {
dispatchEvent: (eventName: string) => {
const listeners = listenersMap.get(eventName) ?? new Set();
for (const listener of listeners) {
act(() => {
Expand Down Expand Up @@ -143,8 +141,7 @@ describe('app/ServiceWorkerManager', () => {
}

function getWorkboxInstance() {
// WorkboxModule.Workbox is a mock but Flow doesn't know about that.
const instance = (WorkboxModule.Workbox as any).mock.results[0].value;
const instance = (Workbox as unknown as jest.Mock).mock.results[0].value;
return instance;
}

Expand All @@ -171,7 +168,7 @@ describe('app/ServiceWorkerManager', () => {

it('does not register a service worker in the development environment', () => {
setup();
expect(WorkboxModule.Workbox).not.toHaveBeenCalled();
expect(Workbox).not.toHaveBeenCalled();
});

describe('in the home, with the `none` datasource', () => {
Expand All @@ -180,7 +177,7 @@ describe('app/ServiceWorkerManager', () => {

const { container, getCloseButton, getReloadButton, getWorkboxInstance } =
setup();
expect(WorkboxModule.Workbox).toHaveBeenCalledWith('/sw.js', {
expect(Workbox).toHaveBeenCalledWith('/sw.js', {
updateViaCache: 'none',
});

Expand Down Expand Up @@ -239,7 +236,7 @@ describe('app/ServiceWorkerManager', () => {
navigateToStoreLoadingPage();
await act(() => dispatch(viewProfile(_getSimpleProfile())));

expect(WorkboxModule.Workbox).toHaveBeenCalledWith('/sw.js', {
expect(Workbox).toHaveBeenCalledWith('/sw.js', {
updateViaCache: 'none',
});

Expand Down Expand Up @@ -448,7 +445,7 @@ describe('app/ServiceWorkerManager', () => {
);
await act(() => dispatch(viewProfile(_getSimpleProfile())));

expect(WorkboxModule.Workbox).toHaveBeenCalledWith('/sw.js', {
expect(Workbox).toHaveBeenCalledWith('/sw.js', {
updateViaCache: 'none',
});

Expand Down Expand Up @@ -486,7 +483,7 @@ describe('app/ServiceWorkerManager', () => {
navigateToFromUrlLoadingPage('http://localhost:5656/profile_amazon.zip');
await act(() => dispatch(viewProfile(_getSimpleProfile())));

expect(WorkboxModule.Workbox).toHaveBeenCalledWith('/sw.js', {
expect(Workbox).toHaveBeenCalledWith('/sw.js', {
updateViaCache: 'none',
});

Expand Down
Loading
Loading