Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Jest require updates #1701

Merged
merged 3 commits into from
Dec 9, 2020
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
4 changes: 2 additions & 2 deletions packages/enzyme-utilities/src/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import {trigger, findById} from '..';
function noop() {}

jest.mock('react-dom/test-utils', () => {
const actualTestUtilities = require.requireActual('react-dom/test-utils');
const actualTestUtilities = jest.requireActual('react-dom/test-utils');

return {
...actualTestUtilities,
act: jest.fn(actualTestUtilities.act),
};
});

const {act} = require.requireMock('react-dom/test-utils') as {act: jest.Mock};
const {act} = jest.requireMock('react-dom/test-utils') as {act: jest.Mock};

describe('enzyme-utilities', () => {
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/koa-performance/src/test/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const config = {
logger: {log: jest.fn()},
};

const StatsDClient = require.requireMock('@shopify/statsd').StatsDClient;
const StatsDClient = jest.requireMock('@shopify/statsd').StatsDClient;

describe('client metrics middleware', () => {
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/koa-shopify-graphql-proxy/src/test/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jest.mock('koa-better-http-proxy', () => {
return jest.fn(() => jest.fn());
});

const proxyFactory = require.requireMock('koa-better-http-proxy');
const proxyFactory = jest.requireMock('koa-better-http-proxy');

describe('koa-shopify-graphql-proxy', () => {
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-bugsnag/src/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jest.mock('@bugsnag/js', () => ({
createClient: jest.fn(),
}));

const Bugsnag = require.requireMock('@bugsnag/js');
const Bugsnag = jest.requireMock('@bugsnag/js');

describe('createBugsnagClient()', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {CookieUniversalProvider} from '../CookieUniversalProvider';
import {CookieContext} from '../context';
import {BrowserCookieManager} from '../BrowserCookieManager';

const {hasDocumentCookie} = require.requireMock('../utilities');
const {hasDocumentCookie} = jest.requireMock('../utilities');

jest.mock('../utilities', () => ({
hasDocumentCookie: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion packages/react-cookie/src/tests/hooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {useCookie} from '../hooks';

import {clearCookies} from './utilities';

const {hasDocumentCookie} = require.requireMock('../utilities');
const {hasDocumentCookie} = jest.requireMock('../utilities');

jest.mock('../utilities', () => ({
hasDocumentCookie: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ import {NetworkContext, NetworkManager} from '@shopify/react-network';
import {GraphQLUniversalProvider} from '../GraphQLUniversalProvider';

jest.mock('apollo-client', () => {
const ApolloClient = require.requireActual('apollo-client').ApolloClient;
const ApolloClient = jest.requireActual('apollo-client').ApolloClient;
const mockApolloClient = jest.fn(options => new ApolloClient(options));

return {
...require.requireActual('apollo-client'),
...jest.requireActual('apollo-client'),
default: mockApolloClient,
ApolloClient: mockApolloClient,
};
});

jest.mock('../utilities', () => ({
...require.requireActual('../utilities'),
...jest.requireActual('../utilities'),
isServer: jest.fn(),
}));
const {isServer} = require.requireMock('../utilities');
const {isServer} = jest.requireMock('../utilities');

jest.mock('../request-id-link', () => ({
...require.requireActual('../request-id-link'),
...jest.requireActual('../request-id-link'),
createRequestIdLink: jest.fn(),
}));
const {createRequestIdLink} = require.requireMock('../request-id-link');
const {createRequestIdLink} = jest.requireMock('../request-id-link');

const ApolloClient = require.requireMock('apollo-client').default;
const ApolloClient = jest.requireMock('apollo-client').default;

describe('<GraphQLUniversalProvider />', () => {
beforeEach(() => {
Expand All @@ -51,7 +51,7 @@ describe('<GraphQLUniversalProvider />', () => {
);

expect(graphQL).toContainReactComponent(ApolloProvider, {
client: expect.any(require.requireActual('apollo-client').ApolloClient),
client: expect.any(jest.requireActual('apollo-client').ApolloClient),
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/react-i18n/src/test/i18n.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {DateStyle, Weekday} from '../constants';
import {MissingTranslationError} from '../errors';

jest.mock('../utilities', () => ({
...require.requireActual('../utilities'),
...jest.requireActual('../utilities'),
translate: jest.fn(),
getTranslationTree: jest.fn(),
getCurrencySymbol: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion packages/react-i18n/src/test/utilities.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
memoizedPluralRules,
} from '../utilities';

const {pseudotranslate} = require.requireMock('@shopify/i18n') as {
const {pseudotranslate} = jest.requireMock('@shopify/i18n') as {
pseudotranslate: jest.Mock;
};

Expand Down
4 changes: 2 additions & 2 deletions packages/react-import-remote/src/test/ImportRemote.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ jest.mock('@shopify/react-html', () => ({
}));

jest.mock('@shopify/react-intersection-observer', () => ({
...require.requireActual('@shopify/react-intersection-observer'),
...jest.requireActual('@shopify/react-intersection-observer'),
IntersectionObserver() {
return null;
},
}));

jest.mock('../load', () => jest.fn());

const load: jest.Mock = require.requireMock('../load');
const load: jest.Mock = jest.requireMock('../load');

describe('<ImportRemote />', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jest.mock('../utilities', () => ({
isSupported: jest.fn(),
}));

const {isSupported} = require.requireMock('../utilities') as {
const {isSupported} = jest.requireMock('../utilities') as {
isSupported: jest.Mock;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {mount} from '@shopify/react-testing';
import Link from '../Link';

jest.mock('react-router-dom', () => ({
...require.requireActual('react-router-dom'),
...jest.requireActual('react-router-dom'),
Link: function Link() {
return null;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jest.mock('../utilities', () => ({
isClient: jest.fn(),
}));

const {isClient} = require.requireMock('../utilities') as {
const {isClient} = jest.requireMock('../utilities') as {
isClient: jest.Mock;
};

Expand Down
4 changes: 2 additions & 2 deletions packages/sewing-kit-koa/src/tests/manifests-locales.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {
} from './test-utilities';

jest.mock('fs-extra', () => ({
...require.requireActual('fs-extra'),
...jest.requireActual('fs-extra'),
pathExists: jest.fn(() => Promise.resolve(false)),
readFile: jest.fn(() => '[]'),
readJson: jest.fn(() => []),
}));

const {pathExists, readFile, readJson} = require.requireMock('fs-extra');
const {pathExists, readFile, readJson} = jest.requireMock('fs-extra');

describe('Manifests locales', () => {
beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/sewing-kit-koa/src/tests/manifests-read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import {
} from './test-utilities';

jest.mock('fs-extra', () => ({
...require.requireActual('fs-extra'),
...jest.requireActual('fs-extra'),
pathExists: jest.fn(() => Promise.resolve(false)),
readFile: jest.fn(() => '[]'),
readJson: jest.fn(() => []),
}));

const {pathExists, readFile, readJson} = require.requireMock('fs-extra');
const {pathExists, readFile, readJson} = jest.requireMock('fs-extra');

describe('Manifests read', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {
} from './test-utilities';

jest.mock('fs-extra', () => ({
...require.requireActual('fs-extra'),
...jest.requireActual('fs-extra'),
pathExists: jest.fn(() => Promise.resolve(false)),
readFile: jest.fn(() => '[]'),
readJson: jest.fn(() => []),
}));

const {pathExists, readFile, readJson} = require.requireMock('fs-extra');
const {pathExists, readFile, readJson} = jest.requireMock('fs-extra');

describe('Manifests user agents', () => {
beforeEach(() => {
Expand Down