This commit is contained in:
Alessio Gravili
2024-04-01 22:41:24 -04:00
parent df9812b2a3
commit ee3ae6025f
4 changed files with 110 additions and 102 deletions

View File

@@ -77,10 +77,13 @@ export async function buildConfigWithDefaults(
): Promise<SanitizedConfig> {
if (!process.env.PAYLOAD_DATABASE || process.env.PAYLOAD_DATABASE === 'mongodb') {
if (process.env.JEST_WORKER_ID || process.env.PW_TS_ESM_LOADER_ON) {
console.log('Good: Using in-memory MongoDB for tests')
if (cached.adapter) {
console.log('MDB: Cached')
databaseAdapters.mongodb = cached.adapter
} else {
if (!cached.promise) {
console.log('MDB: Creating')
cached.promise = MongoMemoryReplSet.create({
replSet: {
count: 3,
@@ -94,13 +97,18 @@ export async function buildConfigWithDefaults(
})
})
}
console.log('MDB: Awaiting')
cached.adapter = await cached.promise
cached.promise = null
databaseAdapters.mongodb = cached.adapter
}
} else {
console.log('Bad1!!')
}
} else {
console.log('Bad2!!')
}
const config: Config = {

View File

@@ -8,7 +8,7 @@ import VersionPosts from './collections/Versions.js'
import AutosaveGlobal from './globals/Autosave.js'
import DisablePublishGlobal from './globals/DisablePublish.js'
import DraftGlobal from './globals/Draft.js'
import { clearAndSeedEverything } from './seed.js'
import { seed } from './seed.js'
export default buildConfigWithDefaults({
collections: [DisablePublish, Posts, AutosavePosts, DraftPosts, VersionPosts, CustomIDs],
@@ -20,7 +20,7 @@ export default buildConfigWithDefaults({
},
onInit: async (payload) => {
if (process.env.SEED_IN_CONFIG_ONINIT !== 'false') {
await clearAndSeedEverything(payload)
await seed(payload)
}
},
})

View File

@@ -24,12 +24,14 @@
*/
import type { Page } from '@playwright/test'
import type { Payload } from 'payload/types'
import { expect, test } from '@playwright/test'
import path from 'path'
import { fileURLToPath } from 'url'
import type { PayloadTestSDK } from '../helpers/sdk/index.js'
import type { Config } from './payload-types.js'
import { globalSlug } from '../admin/slugs.js'
import {
changeLocale,
@@ -40,9 +42,9 @@ import {
selectTableRow,
} from '../helpers.js'
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js'
import { reInitializeDB } from '../helpers/reInit.js'
import { POLL_TOPASS_TIMEOUT } from '../playwright.config.js'
import { clearAndSeedEverything } from './seed.js'
import { titleToDelete } from './shared.js'
import {
autoSaveGlobalSlug,
@@ -54,12 +56,13 @@ import {
draftGlobalSlug,
postCollectionSlug,
} from './slugs.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
const { beforeAll, beforeEach, describe } = test
let payload: Payload
let payload: PayloadTestSDK<Config>
const waitForAutoSaveToComplete = async (page: Page) => {
await expect(async () => {
@@ -88,7 +91,7 @@ describe('versions', () => {
beforeAll(async ({ browser }) => {
process.env.SEED_IN_CONFIG_ONINIT = 'false' // Makes it so the payload config onInit seed is not run. Otherwise, the seed would be run unnecessarily twice for the initial test run - once for beforeEach and once for onInit
;({ payload, serverURL } = await initPayloadE2E({ dirname }))
;({ payload, serverURL } = await initPayloadE2ENoConfig<Config>({ dirname }))
const context = await browser.newContext()
page = await context.newPage()
@@ -96,7 +99,11 @@ describe('versions', () => {
})
beforeEach(async () => {
await clearAndSeedEverything(payload)
await reInitializeDB({
serverURL,
snapshotKey: 'versionsTest',
})
//await clearAndSeedEverything(payload)
})
describe('draft collections', () => {
@@ -408,17 +415,18 @@ describe('versions', () => {
test('collection - autosave should only update the current document', async () => {
// create and save first doc
await page.goto(autosaveURL.create)
await page.waitForURL(`${autosaveURL.create}`)
await page.waitForURL(/\/(?!create$)[\w-]+$/)
// Should redirect from /create to /[collectionslug]/[new id] due to auto-save
await page.waitForURL(`${autosaveURL.list}/**`) // TODO: Make sure this doesnt match for list view and /create view, but only for the ID edit view
await page.locator('#field-title').fill('first post title')
await page.locator('#field-description').fill('first post description')
await page.locator('#action-save').click()
await saveDocAndAssert(page)
// create and save second doc
console.log('Goto autosaveURL.create', autosaveURL.create)
await page.goto(autosaveURL.create)
await page.waitForURL(`${autosaveURL.create}`)
await page.waitForURL(/\/(?!create$)[\w-]+$/)
// Should redirect from /create to /[collectionslug]/[new id] due to auto-save
await page.waitForURL(`${autosaveURL.list}/**`)
await page.locator('#field-title').fill('second post title')
await page.locator('#field-description').fill('second post description')
// publish changes

View File

@@ -2,16 +2,10 @@ import { type Payload } from 'payload'
import { devUser } from '../credentials.js'
import { executePromises } from '../helpers/executePromises.js'
import { seedDB } from '../helpers/seed.js'
import { titleToDelete } from './shared.js'
import { collectionSlugs, draftCollectionSlug } from './slugs.js'
import { draftCollectionSlug } from './slugs.js'
export async function clearAndSeedEverything(_payload: Payload, parallel: boolean = false) {
return await seedDB({
snapshotKey: 'versionsTest',
collectionSlugs,
_payload,
seedFunction: async (_payload) => {
export async function seed(_payload: Payload, parallel: boolean = false) {
const blocksField = [
{
blockType: 'block',
@@ -99,6 +93,4 @@ export async function clearAndSeedEverything(_payload: Payload, parallel: boolea
overrideAccess: true,
draft: true,
})
},
})
}