temp2
This commit is contained in:
@@ -77,10 +77,13 @@ export async function buildConfigWithDefaults(
|
|||||||
): Promise<SanitizedConfig> {
|
): Promise<SanitizedConfig> {
|
||||||
if (!process.env.PAYLOAD_DATABASE || process.env.PAYLOAD_DATABASE === 'mongodb') {
|
if (!process.env.PAYLOAD_DATABASE || process.env.PAYLOAD_DATABASE === 'mongodb') {
|
||||||
if (process.env.JEST_WORKER_ID || process.env.PW_TS_ESM_LOADER_ON) {
|
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) {
|
if (cached.adapter) {
|
||||||
|
console.log('MDB: Cached')
|
||||||
databaseAdapters.mongodb = cached.adapter
|
databaseAdapters.mongodb = cached.adapter
|
||||||
} else {
|
} else {
|
||||||
if (!cached.promise) {
|
if (!cached.promise) {
|
||||||
|
console.log('MDB: Creating')
|
||||||
cached.promise = MongoMemoryReplSet.create({
|
cached.promise = MongoMemoryReplSet.create({
|
||||||
replSet: {
|
replSet: {
|
||||||
count: 3,
|
count: 3,
|
||||||
@@ -94,13 +97,18 @@ export async function buildConfigWithDefaults(
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
console.log('MDB: Awaiting')
|
||||||
|
|
||||||
cached.adapter = await cached.promise
|
cached.adapter = await cached.promise
|
||||||
cached.promise = null
|
cached.promise = null
|
||||||
|
|
||||||
databaseAdapters.mongodb = cached.adapter
|
databaseAdapters.mongodb = cached.adapter
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log('Bad1!!')
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log('Bad2!!')
|
||||||
}
|
}
|
||||||
|
|
||||||
const config: Config = {
|
const config: Config = {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import VersionPosts from './collections/Versions.js'
|
|||||||
import AutosaveGlobal from './globals/Autosave.js'
|
import AutosaveGlobal from './globals/Autosave.js'
|
||||||
import DisablePublishGlobal from './globals/DisablePublish.js'
|
import DisablePublishGlobal from './globals/DisablePublish.js'
|
||||||
import DraftGlobal from './globals/Draft.js'
|
import DraftGlobal from './globals/Draft.js'
|
||||||
import { clearAndSeedEverything } from './seed.js'
|
import { seed } from './seed.js'
|
||||||
|
|
||||||
export default buildConfigWithDefaults({
|
export default buildConfigWithDefaults({
|
||||||
collections: [DisablePublish, Posts, AutosavePosts, DraftPosts, VersionPosts, CustomIDs],
|
collections: [DisablePublish, Posts, AutosavePosts, DraftPosts, VersionPosts, CustomIDs],
|
||||||
@@ -20,7 +20,7 @@ export default buildConfigWithDefaults({
|
|||||||
},
|
},
|
||||||
onInit: async (payload) => {
|
onInit: async (payload) => {
|
||||||
if (process.env.SEED_IN_CONFIG_ONINIT !== 'false') {
|
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 { Page } from '@playwright/test'
|
||||||
import type { Payload } from 'payload/types'
|
|
||||||
|
|
||||||
import { expect, test } from '@playwright/test'
|
import { expect, test } from '@playwright/test'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { fileURLToPath } from 'url'
|
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 { globalSlug } from '../admin/slugs.js'
|
||||||
import {
|
import {
|
||||||
changeLocale,
|
changeLocale,
|
||||||
@@ -40,9 +42,9 @@ import {
|
|||||||
selectTableRow,
|
selectTableRow,
|
||||||
} from '../helpers.js'
|
} from '../helpers.js'
|
||||||
import { AdminUrlUtil } from '../helpers/adminUrlUtil.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 { POLL_TOPASS_TIMEOUT } from '../playwright.config.js'
|
||||||
import { clearAndSeedEverything } from './seed.js'
|
|
||||||
import { titleToDelete } from './shared.js'
|
import { titleToDelete } from './shared.js'
|
||||||
import {
|
import {
|
||||||
autoSaveGlobalSlug,
|
autoSaveGlobalSlug,
|
||||||
@@ -54,12 +56,13 @@ import {
|
|||||||
draftGlobalSlug,
|
draftGlobalSlug,
|
||||||
postCollectionSlug,
|
postCollectionSlug,
|
||||||
} from './slugs.js'
|
} from './slugs.js'
|
||||||
|
|
||||||
const filename = fileURLToPath(import.meta.url)
|
const filename = fileURLToPath(import.meta.url)
|
||||||
const dirname = path.dirname(filename)
|
const dirname = path.dirname(filename)
|
||||||
|
|
||||||
const { beforeAll, beforeEach, describe } = test
|
const { beforeAll, beforeEach, describe } = test
|
||||||
|
|
||||||
let payload: Payload
|
let payload: PayloadTestSDK<Config>
|
||||||
|
|
||||||
const waitForAutoSaveToComplete = async (page: Page) => {
|
const waitForAutoSaveToComplete = async (page: Page) => {
|
||||||
await expect(async () => {
|
await expect(async () => {
|
||||||
@@ -88,7 +91,7 @@ describe('versions', () => {
|
|||||||
|
|
||||||
beforeAll(async ({ browser }) => {
|
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
|
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()
|
const context = await browser.newContext()
|
||||||
page = await context.newPage()
|
page = await context.newPage()
|
||||||
|
|
||||||
@@ -96,7 +99,11 @@ describe('versions', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await clearAndSeedEverything(payload)
|
await reInitializeDB({
|
||||||
|
serverURL,
|
||||||
|
snapshotKey: 'versionsTest',
|
||||||
|
})
|
||||||
|
//await clearAndSeedEverything(payload)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('draft collections', () => {
|
describe('draft collections', () => {
|
||||||
@@ -408,17 +415,18 @@ describe('versions', () => {
|
|||||||
test('collection - autosave should only update the current document', async () => {
|
test('collection - autosave should only update the current document', async () => {
|
||||||
// create and save first doc
|
// create and save first doc
|
||||||
await page.goto(autosaveURL.create)
|
await page.goto(autosaveURL.create)
|
||||||
await page.waitForURL(`${autosaveURL.create}`)
|
// Should redirect from /create to /[collectionslug]/[new id] due to auto-save
|
||||||
await page.waitForURL(/\/(?!create$)[\w-]+$/)
|
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-title').fill('first post title')
|
||||||
await page.locator('#field-description').fill('first post description')
|
await page.locator('#field-description').fill('first post description')
|
||||||
await page.locator('#action-save').click()
|
await saveDocAndAssert(page)
|
||||||
|
|
||||||
// create and save second doc
|
// create and save second doc
|
||||||
|
console.log('Goto autosaveURL.create', autosaveURL.create)
|
||||||
await page.goto(autosaveURL.create)
|
await page.goto(autosaveURL.create)
|
||||||
await page.waitForURL(`${autosaveURL.create}`)
|
// Should redirect from /create to /[collectionslug]/[new id] due to auto-save
|
||||||
await page.waitForURL(/\/(?!create$)[\w-]+$/)
|
await page.waitForURL(`${autosaveURL.list}/**`)
|
||||||
await page.locator('#field-title').fill('second post title')
|
await page.locator('#field-title').fill('second post title')
|
||||||
await page.locator('#field-description').fill('second post description')
|
await page.locator('#field-description').fill('second post description')
|
||||||
// publish changes
|
// publish changes
|
||||||
|
|||||||
@@ -2,16 +2,10 @@ import { type Payload } from 'payload'
|
|||||||
|
|
||||||
import { devUser } from '../credentials.js'
|
import { devUser } from '../credentials.js'
|
||||||
import { executePromises } from '../helpers/executePromises.js'
|
import { executePromises } from '../helpers/executePromises.js'
|
||||||
import { seedDB } from '../helpers/seed.js'
|
|
||||||
import { titleToDelete } from './shared.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) {
|
export async function seed(_payload: Payload, parallel: boolean = false) {
|
||||||
return await seedDB({
|
|
||||||
snapshotKey: 'versionsTest',
|
|
||||||
collectionSlugs,
|
|
||||||
_payload,
|
|
||||||
seedFunction: async (_payload) => {
|
|
||||||
const blocksField = [
|
const blocksField = [
|
||||||
{
|
{
|
||||||
blockType: 'block',
|
blockType: 'block',
|
||||||
@@ -99,6 +93,4 @@ export async function clearAndSeedEverything(_payload: Payload, parallel: boolea
|
|||||||
overrideAccess: true,
|
overrideAccess: true,
|
||||||
draft: true,
|
draft: true,
|
||||||
})
|
})
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user