From 21ee94739b4007f8c3e65316a0c8abe1bcef6baa Mon Sep 17 00:00:00 2001 From: James Date: Thu, 7 Mar 2024 15:40:29 -0500 Subject: [PATCH] chore: jest esm compat --- jest.config.js | 6 ++++-- test/_community/int.spec.ts | 12 ++++++------ test/helpers/mocks/emptyModule.js | 1 + test/helpers/mocks/fileMock.js | 1 + 4 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 test/helpers/mocks/emptyModule.js create mode 100644 test/helpers/mocks/fileMock.js diff --git a/jest.config.js b/jest.config.js index b28564341..34d7cb645 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,11 +6,13 @@ // }) const customJestConfig = { + extensionsToTreatAsEsm: ['.ts', '.tsx'], globalSetup: './test/jest.setup.ts', moduleNameMapper: { - '\\.(css|scss)$': '/packages/payload/src/bundlers/mocks/emptyModule.js', + '\\.(css|scss)$': '/test/helpers/mocks/emptyModule.js', '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': - '/packages/payload/src/bundlers/mocks/fileMock.js', + '/test/helpers/mocks/fileMock.js', + '^(\\.{1,2}/.*)\\.js$': '$1', }, testEnvironment: 'node', testMatch: ['/packages/payload/src/**/*.spec.ts', '/test/**/*int.spec.ts'], diff --git a/test/_community/int.spec.ts b/test/_community/int.spec.ts index ad90431c4..95876accc 100644 --- a/test/_community/int.spec.ts +++ b/test/_community/int.spec.ts @@ -1,10 +1,10 @@ -import type { Payload } from '../../packages/payload/src' +import type { Payload } from '../../packages/payload/src/index.js' -import { getPayload } from '../../packages/payload/src' -import { devUser } from '../credentials' -import { NextRESTClient } from '../helpers/NextRESTClient' -import { postsSlug } from './collections/Posts' -import configPromise from './config' +import { getPayload } from '../../packages/payload/src/index.js' +import { devUser } from '../credentials.js' +import { NextRESTClient } from '../helpers/NextRESTClient.js' +import { postsSlug } from './collections/Posts/index.js' +import configPromise from './config.js' let payload: Payload let token: string diff --git a/test/helpers/mocks/emptyModule.js b/test/helpers/mocks/emptyModule.js new file mode 100644 index 000000000..ead516c97 --- /dev/null +++ b/test/helpers/mocks/emptyModule.js @@ -0,0 +1 @@ +export default () => {} diff --git a/test/helpers/mocks/fileMock.js b/test/helpers/mocks/fileMock.js new file mode 100644 index 000000000..e25c9a3dc --- /dev/null +++ b/test/helpers/mocks/fileMock.js @@ -0,0 +1 @@ +export default 'file-stub'