diff --git a/test/helpers/startMemoryDB.ts b/test/helpers/startMemoryDB.ts index e21441945..8973d0f42 100644 --- a/test/helpers/startMemoryDB.ts +++ b/test/helpers/startMemoryDB.ts @@ -1,6 +1,11 @@ import { MongoMemoryReplSet } from 'mongodb-memory-server' export const startMemoryDB = 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 diff --git a/test/jest.config.js b/test/jest.config.js index ffc6eef5b..41f2102af 100644 --- a/test/jest.config.js +++ b/test/jest.config.js @@ -1,9 +1,3 @@ -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'], @@ -16,7 +10,6 @@ const customJestConfig = { }, reporters: ['default', ['github-actions', { silent: false }], 'summary'], testEnvironment: 'node', - globalSetup: path.resolve(dirname, 'setup.ts'), testMatch: ['/**/*int.spec.ts'], testTimeout: 90000, transform: { diff --git a/test/playwright.config.ts b/test/playwright.config.ts index 0a4eb660a..85218d8ab 100644 --- a/test/playwright.config.ts +++ b/test/playwright.config.ts @@ -1,9 +1,4 @@ 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 @@ -18,7 +13,6 @@ export default defineConfig({ trace: 'retain-on-failure', video: 'retain-on-failure', }, - globalSetup: path.resolve(dirname, 'setup.ts'), expect: { timeout: EXPECT_TIMEOUT, }, diff --git a/test/runE2E.ts b/test/runE2E.ts deleted file mode 100644 index 81dba165e..000000000 --- a/test/runE2E.ts +++ /dev/null @@ -1,100 +0,0 @@ -import glob from 'glob' -import minimist from 'minimist' -import path from 'path' -import shelljs from 'shelljs' -import slash from 'slash' -import { fileURLToPath } from 'url' - -const __filename = fileURLToPath(import.meta.url) -const dirname = path.dirname(__filename) - -shelljs.env.DISABLE_LOGGING = 'true' - -const playwrightBin = path.resolve(dirname, '../node_modules/.bin/playwright') - -const testRunCodes: { code: number; suiteName: string }[] = [] -const { _: args, bail, part } = minimist(process.argv.slice(2)) -const suiteName = args[0] - -// Run all -if (!suiteName) { - let files = glob.sync(`${path.resolve(dirname).replace(/\\/g, '/')}/**/*e2e.spec.ts`) - - const totalFiles = files.length - - if (part) { - if (!part.includes('/')) { - throw new Error('part must be in the format of "1/2"') - } - - const [partToRun, totalParts] = part.split('/').map((n) => parseInt(n)) - - if (partToRun > totalParts) { - throw new Error('part cannot be greater than totalParts') - } - - const partSize = Math.ceil(files.length / totalParts) - const start = (partToRun - 1) * partSize - const end = start + partSize - files = files.slice(start, end) - } - - if (files.length !== totalFiles) { - console.log(`\n\nExecuting part ${part}: ${files.length} of ${totalFiles} E2E tests...\n\n`) - } else { - console.log(`\n\nExecuting all ${files.length} E2E tests...\n\n`) - } - console.log(`${files.join('\n')}\n`) - - files.forEach((file) => { - clearWebpackCache() - executePlaywright(file, bail) - }) -} else { - // Run specific suite - clearWebpackCache() - let suitePath: string - if (suiteName.includes('/')) { - // Used for fields/lexical.e2e.spec.ts which is run from CI as fields/lexical - const suiteNameSplit = suiteName.split('/') - suitePath = path.resolve(dirname, suiteNameSplit[0], suiteNameSplit[1] + '.e2e.spec.ts') - } else { - suitePath = path.resolve(dirname, suiteName, 'e2e.spec.ts') - } - executePlaywright(suitePath) -} - -console.log('\nRESULTS:') -testRunCodes.forEach((tr) => { - console.log(`\tSuite: ${tr.suiteName}, Success: ${tr.code === 0}`) -}) -console.log('\n') - -if (testRunCodes.some((tr) => tr.code > 0)) process.exit(1) - -function executePlaywright(suitePath: string, bail = false) { - console.log(`Executing ${suitePath}...`) - const playwrightCfg = path.resolve( - dirname, - `${bail ? 'playwright.bail.config.ts' : 'playwright.config.ts'}`, - ) - - const cmd = slash(`${playwrightBin} test ${suitePath} -c ${playwrightCfg}`) - console.log('\n', cmd) - const { stdout, code } = shelljs.exec(cmd) - const suite = path.basename(path.dirname(suitePath)) - const results = { suiteName: suite, code } - if (code) { - if (bail) { - console.error(`TEST FAILURE DURING ${suite} suite.`) - process.exit(1) - } - } - testRunCodes.push(results) - return stdout -} - -function clearWebpackCache() { - const webpackCachePath = path.resolve(dirname, '../node_modules/.cache/webpack') - shelljs.rm('-rf', webpackCachePath) -}