diff --git a/jest.config.js b/jest.config.js index 33633c5ed4..6807839c68 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,29 +1,4 @@ -module.exports = { - globalSetup: './test/jest.setup.ts', - moduleNameMapper: { - '\\.(css|scss)$': '/packages/payload/src/bundlers/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', - }, - testEnvironment: 'node', - testMatch: ['/packages/payload/src/**/*.spec.ts', '/test/**/*int.spec.ts'], - testTimeout: 90000, - transform: { - '^.+\\.(t|j)sx?$': ['@swc/jest'], - }, - verbose: true, -} - -// // NextJS way of doing it -// const path = require('path') - -// const nextJest = require('next/jest') - -// // Optionally provide path to Next.js app which will enable loading next.config.js and .env files -// const createJestConfig = nextJest({ dir: path.resolve(__dirname, './test/REST_API') }) - -// // Any custom config you want to pass to Jest -// const customJestConfig = { +// module.exports = { // globalSetup: './test/jest.setup.ts', // moduleNameMapper: { // '\\.(css|scss)$': '/packages/payload/src/bundlers/mocks/emptyModule.js', @@ -39,5 +14,32 @@ module.exports = { // verbose: true, // } -// // createJestConfig is exported in this way to ensure that next/jest can load the Next.js config which is async -// module.exports = createJestConfig(customJestConfig) +// NextJS way of doing it +const path = require('path') + +const nextJest = require('next/jest') + +// Optionally provide path to Next.js app which will enable loading next.config.js and .env files +const createJestConfig = nextJest({ dir: path.resolve(__dirname, './packages/dev') }) + +// Any custom config you want to pass to Jest +const customJestConfig = { + globalSetup: './test/jest.setup.ts', + moduleNameMapper: { + // '@payloadcms/db-mongodb': '/packages/db-mongodb/src/index.ts', + '\\.(css|scss)$': '/packages/payload/src/bundlers/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', + 'payload-config': '/__mocks__/payload-config.ts', + }, + testEnvironment: 'node', + testMatch: ['/packages/payload/src/**/*.spec.ts', '/test/**/*int.spec.ts'], + testTimeout: 90000, + transform: { + '^.+\\.(t|j)sx?$': ['@swc/jest'], + }, + verbose: true, +} + +// createJestConfig is exported in this way to ensure that next/jest can load the Next.js config which is async +module.exports = createJestConfig(customJestConfig) diff --git a/packages/dev/next.config.js b/packages/dev/next.config.js index 4b2f22239a..8ec28c2d41 100644 --- a/packages/dev/next.config.js +++ b/packages/dev/next.config.js @@ -14,6 +14,7 @@ const nextConfig = { 'mongodb-memory-server', ], }, + transpilePackages: ['mongoose', 'sharp'], // transpilePackages: ['@payloadcms/db-mongodb', 'mongoose'], webpack: (config) => { return { @@ -24,7 +25,6 @@ const nextConfig = { 'drizzle-kit/utils', 'pino', 'pino-pretty', - 'mongoose', 'sharp', ], resolve: { @@ -34,6 +34,12 @@ const nextConfig = { graphql$: path.resolve(__dirname, '../next/node_modules/graphql/index.js'), 'graphql-http$': path.resolve(__dirname, '../next/node_modules/graphql-http/index.js'), }, + fallback: { + ...config.resolve.fallback, + '@smithy/middleware-endpoint': false, + aws4: false, + 'mongodb-client-encryption': false, + }, }, } }, diff --git a/test/auth/int.spec.ts b/test/auth/int.spec.ts index ac13b00ac6..048e43f54d 100644 --- a/test/auth/int.spec.ts +++ b/test/auth/int.spec.ts @@ -40,6 +40,10 @@ describe('Auth', () => { } }) + beforeEach(() => { + jest.resetModules() + }) + describe('GraphQL - admin user', () => { let token let user