diff --git a/packages/performance/CHANGELOG.md b/packages/performance/CHANGELOG.md index 066cb348a5..7e6825e113 100644 --- a/packages/performance/CHANGELOG.md +++ b/packages/performance/CHANGELOG.md @@ -7,6 +7,10 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +### Fixed + +- `withTiming` used in `Performance` object constructor will now check if `performance.timing` exist. This is mostly to reduce error encounter during test. [[#1119](https://github.com/Shopify/quilt/pull/1119)] + ## [1.2.1] - 2019-10-11 ### Fixed diff --git a/packages/performance/src/utilities.ts b/packages/performance/src/utilities.ts index e2a4f775a1..d2c5bfd557 100644 --- a/packages/performance/src/utilities.ts +++ b/packages/performance/src/utilities.ts @@ -89,7 +89,11 @@ export function withNavigation( export function withTiming( handler: (timing: typeof performance.timing) => void, ) { - if (typeof document === 'undefined' || typeof performance === 'undefined') { + if ( + typeof document === 'undefined' || + typeof performance === 'undefined' || + typeof performance.timing === 'undefined' + ) { return; } diff --git a/packages/react-performance/src/context.ts b/packages/react-performance/src/context.ts index 1d28ae3c19..1ab28c9df8 100644 --- a/packages/react-performance/src/context.ts +++ b/packages/react-performance/src/context.ts @@ -1,6 +1,6 @@ import React from 'react'; import {Performance} from '@shopify/performance'; -export const PerformanceContext = React.createContext( - typeof window === 'undefined' ? null : new Performance(), +export const PerformanceContext = React.createContext( + typeof window === 'undefined' ? undefined : new Performance(), ); diff --git a/packages/react-performance/src/test/LifecycleEventListener.test.tsx b/packages/react-performance/src/test/LifecycleEventListener.test.tsx index 735acad9fe..a5a7f4d808 100644 --- a/packages/react-performance/src/test/LifecycleEventListener.test.tsx +++ b/packages/react-performance/src/test/LifecycleEventListener.test.tsx @@ -3,13 +3,6 @@ import {mount} from '@shopify/react-testing'; import {mockPerformance} from './utilities'; import {LifecycleEventListener, PerformanceContext} from '..'; -jest.mock('@shopify/performance', () => { - return { - ...require.requireActual('@shopify/performance'), - Performance: jest.fn(), - }; -}); - describe('', () => { it('sets up a event listener on the Performance context object', () => { const performance = mockPerformance(); diff --git a/packages/react-performance/src/test/NavigationListener.test.tsx b/packages/react-performance/src/test/NavigationListener.test.tsx index 3c5b87a004..4185b4520a 100644 --- a/packages/react-performance/src/test/NavigationListener.test.tsx +++ b/packages/react-performance/src/test/NavigationListener.test.tsx @@ -3,13 +3,6 @@ import {mount} from '@shopify/react-testing'; import {mockPerformance} from './utilities'; import {NavigationListener, PerformanceContext} from '..'; -jest.mock('@shopify/performance', () => { - return { - ...require.requireActual('@shopify/performance'), - Performance: jest.fn(), - }; -}); - describe('', () => { it('sets up a navigation listener on the Performance context object', () => { const performance = mockPerformance(); diff --git a/packages/react-performance/src/test/PerformanceMark.test.tsx b/packages/react-performance/src/test/PerformanceMark.test.tsx index 89c1af72ed..6adf4fe070 100644 --- a/packages/react-performance/src/test/PerformanceMark.test.tsx +++ b/packages/react-performance/src/test/PerformanceMark.test.tsx @@ -3,13 +3,6 @@ import {mount} from '@shopify/react-testing'; import {mockPerformance} from './utilities'; import {PerformanceMark, PerformanceContext} from '..'; -jest.mock('@shopify/performance', () => { - return { - ...require.requireActual('@shopify/performance'), - Performance: jest.fn(), - }; -}); - describe('', () => { it('calls performance.mark', () => { const performance = mockPerformance({mark: jest.fn()}); diff --git a/packages/react-performance/src/test/PerformanceReport.test.tsx b/packages/react-performance/src/test/PerformanceReport.test.tsx index 1aafa43d1d..80090a5d6a 100644 --- a/packages/react-performance/src/test/PerformanceReport.test.tsx +++ b/packages/react-performance/src/test/PerformanceReport.test.tsx @@ -7,13 +7,6 @@ import {Method, Header} from '@shopify/network'; import {mockPerformance, randomConnection} from './utilities'; import {PerformanceReport, PerformanceContext} from '..'; -jest.mock('@shopify/performance', () => { - return { - ...require.requireActual('@shopify/performance'), - Performance: jest.fn(), - }; -}); - describe('', () => { beforeEach(() => { timer.mock(); diff --git a/packages/react-performance/src/test/performance-effect.server.test.tsx b/packages/react-performance/src/test/performance-effect.server.test.tsx index 70114cc34e..4b31d998fe 100644 --- a/packages/react-performance/src/test/performance-effect.server.test.tsx +++ b/packages/react-performance/src/test/performance-effect.server.test.tsx @@ -6,13 +6,6 @@ import React from 'react'; import ReactDOMServer from 'react-dom/server'; import {usePerformanceEffect, PerformanceEffectCallback} from '..'; -jest.mock('@shopify/performance', () => { - return { - ...require.requireActual('@shopify/performance'), - Performance: jest.fn(), - }; -}); - describe('usePerformanceEffect', () => { function TestComponent({callback}: {callback: PerformanceEffectCallback}) { usePerformanceEffect(callback); diff --git a/packages/react-performance/src/test/performance-effect.test.tsx b/packages/react-performance/src/test/performance-effect.test.tsx index 8932301923..6af9e13ed4 100644 --- a/packages/react-performance/src/test/performance-effect.test.tsx +++ b/packages/react-performance/src/test/performance-effect.test.tsx @@ -7,13 +7,6 @@ import { PerformanceContext, } from '..'; -jest.mock('@shopify/performance', () => { - return { - ...require.requireActual('@shopify/performance'), - Performance: jest.fn(), - }; -}); - describe('usePerformanceEffect', () => { function TestComponent({callback}: {callback: PerformanceEffectCallback}) { usePerformanceEffect(callback);