chore: uses globalSetup for starting memory db
This commit is contained in:
@@ -6,7 +6,7 @@ import { fileURLToPath } from 'url'
|
||||
|
||||
import { initPageConsoleErrorCatch } from '../helpers.js'
|
||||
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
|
||||
import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
|
||||
import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js'
|
||||
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
@@ -16,7 +16,7 @@ test.describe('Admin Panel', () => {
|
||||
let url: AdminUrlUtil
|
||||
|
||||
test.beforeAll(async ({ browser }) => {
|
||||
const { payload, serverURL } = await initPayloadE2E({ dirname })
|
||||
const { payload, serverURL } = await initPayloadE2ENoConfig({ dirname })
|
||||
url = new AdminUrlUtil(serverURL, 'posts')
|
||||
|
||||
const context = await browser.newContext()
|
||||
|
||||
@@ -29,47 +29,48 @@ import {
|
||||
import { type Config, buildConfig } from 'payload/config'
|
||||
import sharp from 'sharp'
|
||||
|
||||
import { getDBAdapter } from './getDBAdapter.js'
|
||||
import { reInitEndpoint } from './helpers/reInit.js'
|
||||
import { localAPIEndpoint } from './helpers/sdk/endpoint.js'
|
||||
// process.env.PAYLOAD_DATABASE = 'postgres'
|
||||
|
||||
const databaseAdapters = {
|
||||
mongodb: mongooseAdapter({
|
||||
url: process.env.DATABASE_URI || 'mongodb://127.0.0.1/payloadtests',
|
||||
}),
|
||||
postgres: postgresAdapter({
|
||||
pool: {
|
||||
connectionString: process.env.POSTGRES_URL || 'postgres://127.0.0.1:5432/payloadtests',
|
||||
},
|
||||
}),
|
||||
'postgres-custom-schema': postgresAdapter({
|
||||
pool: {
|
||||
connectionString: process.env.POSTGRES_URL || 'postgres://127.0.0.1:5432/payloadtests',
|
||||
},
|
||||
schemaName: 'custom',
|
||||
}),
|
||||
'postgres-uuid': postgresAdapter({
|
||||
idType: 'uuid',
|
||||
pool: {
|
||||
connectionString: process.env.POSTGRES_URL || 'postgres://127.0.0.1:5432/payloadtests',
|
||||
},
|
||||
}),
|
||||
supabase: postgresAdapter({
|
||||
pool: {
|
||||
connectionString:
|
||||
process.env.POSTGRES_URL || 'postgresql://postgres:postgres@127.0.0.1:54322/postgres',
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
export async function buildConfigWithDefaults(
|
||||
testConfig?: Partial<Config>,
|
||||
): Promise<SanitizedConfig> {
|
||||
const adapter = await getDBAdapter()
|
||||
console.log('MEMORY URI', process.env.MONGODB_MEMORY_SERVER_URI)
|
||||
const databaseAdapters = {
|
||||
mongodb: mongooseAdapter({
|
||||
url:
|
||||
process.env.MONGODB_MEMORY_SERVER_URI ||
|
||||
process.env.DATABASE_URI ||
|
||||
'mongodb://127.0.0.1/payloadtests',
|
||||
}),
|
||||
postgres: postgresAdapter({
|
||||
pool: {
|
||||
connectionString: process.env.POSTGRES_URL || 'postgres://127.0.0.1:5432/payloadtests',
|
||||
},
|
||||
}),
|
||||
'postgres-custom-schema': postgresAdapter({
|
||||
pool: {
|
||||
connectionString: process.env.POSTGRES_URL || 'postgres://127.0.0.1:5432/payloadtests',
|
||||
},
|
||||
schemaName: 'custom',
|
||||
}),
|
||||
'postgres-uuid': postgresAdapter({
|
||||
idType: 'uuid',
|
||||
pool: {
|
||||
connectionString: process.env.POSTGRES_URL || 'postgres://127.0.0.1:5432/payloadtests',
|
||||
},
|
||||
}),
|
||||
supabase: postgresAdapter({
|
||||
pool: {
|
||||
connectionString:
|
||||
process.env.POSTGRES_URL || 'postgresql://postgres:postgres@127.0.0.1:54322/postgres',
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
const config: Config = {
|
||||
db: adapter || databaseAdapters[process.env.PAYLOAD_DATABASE || 'mongodb'],
|
||||
db: databaseAdapters[process.env.PAYLOAD_DATABASE || 'mongodb'],
|
||||
secret: 'TEST_SECRET',
|
||||
//editor: slateEditor({}),
|
||||
// editor: slateEditor({
|
||||
|
||||
@@ -18,11 +18,6 @@ type Result = {
|
||||
}
|
||||
|
||||
export async function initPayloadE2E({ dirname }: Args): Promise<Result> {
|
||||
// @ts-expect-error
|
||||
process.env.NODE_ENV = 'test'
|
||||
process.env.NODE_OPTIONS = '--no-deprecation'
|
||||
process.env.PAYLOAD_DROP_DATABASE = 'true'
|
||||
|
||||
const testSuiteName = dirname.split('/').pop()
|
||||
const { beforeTest } = await createTestHooks(testSuiteName)
|
||||
await beforeTest()
|
||||
|
||||
@@ -21,11 +21,6 @@ type Result<T extends GeneratedTypes<T>> = {
|
||||
export async function initPayloadE2ENoConfig<T extends GeneratedTypes<T>>({
|
||||
dirname,
|
||||
}: Args): Promise<Result<T>> {
|
||||
// @ts-expect-error
|
||||
process.env.NODE_ENV = 'test'
|
||||
process.env.NODE_OPTIONS = '--no-deprecation'
|
||||
process.env.PAYLOAD_DROP_DATABASE = 'true'
|
||||
|
||||
const testSuiteName = dirname.split('/').pop()
|
||||
const { beforeTest } = await createTestHooks(testSuiteName)
|
||||
await beforeTest()
|
||||
|
||||
@@ -10,11 +10,6 @@ import { NextRESTClient } from './NextRESTClient.js'
|
||||
export async function initPayloadInt(
|
||||
config: Promise<SanitizedConfig>,
|
||||
): Promise<{ config: SanitizedConfig; payload: Payload; restClient: NextRESTClient }> {
|
||||
// @ts-expect-error
|
||||
process.env.NODE_ENV = 'test'
|
||||
process.env.NODE_OPTIONS = '--no-deprecation'
|
||||
process.env.PAYLOAD_DROP_DATABASE = 'true'
|
||||
|
||||
const payload = await getPayload({ config })
|
||||
const restClient = new NextRESTClient(payload.config)
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
/** @type {import('jest').Config} */
|
||||
const customJestConfig = {
|
||||
extensionsToTreatAsEsm: ['.ts', '.tsx'],
|
||||
@@ -10,6 +16,7 @@ const customJestConfig = {
|
||||
},
|
||||
reporters: ['default', ['github-actions', { silent: false }], 'summary'],
|
||||
testEnvironment: 'node',
|
||||
globalSetup: path.resolve(dirname, 'setup.ts'),
|
||||
testMatch: ['<rootDir>/**/*int.spec.ts'],
|
||||
testTimeout: 90000,
|
||||
transform: {
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { defineConfig } from '@playwright/test'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
export const EXPECT_TIMEOUT = 45000
|
||||
export const POLL_TOPASS_TIMEOUT = EXPECT_TIMEOUT * 4 // That way expect.poll() or expect().toPass can retry 4 times. 4x higher than default expect timeout => can retry 4 times if retryable expects are used inside
|
||||
@@ -13,6 +18,7 @@ export default defineConfig({
|
||||
trace: 'retain-on-failure',
|
||||
video: 'retain-on-failure',
|
||||
},
|
||||
globalSetup: path.resolve(dirname, 'setup.js'),
|
||||
expect: {
|
||||
timeout: EXPECT_TIMEOUT,
|
||||
},
|
||||
|
||||
23
test/setup.js
Normal file
23
test/setup.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import { MongoMemoryReplSet } from 'mongodb-memory-server'
|
||||
|
||||
// eslint-disable-next-line no-restricted-exports
|
||||
export default async () => {
|
||||
// @ts-expect-error
|
||||
process.env.NODE_ENV = 'test'
|
||||
process.env.PAYLOAD_DROP_DATABASE = 'true'
|
||||
process.env.NODE_OPTIONS = '--no-deprecation'
|
||||
|
||||
if (
|
||||
(!process.env.PAYLOAD_DATABASE || process.env.PAYLOAD_DATABASE === 'mongoose') &&
|
||||
!global._mongoMemoryServer
|
||||
) {
|
||||
global._mongoMemoryServer = await MongoMemoryReplSet.create({
|
||||
replSet: {
|
||||
count: 3,
|
||||
dbName: 'payloadmemory',
|
||||
},
|
||||
})
|
||||
|
||||
process.env.MONGODB_MEMORY_SERVER_URI = global._mongoMemoryServer.getUri()
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,6 @@
|
||||
}
|
||||
},
|
||||
"exclude": ["dist", "build", "node_modules", ".eslintrc.js", "dist/**/*.js", "**/dist/**/*.js"],
|
||||
"include": ["./**/*.ts", ".next/types/**/*.ts"],
|
||||
"include": ["./**/*.ts", ".next/types/**/*.ts", "setup.js"],
|
||||
"references": []
|
||||
}
|
||||
|
||||
@@ -160,4 +160,4 @@
|
||||
".next/types/**/*.ts",
|
||||
"scripts/**/*.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user