temp2
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,103 +2,95 @@ 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) => {
|
||||
const blocksField = [
|
||||
{
|
||||
blockType: 'block',
|
||||
localized: 'text',
|
||||
text: 'text',
|
||||
},
|
||||
]
|
||||
export async function seed(_payload: Payload, parallel: boolean = false) {
|
||||
const blocksField = [
|
||||
{
|
||||
blockType: 'block',
|
||||
localized: 'text',
|
||||
text: 'text',
|
||||
},
|
||||
]
|
||||
|
||||
await executePromises(
|
||||
[
|
||||
() =>
|
||||
_payload.create({
|
||||
collection: 'users',
|
||||
data: {
|
||||
email: devUser.email,
|
||||
password: devUser.password,
|
||||
},
|
||||
depth: 0,
|
||||
overrideAccess: true,
|
||||
}),
|
||||
() =>
|
||||
_payload.create({
|
||||
collection: draftCollectionSlug,
|
||||
data: {
|
||||
blocksField,
|
||||
description: 'Description',
|
||||
radio: 'test',
|
||||
title: 'Draft Title',
|
||||
},
|
||||
depth: 0,
|
||||
overrideAccess: true,
|
||||
draft: true,
|
||||
}),
|
||||
],
|
||||
parallel,
|
||||
)
|
||||
|
||||
const { id: manyDraftsID } = await _payload.create({
|
||||
collection: draftCollectionSlug,
|
||||
data: {
|
||||
blocksField,
|
||||
description: 'Description',
|
||||
radio: 'test',
|
||||
title: 'Title With Many Versions',
|
||||
},
|
||||
depth: 0,
|
||||
overrideAccess: true,
|
||||
draft: true,
|
||||
})
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
await _payload.update({
|
||||
id: manyDraftsID,
|
||||
collection: draftCollectionSlug,
|
||||
await executePromises(
|
||||
[
|
||||
() =>
|
||||
_payload.create({
|
||||
collection: 'users',
|
||||
data: {
|
||||
title: `Title With Many Versions ${i + 2}`,
|
||||
email: devUser.email,
|
||||
password: devUser.password,
|
||||
},
|
||||
depth: 0,
|
||||
overrideAccess: true,
|
||||
})
|
||||
}
|
||||
}),
|
||||
() =>
|
||||
_payload.create({
|
||||
collection: draftCollectionSlug,
|
||||
data: {
|
||||
blocksField,
|
||||
description: 'Description',
|
||||
radio: 'test',
|
||||
title: 'Draft Title',
|
||||
},
|
||||
depth: 0,
|
||||
overrideAccess: true,
|
||||
draft: true,
|
||||
}),
|
||||
],
|
||||
parallel,
|
||||
)
|
||||
|
||||
await _payload.create({
|
||||
collection: draftCollectionSlug,
|
||||
data: {
|
||||
_status: 'published',
|
||||
blocksField,
|
||||
description: 'Description',
|
||||
radio: 'test',
|
||||
title: 'Published Title',
|
||||
},
|
||||
depth: 0,
|
||||
overrideAccess: true,
|
||||
draft: false,
|
||||
})
|
||||
|
||||
await _payload.create({
|
||||
collection: draftCollectionSlug,
|
||||
data: {
|
||||
blocksField,
|
||||
description: 'Description',
|
||||
title: titleToDelete,
|
||||
},
|
||||
depth: 0,
|
||||
overrideAccess: true,
|
||||
draft: true,
|
||||
})
|
||||
const { id: manyDraftsID } = await _payload.create({
|
||||
collection: draftCollectionSlug,
|
||||
data: {
|
||||
blocksField,
|
||||
description: 'Description',
|
||||
radio: 'test',
|
||||
title: 'Title With Many Versions',
|
||||
},
|
||||
depth: 0,
|
||||
overrideAccess: true,
|
||||
draft: true,
|
||||
})
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
await _payload.update({
|
||||
id: manyDraftsID,
|
||||
collection: draftCollectionSlug,
|
||||
data: {
|
||||
title: `Title With Many Versions ${i + 2}`,
|
||||
},
|
||||
depth: 0,
|
||||
overrideAccess: true,
|
||||
})
|
||||
}
|
||||
|
||||
await _payload.create({
|
||||
collection: draftCollectionSlug,
|
||||
data: {
|
||||
_status: 'published',
|
||||
blocksField,
|
||||
description: 'Description',
|
||||
radio: 'test',
|
||||
title: 'Published Title',
|
||||
},
|
||||
depth: 0,
|
||||
overrideAccess: true,
|
||||
draft: false,
|
||||
})
|
||||
|
||||
await _payload.create({
|
||||
collection: draftCollectionSlug,
|
||||
data: {
|
||||
blocksField,
|
||||
description: 'Description',
|
||||
title: titleToDelete,
|
||||
},
|
||||
depth: 0,
|
||||
overrideAccess: true,
|
||||
draft: true,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user