Skip to content

Commit

Permalink
Merge branch 'master' into move-component-update-button
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored Jul 20, 2022
2 parents 428d046 + 41a2610 commit 962599d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
projects: ['<rootDir>/packages/toolpad-app/jest.config.js'],
projects: ['<rootDir>/packages/toolpad-app/jest.config.ts'],
setupFilesAfterEnv: ['<rootDir>/test/utils/jest-setup.ts'],
};

Expand Down
30 changes: 30 additions & 0 deletions packages/toolpad-app/jest-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { TextDecoder, TextEncoder } from 'util';
import fetch, { Headers, Request, Response } from 'node-fetch';

if (!global.TextDecoder) {
// @ts-expect-error
global.TextDecoder = TextDecoder;
} else {
// eslint-disable-next-line no-console
console.info('TextDecoder not polyfilled: running on a platform that supports TextDecoder');
}

if (!global.TextEncoder) {
global.TextEncoder = TextEncoder;
} else {
// eslint-disable-next-line no-console
console.info('TextEncoder not polyfilled: running on a platform that supports TextEncoder');
}

if (!global.fetch) {
// @ts-expect-error
global.fetch = fetch;
global.Headers = Headers;
// @ts-expect-error
global.Request = Request;
// @ts-expect-error
global.Response = Response;
} else {
// eslint-disable-next-line no-console
console.info('Fetch API not polyfilled: running on a platform that supports fetch');
}
14 changes: 0 additions & 14 deletions packages/toolpad-app/jest.config.js

This file was deleted.

20 changes: 20 additions & 0 deletions packages/toolpad-app/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Config } from '@jest/types';
import nextJest from 'next/jest';

const createJestConfig = nextJest();

async function jestConfig(): Promise<Config.InitialOptions> {
const baseConfig: Config.InitialOptions = {
testEnvironment: 'jest-environment-jsdom',
setupFilesAfterEnv: ['<rootDir>/jest-setup.ts'],
};
const nextJestConfig: Config.InitialOptions = await createJestConfig(baseConfig)();

// Workaround, see https://github.com/vercel/next.js/issues/35634#issuecomment-1115250297
nextJestConfig.transformIgnorePatterns = nextJestConfig.transformIgnorePatterns ?? [];
nextJestConfig.transformIgnorePatterns[0] = '/node_modules/(?!lodash-es)/';

return nextJestConfig;
}

export default jestConfig;

0 comments on commit 962599d

Please sign in to comment.