<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow

import React from 'react';
import { Provider } from 'react-redux';
import { render, fireEvent } from 'react-testing-library';
import serviceWorkerRuntime from '@mstange/offline-plugin/runtime';

import ServiceWorkerManager from '../../components/app/ServiceWorkerManager';
import { stateFromLocation } from '../../app-logic/url-handling';
import { updateUrlState } from '../../actions/app';
import { fatalError } from '../../actions/receive-profile';

import { blankStore } from '../fixtures/stores';

// Mock the offline plugin library.
jest.mock('@mstange/offline-plugin/runtime', () => ({
  install: jest.fn(),
  applyUpdate: jest.fn(),
}));

describe('app/ServiceWorkerManager', () => {
  afterEach(() => {
    process.env.NODE_ENV = 'development';
  });

  function setup() {
    jest.spyOn(console, 'log').mockImplementation(() => {});

    // Because of how window.location is implemented in browsers and jsdom, we
    // can't easily spy on `window.location.reload`. That's why we replace the
    // full property 'location' instead. This is fine to do it on `window`
    // without reverting it because `window` is a new object for each test.
    // $FlowExpectError because the value we pass isn't a proper Location object.
    Object.defineProperty(window, 'location', {
      value: { reload: jest.fn() },
      writable: true,
      configurable: true,
    });

    function navigateToStoreLoadingPage() {
      const newUrlState = stateFromLocation({
        pathname: '/public/ThisIsAFakeHash/calltree',
        search: '',<commit_msg>Fix tests for node v8<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow

import React from 'react';
import { Provider } from 'react-redux';
import { render, fireEvent } from 'react-testing-library';
import serviceWorkerRuntime from '@mstange/offline-plugin/runtime';

import ServiceWorkerManager from '../../components/app/ServiceWorkerManager';
import { stateFromLocation } from '../../app-logic/url-handling';
import { updateUrlState } from '../../actions/app';
import { fatalError } from '../../actions/receive-profile';

import { blankStore } from '../fixtures/stores';

// Mock the offline plugin library.
jest.mock('@mstange/offline-plugin/runtime', () => ({
  install: jest.fn(),
  applyUpdate: jest.fn(),
}));

describe('app/ServiceWorkerManager', () => {
  // Opt out of Flow checking for this variable because we're doing
  // unconventional things with it.
  let nativeLocation: any;
  beforeEach(() => {
    // Because of how window.location is implemented in browsers and jsdom, we
    // can't easily spy on `window.location.reload`. That's why we replace the
    // full property 'location' instead.

    nativeLocation = Object.getOwnPropertyDescriptor(window, 'location');

    // It seems node v8 doesn't let us change the value unless we delete it before.
    delete window.location;
    // $FlowExpectError because the value we pass isn't a proper Location object.
    Object.defineProperty(window, 'location', {
      value: { reload: jest.fn() },
      writable: true,
      configurable: true,
    });
  });

  afterEach(() => {
    process.env.NODE_ENV = 'development';

    Object.defineProperty(window, 'location', nativeLocation);
    nativeLocation = null;
  });

  function setup() {
    jest.spyOn(console, 'log').mockImplementation(() => {});

    function navigateToStoreLoadingPage() {
      const newUrlState = stateFromLocation({
        pathname: '/public/ThisIsAFakeHash/calltree',
        search: '',
{'fraction_non_alphanumeric': 0.13915275994865212, 'fraction_numerical': 0.0025673940949935813, 'mean_word_length': 3.4730195177956373, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5621807', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1076, 'n_words': 356}