chore: improve test suites, upgrade jest and playwright, add debug utilities for lexical (#4011)

* feat(richtext-lexical): 'bottom' position value for plugins

* feat: TestRecorderFeature

* chore: restructuring to seed and clear db before each test

* chore: make sure all tests pass

* chore: make sure indexes are created in seed.ts - this fixes one erroring test

* chore: speed up test runs through db snapshots

* chore: support drizzle when resetting db

* chore: simplify seeding process, by moving boilerplate db reset / snapshot logic into a wrapper function

* chore: add new seeding process to admin test suite

* chore(deps): upgrade jest and playwright

* chore: make sure mongoose-specific tests are not skipped

* chore: fix point test, which was depending on another test (that's bad!)

* chore: fix incorrect import

* chore: remove unnecessary comments

* chore: clearly label lexicalE2E test file as todo

* chore: simplify seed logic

* chore: move versions test suite to new seed system
This commit is contained in:
Alessio Gravili
2023-11-06 16:38:40 +01:00
committed by GitHub
parent 04850694c1
commit 17f7b94555
90 changed files with 2929 additions and 762 deletions

View File

@@ -8,28 +8,24 @@ import type { RichTextField } from './payload-types'
import payload from '../../packages/payload/src'
import { initPayloadTest } from '../helpers/configHelpers'
import { isMongoose } from '../helpers/isMongoose'
import { RESTClient } from '../helpers/rest'
import configPromise from '../uploads/config'
import { arrayDefaultValue, arrayFieldsSlug } from './collections/Array'
import { arrayDefaultValue } from './collections/Array'
import { blocksDoc } from './collections/Blocks'
import { dateDoc } from './collections/Date'
import {
groupDefaultChild,
groupDefaultValue,
groupDoc,
groupFieldsSlug,
} from './collections/Group'
import { groupDefaultChild, groupDefaultValue, groupDoc } from './collections/Group'
import { defaultNumber, numberDoc } from './collections/Number'
import { pointDoc } from './collections/Point'
import { relationshipFieldsSlug } from './collections/Relationship'
import { tabsDoc } from './collections/Tabs'
import {
localizedTextValue,
namedTabDefaultValue,
namedTabText,
tabsSlug,
} from './collections/Tabs/constants'
import { defaultText } from './collections/Text'
import { clearAndSeedEverything } from './seed'
import { arrayFieldsSlug, groupFieldsSlug, relationshipFieldsSlug, tabsFieldsSlug } from './slugs'
let client
let graphQLClient: GraphQLClient
@@ -48,10 +44,16 @@ describe('Fields', () => {
token = await client.login()
})
beforeEach(async () => {
await clearAndSeedEverything(payload)
client = new RESTClient(config, { defaultSlug: 'point-fields', serverURL })
await client.login()
})
describe('text', () => {
let doc
const text = 'text field'
beforeAll(async () => {
beforeEach(async () => {
doc = await payload.create({
collection: 'text-fields',
data: { text },
@@ -86,7 +88,7 @@ describe('Fields', () => {
const otherTextDocText = 'alt text'
const relationshipText = 'relationship text'
beforeAll(async () => {
beforeEach(async () => {
textDoc = await payload.create({
collection: 'text-fields',
data: {
@@ -193,7 +195,7 @@ describe('Fields', () => {
describe('timestamps', () => {
const tenMinutesAgo = new Date(Date.now() - 1000 * 60 * 10)
let doc
beforeAll(async () => {
beforeEach(async () => {
doc = await payload.create({
collection: 'date-fields',
data: dateDoc,
@@ -231,7 +233,7 @@ describe('Fields', () => {
describe('select', () => {
let doc
beforeAll(async () => {
beforeEach(async () => {
const { id } = await payload.create({
collection: 'select-fields',
data: {
@@ -273,7 +275,7 @@ describe('Fields', () => {
describe('number', () => {
let doc
beforeAll(async () => {
beforeEach(async () => {
doc = await payload.create({
collection: 'number-fields',
data: numberDoc,
@@ -375,13 +377,13 @@ describe('Fields', () => {
})
})
if (['mongoose'].includes(process.env.PAYLOAD_DATABASE)) {
if (isMongoose(payload) || !['postgres'].includes(process.env.PAYLOAD_DATABASE)) {
describe('indexes', () => {
let indexes
const definitions: Record<string, IndexDirection> = {}
const options: Record<string, IndexOptions> = {}
beforeAll(() => {
beforeEach(() => {
indexes = (payload.db as MongooseAdapter).collections[
'indexed-fields'
].schema.indexes() as [Record<string, IndexDirection>, IndexOptions]
@@ -434,7 +436,7 @@ describe('Fields', () => {
const definitions: Record<string, IndexDirection> = {}
const options: Record<string, IndexOptions> = {}
beforeAll(() => {
beforeEach(() => {
indexes = (payload.db as MongooseAdapter).versions['indexed-fields'].schema.indexes() as [
Record<string, IndexDirection>,
IndexOptions,
@@ -458,7 +460,7 @@ describe('Fields', () => {
const localized = [5, -2]
const group = { point: [1, 9] }
beforeAll(async () => {
beforeEach(async () => {
const findDoc = await payload.find({
collection: 'point-fields',
pagination: false,
@@ -495,6 +497,17 @@ describe('Fields', () => {
})
it('should not create duplicate point when unique', async () => {
// first create the point field
doc = await payload.create({
collection: 'point-fields',
data: {
group,
localized,
point,
},
})
// Now make sure we can't create a duplicate (since 'localized' is a unique field)
await expect(() =>
payload.create({
collection: 'point-fields',
@@ -546,7 +559,7 @@ describe('Fields', () => {
let doc
const collection = arrayFieldsSlug
beforeAll(async () => {
beforeEach(async () => {
doc = await payload.create({
collection,
data: {},
@@ -611,7 +624,7 @@ describe('Fields', () => {
describe('group', () => {
let document
beforeAll(async () => {
beforeEach(async () => {
document = await payload.create({
collection: groupFieldsSlug,
data: {},
@@ -627,9 +640,9 @@ describe('Fields', () => {
describe('tabs', () => {
let document
beforeAll(async () => {
beforeEach(async () => {
document = await payload.create({
collection: tabsSlug,
collection: tabsFieldsSlug,
data: tabsDoc,
})
})
@@ -649,7 +662,7 @@ describe('Fields', () => {
it('should create with localized text inside a named tab', async () => {
document = await payload.findByID({
id: document.id,
collection: tabsSlug,
collection: tabsFieldsSlug,
locale: 'all',
})
expect(document.localizedTab.en.text).toStrictEqual(localizedTextValue)
@@ -658,7 +671,7 @@ describe('Fields', () => {
it('should allow access control on a named tab', async () => {
document = await payload.findByID({
id: document.id,
collection: tabsSlug,
collection: tabsFieldsSlug,
overrideAccess: false,
})
expect(document.accessControlTab).toBeUndefined()
@@ -666,7 +679,7 @@ describe('Fields', () => {
it('should allow hooks on a named tab', async () => {
const newDocument = await payload.create({
collection: tabsSlug,
collection: tabsFieldsSlug,
data: tabsDoc,
})
expect(newDocument.hooksTab.beforeValidate).toBe(true)