Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
♻️ have withTiming return early if performance.timing does not ex…
Browse files Browse the repository at this point in the history
…ist.
  • Loading branch information
michenly committed Oct 15, 2019
1 parent d979960 commit 1550544
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 45 deletions.
4 changes: 4 additions & 0 deletions packages/performance/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

<!-- ## Unreleased -->

### 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
Expand Down
6 changes: 5 additions & 1 deletion packages/performance/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react-performance/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import {Performance} from '@shopify/performance';

export const PerformanceContext = React.createContext<Performance | null>(
typeof window === 'undefined' ? null : new Performance(),
export const PerformanceContext = React.createContext<Performance | undefined>(
typeof window === 'undefined' ? undefined : new Performance(),
);
Original file line number Diff line number Diff line change
Expand Up @@ -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('<LifecycleEventListener />', () => {
it('sets up a event listener on the Performance context object', () => {
const performance = mockPerformance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('<NavigationListener />', () => {
it('sets up a navigation listener on the Performance context object', () => {
const performance = mockPerformance();
Expand Down
7 changes: 0 additions & 7 deletions packages/react-performance/src/test/PerformanceMark.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('<PerformanceMark />', () => {
it('calls performance.mark', () => {
const performance = mockPerformance({mark: jest.fn()});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('<PerformanceReport />', () => {
beforeEach(() => {
timer.mock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1550544

Please sign in to comment.