chore: sets env vars for tests in globalSetup
This commit is contained in:
@@ -1,10 +1,6 @@
|
|||||||
import { MongoMemoryReplSet } from 'mongodb-memory-server'
|
import { MongoMemoryReplSet } from 'mongodb-memory-server'
|
||||||
|
|
||||||
export const startMemoryDB = async () => {
|
export const startMemoryDB = async () => {
|
||||||
process.env.NODE_ENV = 'test'
|
|
||||||
process.env.PAYLOAD_DROP_DATABASE = 'true'
|
|
||||||
process.env.NODE_OPTIONS = '--no-deprecation'
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(!process.env.PAYLOAD_DATABASE || process.env.PAYLOAD_DATABASE === 'mongoose') &&
|
(!process.env.PAYLOAD_DATABASE || process.env.PAYLOAD_DATABASE === 'mongoose') &&
|
||||||
!global._mongoMemoryServer
|
!global._mongoMemoryServer
|
||||||
|
|||||||
@@ -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} */
|
/** @type {import('jest').Config} */
|
||||||
const customJestConfig = {
|
const customJestConfig = {
|
||||||
extensionsToTreatAsEsm: ['.ts', '.tsx'],
|
extensionsToTreatAsEsm: ['.ts', '.tsx'],
|
||||||
@@ -10,6 +16,7 @@ const customJestConfig = {
|
|||||||
},
|
},
|
||||||
reporters: ['default', ['github-actions', { silent: false }], 'summary'],
|
reporters: ['default', ['github-actions', { silent: false }], 'summary'],
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
|
globalSetup: path.resolve(dirname, 'setup.ts'),
|
||||||
testMatch: ['<rootDir>/**/*int.spec.ts'],
|
testMatch: ['<rootDir>/**/*int.spec.ts'],
|
||||||
testTimeout: 90000,
|
testTimeout: 90000,
|
||||||
transform: {
|
transform: {
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
import { defineConfig } from '@playwright/test'
|
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 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
|
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',
|
trace: 'retain-on-failure',
|
||||||
video: 'retain-on-failure',
|
video: 'retain-on-failure',
|
||||||
},
|
},
|
||||||
|
globalSetup: path.resolve(dirname, 'setup.ts'),
|
||||||
expect: {
|
expect: {
|
||||||
timeout: EXPECT_TIMEOUT,
|
timeout: EXPECT_TIMEOUT,
|
||||||
},
|
},
|
||||||
|
|||||||
7
test/setup.ts
Normal file
7
test/setup.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
// eslint-disable-next-line no-restricted-exports
|
||||||
|
export default () => {
|
||||||
|
// @ts-expect-error
|
||||||
|
process.env.NODE_ENV = 'test'
|
||||||
|
process.env.PAYLOAD_DROP_DATABASE = 'true'
|
||||||
|
process.env.NODE_OPTIONS = '--no-deprecation'
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user