chore: adds retryWrites, fixes a few flakes (#5674)

This commit is contained in:
James Mikrut
2024-04-04 20:09:51 -04:00
committed by GitHub
6 changed files with 32 additions and 7 deletions

View File

@@ -79,7 +79,7 @@ export class BasePayload<TGeneratedTypes extends GeneratedTypes> {
return create<T>(this, options) return create<T>(this, options)
} }
db: BaseDatabaseAdapter db: DatabaseAdapter
decrypt = decrypt decrypt = decrypt
@@ -469,6 +469,6 @@ interface RequestContext {
[key: string]: unknown [key: string]: unknown
} }
// type DatabaseAdapter = BaseDatabaseAdapter type DatabaseAdapter = BaseDatabaseAdapter
export type { GeneratedTypes, Payload, RequestContext } export type { DatabaseAdapter, GeneratedTypes, Payload, RequestContext }

View File

@@ -367,6 +367,7 @@ describe('admin', () => {
test('collection — should render preview button when `admin.preview` is set', async () => { test('collection — should render preview button when `admin.preview` is set', async () => {
const collectionWithPreview = new AdminUrlUtil(serverURL, postsCollectionSlug) const collectionWithPreview = new AdminUrlUtil(serverURL, postsCollectionSlug)
await page.goto(collectionWithPreview.create) await page.goto(collectionWithPreview.create)
await page.waitForURL(collectionWithPreview.create)
await page.locator('#field-title').fill(title) await page.locator('#field-title').fill(title)
await saveDocAndAssert(page) await saveDocAndAssert(page)
await expect(page.locator('.btn.preview-btn')).toBeVisible() await expect(page.locator('.btn.preview-btn')).toBeVisible()
@@ -375,6 +376,7 @@ describe('admin', () => {
test('collection — should not render preview button when `admin.preview` is not set', async () => { test('collection — should not render preview button when `admin.preview` is not set', async () => {
const collectionWithoutPreview = new AdminUrlUtil(serverURL, group1Collection1Slug) const collectionWithoutPreview = new AdminUrlUtil(serverURL, group1Collection1Slug)
await page.goto(collectionWithoutPreview.create) await page.goto(collectionWithoutPreview.create)
await page.waitForURL(collectionWithoutPreview.create)
await page.locator('#field-title').fill(title) await page.locator('#field-title').fill(title)
await saveDocAndAssert(page) await saveDocAndAssert(page)
await expect(page.locator('.btn.preview-btn')).toBeHidden() await expect(page.locator('.btn.preview-btn')).toBeHidden()
@@ -769,6 +771,7 @@ describe('admin', () => {
test('should link second cell', async () => { test('should link second cell', async () => {
const { id } = await createPost() const { id } = await createPost()
await page.reload()
const linkCell = page.locator(`${tableRowLocator} td`).nth(1).locator('a') const linkCell = page.locator(`${tableRowLocator} td`).nth(1).locator('a')
await expect(linkCell).toHaveAttribute('href', `/admin/collections/posts/${id}`) await expect(linkCell).toHaveAttribute('href', `/admin/collections/posts/${id}`)
@@ -1180,6 +1183,7 @@ describe('admin', () => {
}) })
test('should select multiple rows', async () => { test('should select multiple rows', async () => {
await page.reload()
const selectAll = page.locator('.checkbox-input:has(#select-all)') const selectAll = page.locator('.checkbox-input:has(#select-all)')
await page.locator('.row-1 .cell-_select input').check() await page.locator('.row-1 .cell-_select input').check()
@@ -1251,6 +1255,7 @@ describe('admin', () => {
}) })
test('should sort', async () => { test('should sort', async () => {
await page.reload()
const upChevron = page.locator('#heading-number .sort-column__asc') const upChevron = page.locator('#heading-number .sort-column__asc')
const downChevron = page.locator('#heading-number .sort-column__desc') const downChevron = page.locator('#heading-number .sort-column__desc')

View File

@@ -15,6 +15,19 @@ import {
} from './slugs.js' } from './slugs.js'
export const seed = async (_payload) => { export const seed = async (_payload) => {
if (_payload.db.name === 'mongoose') {
await Promise.all(
_payload.config.collections.map(async (coll) => {
await new Promise((resolve, reject) => {
_payload.db?.collections[coll.slug]?.ensureIndexes(function (err) {
if (err) reject(err)
resolve(true)
})
})
}),
)
}
await executePromises( await executePromises(
[ [
() => () =>

View File

@@ -396,6 +396,8 @@ describe('fields - relationship', () => {
) )
await button.click() await button.click()
await wait(500)
const documentDrawer = page.locator('[id^=doc-drawer_relation-one_1_]') const documentDrawer = page.locator('[id^=doc-drawer_relation-one_1_]')
await expect(documentDrawer).toBeVisible() await expect(documentDrawer).toBeVisible()
}) })

View File

@@ -1917,9 +1917,10 @@ describe('fields', () => {
test('should upload using the document drawer', async () => { test('should upload using the document drawer', async () => {
await uploadImage() await uploadImage()
await wait(500)
// Open the media drawer and create a png upload // Open the media drawer and create a png upload
await page.locator('.field-type.upload .upload__toggler.doc-drawer__toggler').click() await page.locator('.field-type.upload .upload__toggler.doc-drawer__toggler').click()
await wait(500) // TODO: Fix this. Need to wait a bit until the form in the drawer mounted, otherwise values sometimes disappear. This is an issue for all drawers await wait(1000) // TODO: Fix this. Need to wait a bit until the form in the drawer mounted, otherwise values sometimes disappear. This is an issue for all drawers
await page await page
.locator('[id^=doc-drawer_uploads_1_] .file-field__upload input[type="file"]') .locator('[id^=doc-drawer_uploads_1_] .file-field__upload input[type="file"]')
.setInputFiles(path.resolve(dirname, './uploads/payload.png')) .setInputFiles(path.resolve(dirname, './uploads/payload.png'))
@@ -1945,8 +1946,8 @@ describe('fields', () => {
test('should clear selected upload', async () => { test('should clear selected upload', async () => {
await uploadImage() await uploadImage()
await wait(1000) // TODO: Fix this. Need to wait a bit until the form in the drawer mounted, otherwise values sometimes disappear. This is an issue for all drawers
await page.locator('.field-type.upload .upload__toggler.doc-drawer__toggler').click() await page.locator('.field-type.upload .upload__toggler.doc-drawer__toggler').click()
await wait(500) // TODO: Fix this. Need to wait a bit until the form in the drawer mounted, otherwise values sometimes disappear. This is an issue for all drawers
await page await page
.locator('[id^=doc-drawer_uploads_1_] .file-field__upload input[type="file"]') .locator('[id^=doc-drawer_uploads_1_] .file-field__upload input[type="file"]')

View File

@@ -12,13 +12,17 @@ export default async () => {
(!process.env.PAYLOAD_DATABASE || process.env.PAYLOAD_DATABASE === 'mongodb') && (!process.env.PAYLOAD_DATABASE || process.env.PAYLOAD_DATABASE === 'mongodb') &&
!global._mongoMemoryServer !global._mongoMemoryServer
) { ) {
global._mongoMemoryServer = await MongoMemoryReplSet.create({ const db = await MongoMemoryReplSet.create({
replSet: { replSet: {
count: 3, count: 3,
dbName: 'payloadmemory', dbName: 'payloadmemory',
}, },
}) })
process.env.MONGODB_MEMORY_SERVER_URI = global._mongoMemoryServer.getUri() global._mongoMemoryServer = db
process.env.MONGODB_MEMORY_SERVER_URI = `${global._mongoMemoryServer.getUri()}&retryWrites=true`
console.log(process.env.MONGODB_MEMORY_SERVER_URI)
} }
} }