From fa9bd6191c6139565c71c7cc5ee9c8b5709d0996 Mon Sep 17 00:00:00 2001 From: Elliot DeNolf Date: Sun, 17 Jul 2022 08:20:01 -0700 Subject: [PATCH] chore: run prettier on entire test dir --- test/array-update/config.ts | 42 +++++------ test/array-update/int.spec.ts | 5 +- test/auth/config.ts | 17 ++--- test/auth/e2e.spec.ts | 1 - test/buildConfig.ts | 7 +- test/collections-graphql/int.spec.ts | 4 +- test/collections/config.ts | 38 +++++----- test/collections/e2e.spec.ts | 4 +- test/fields-relationship/config.ts | 15 +++- test/fields-relationship/e2e.spec.ts | 8 +-- test/fields/collections/Blocks/index.ts | 4 +- .../collections/ConditionalLogic/index.ts | 1 - test/fields/collections/Point/index.ts | 1 - test/fields/collections/RichText/index.ts | 1 - test/fields/collections/Tabs/index.ts | 6 +- test/fields/collections/Text/index.ts | 1 - test/helpers.ts | 12 ++-- test/helpers/configHelpers.ts | 8 +-- test/helpers/rest.ts | 71 +++++++++---------- test/hooks/collections/Hook/index.ts | 58 ++++++++------- test/hooks/collections/Transform/index.ts | 4 +- test/hooks/config.ts | 5 +- test/uploads/config.ts | 3 +- test/uploads/int.spec.ts | 25 ++----- test/versions/config.ts | 10 +-- test/versions/e2e.spec.ts | 17 +++++ test/versions/index.template.ts | 58 --------------- 27 files changed, 181 insertions(+), 245 deletions(-) create mode 100644 test/versions/e2e.spec.ts delete mode 100644 test/versions/index.template.ts diff --git a/test/array-update/config.ts b/test/array-update/config.ts index a1f266bd01..02b4ea7ee4 100644 --- a/test/array-update/config.ts +++ b/test/array-update/config.ts @@ -1,24 +1,26 @@ import { buildConfig } from '../buildConfig'; export default buildConfig({ - collections: [{ - slug: 'arrays', - fields: [ - { - name: 'array', - type: 'array', - fields: [ - { - type: 'text', - name: 'required', - required: true, - }, - { - type: 'text', - name: 'optional', - }, - ], - }, - ], - }], + collections: [ + { + slug: 'arrays', + fields: [ + { + name: 'array', + type: 'array', + fields: [ + { + type: 'text', + name: 'required', + required: true, + }, + { + type: 'text', + name: 'optional', + }, + ], + }, + ], + }, + ], }); diff --git a/test/array-update/int.spec.ts b/test/array-update/int.spec.ts index 8a30b7003e..5670a96b70 100644 --- a/test/array-update/int.spec.ts +++ b/test/array-update/int.spec.ts @@ -36,9 +36,7 @@ describe('array-update', () => { }, }); - const arrayWithExistingValues = [ - ...doc.array, - ]; + const arrayWithExistingValues = [...doc.array]; const updatedText = 'this is some new text for the first item in array'; @@ -47,7 +45,6 @@ describe('array-update', () => { required: updatedText, }; - const updatedDoc = await payload.update({ id: doc.id, collection, diff --git a/test/auth/config.ts b/test/auth/config.ts index 6880e35e54..8cf17ae0f8 100644 --- a/test/auth/config.ts +++ b/test/auth/config.ts @@ -6,14 +6,15 @@ export default buildConfig({ admin: { user: 'users', }, - collections: [{ - slug, - auth: { - verify: true, - useAPIKey: true, - maxLoginAttempts: 2, + collections: [ + { + slug, + auth: { + verify: true, + useAPIKey: true, + maxLoginAttempts: 2, + }, + fields: [], }, - fields: [], - }, ], }); diff --git a/test/auth/e2e.spec.ts b/test/auth/e2e.spec.ts index f1cee1a482..a9fcd74071 100644 --- a/test/auth/e2e.spec.ts +++ b/test/auth/e2e.spec.ts @@ -5,7 +5,6 @@ import { initPayloadTest } from '../helpers/configHelpers'; import { firstRegister } from '../helpers'; import { slug } from './config'; - /** * TODO: Auth * change password diff --git a/test/buildConfig.ts b/test/buildConfig.ts index c2ba694b74..f54aabf3e3 100644 --- a/test/buildConfig.ts +++ b/test/buildConfig.ts @@ -2,7 +2,6 @@ import merge from 'deepmerge'; import { Config, SanitizedConfig } from '../src/config/types'; import { buildConfig as buildPayloadConfig } from '../src/config/build'; - const baseConfig: Config = { typescript: { outputFile: process.env.PAYLOAD_TS_OUTPUT_PATH, @@ -12,9 +11,10 @@ const baseConfig: Config = { export function buildConfig(overrides?: Partial): SanitizedConfig { if (process.env.NODE_ENV === 'test') { baseConfig.admin = { - ...baseConfig.admin || {}, + ...(baseConfig.admin || {}), webpack: (config) => { - const existingConfig = typeof overrides?.admin?.webpack === 'function' ? overrides.admin.webpack(config) : config; + const existingConfig = + typeof overrides?.admin?.webpack === 'function' ? overrides.admin.webpack(config) : config; return { ...existingConfig, cache: { @@ -30,6 +30,5 @@ export function buildConfig(overrides?: Partial): SanitizedConfig { baseConfig.admin.disable = true; } - return buildPayloadConfig(merge(baseConfig, overrides || {})); } diff --git a/test/collections-graphql/int.spec.ts b/test/collections-graphql/int.spec.ts index c4b4d74de1..9ab9d84cad 100644 --- a/test/collections-graphql/int.spec.ts +++ b/test/collections-graphql/int.spec.ts @@ -191,9 +191,7 @@ describe('collections-graphql', () => { const response = await client.request(query); const { docs } = response.Posts; - expect(docs).toContainEqual( - expect.objectContaining({ id: withDescription.id, title: withDescription.title }), - ); + expect(docs).toContainEqual(expect.objectContaining({ id: withDescription.id, title: withDescription.title })); }); it('exists - false', async () => { diff --git a/test/collections/config.ts b/test/collections/config.ts index 239233a1c8..2fc09a9037 100644 --- a/test/collections/config.ts +++ b/test/collections/config.ts @@ -5,27 +5,29 @@ import { buildConfig } from '../buildConfig'; export const slug = 'posts'; export interface Post { - id: string, - title: string, - description: string, - createdAt: Date, - updatedAt: Date, + id: string; + title: string; + description: string; + createdAt: Date; + updatedAt: Date; } export default buildConfig({ - collections: [{ - slug, - fields: [ - { - name: 'title', - type: 'text', - }, - { - name: 'description', - type: 'text', - }, - ], - }], + collections: [ + { + slug, + fields: [ + { + name: 'title', + type: 'text', + }, + { + name: 'description', + type: 'text', + }, + ], + }, + ], onInit: async (payload) => { await payload.create({ collection: 'users', diff --git a/test/collections/e2e.spec.ts b/test/collections/e2e.spec.ts index 634c3c19ee..b01aaa6720 100644 --- a/test/collections/e2e.spec.ts +++ b/test/collections/e2e.spec.ts @@ -64,7 +64,6 @@ describe('collections', () => { }); }); - describe('CRUD', () => { test('should create', async () => { await page.goto(url.create); @@ -182,8 +181,7 @@ describe('collections', () => { await wait(1000); await expect(page.locator(tableRowLocator)).toHaveCount(1); - const firstId = await page.locator(tableRowLocator).first().locator('td').first() - .innerText(); + const firstId = await page.locator(tableRowLocator).first().locator('td').first().innerText(); expect(firstId).toEqual(id); // Remove filter diff --git a/test/fields-relationship/config.ts b/test/fields-relationship/config.ts index e74f8f7e17..2f45dc0d03 100644 --- a/test/fields-relationship/config.ts +++ b/test/fields-relationship/config.ts @@ -14,7 +14,7 @@ export interface FieldsRelationship { id: string; relationship: RelationOne; relationshipHasMany: RelationOne[]; - relationshipHasManyMultiple: Array; + relationshipHasManyMultiple: Array; relationshipMultiple: Array; relationshipRestricted: RelationRestricted; relationshipWithTitle: RelationWithTitle; @@ -42,7 +42,13 @@ export default buildConfig({ { slug, admin: { - defaultColumns: ['id', 'relationship', 'relationshipRestricted', 'relationshipHasManyMultiple', 'relationshipWithTitle'], + defaultColumns: [ + 'id', + 'relationship', + 'relationshipRestricted', + 'relationshipHasManyMultiple', + 'relationshipWithTitle', + ], }, fields: [ { @@ -170,7 +176,10 @@ export default buildConfig({ data: { relationship: relationOneDocId, relationshipRestricted: restrictedDocId, - relationshipHasManyMultiple: relationOneIDs.map((id) => ({ relationTo: relationOneSlug, value: id })), + relationshipHasManyMultiple: relationOneIDs.map((id) => ({ + relationTo: relationOneSlug, + value: id, + })), }, }); }); diff --git a/test/fields-relationship/e2e.spec.ts b/test/fields-relationship/e2e.spec.ts index 3d3602bc1c..2fe3be6a09 100644 --- a/test/fields-relationship/e2e.spec.ts +++ b/test/fields-relationship/e2e.spec.ts @@ -12,13 +12,7 @@ import type { RelationTwo, RelationWithTitle, } from './config'; -import { - relationOneSlug, - relationRestrictedSlug, - relationTwoSlug, - relationWithTitleSlug, - slug, -} from './config'; +import { relationOneSlug, relationRestrictedSlug, relationTwoSlug, relationWithTitleSlug, slug } from './config'; import wait from '../../src/utilities/wait'; const { beforeAll, describe } = test; diff --git a/test/fields/collections/Blocks/index.ts b/test/fields/collections/Blocks/index.ts index 0d02f7d509..04907aeeac 100644 --- a/test/fields/collections/Blocks/index.ts +++ b/test/fields/collections/Blocks/index.ts @@ -62,9 +62,7 @@ export const blocksField: Field = { const BlockFields: CollectionConfig = { slug: 'block-fields', - fields: [ - blocksField, - ], + fields: [blocksField], }; export const blocksFieldSeedData = [ diff --git a/test/fields/collections/ConditionalLogic/index.ts b/test/fields/collections/ConditionalLogic/index.ts index 48df2439be..c7c950f944 100644 --- a/test/fields/collections/ConditionalLogic/index.ts +++ b/test/fields/collections/ConditionalLogic/index.ts @@ -32,5 +32,4 @@ export const conditionalLogicDoc = { fieldToToggle: 'spiderman', }; - export default ConditionalLogic; diff --git a/test/fields/collections/Point/index.ts b/test/fields/collections/Point/index.ts index 179fb43d5a..0087e4dec8 100644 --- a/test/fields/collections/Point/index.ts +++ b/test/fields/collections/Point/index.ts @@ -37,5 +37,4 @@ export const pointDoc = { group: { point: [1, 9] }, }; - export default PointFields; diff --git a/test/fields/collections/RichText/index.ts b/test/fields/collections/RichText/index.ts index 989945c577..63e92eaa47 100644 --- a/test/fields/collections/RichText/index.ts +++ b/test/fields/collections/RichText/index.ts @@ -166,5 +166,4 @@ export const richTextDoc = { ], }; - export default RichTextFields; diff --git a/test/fields/collections/Tabs/index.ts b/test/fields/collections/Tabs/index.ts index 070cfcf462..3a904f6145 100644 --- a/test/fields/collections/Tabs/index.ts +++ b/test/fields/collections/Tabs/index.ts @@ -33,9 +33,7 @@ const TabsFields: CollectionConfig = { { label: 'Tab with Blocks', description: 'Blocks are rendered here to ensure they populate and render correctly.', - fields: [ - blocksField, - ], + fields: [blocksField], }, { label: 'Tab with Group', @@ -95,7 +93,7 @@ const TabsFields: CollectionConfig = { export const tabsDoc = { array: [ { - text: 'Hello, I\'m the first row', + text: "Hello, I'm the first row", }, { text: 'Second row here', diff --git a/test/fields/collections/Text/index.ts b/test/fields/collections/Text/index.ts index 54c2e7f06d..95cb2ac0fa 100644 --- a/test/fields/collections/Text/index.ts +++ b/test/fields/collections/Text/index.ts @@ -18,5 +18,4 @@ export const textDoc = { text: 'Seeded text document', }; - export default TextFields; diff --git a/test/helpers.ts b/test/helpers.ts index c664723f72..69ea35f90d 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -4,14 +4,14 @@ import wait from '../src/utilities/wait'; import { devUser } from './credentials'; type FirstRegisterArgs = { - page: Page, - serverURL: string, -} + page: Page; + serverURL: string; +}; type LoginArgs = { - page: Page, - serverURL: string, -} + page: Page; + serverURL: string; +}; export async function firstRegister(args: FirstRegisterArgs): Promise { const { page, serverURL } = args; diff --git a/test/helpers/configHelpers.ts b/test/helpers/configHelpers.ts index 7478ad1976..77918b5b70 100644 --- a/test/helpers/configHelpers.ts +++ b/test/helpers/configHelpers.ts @@ -7,9 +7,9 @@ import type { InitOptions } from '../../src/config/types'; import payload from '../../src'; type Options = { - __dirname: string - init?: Partial -} + __dirname: string; + init?: Partial; +}; export async function initPayloadE2E(__dirname: string): Promise<{ serverURL: string }> { return initPayloadTest({ @@ -25,7 +25,7 @@ export async function initPayloadTest(options: Options): Promise<{ serverURL: st local: true, secret: uuid(), mongoURL: `mongodb://localhost/${uuid()}`, - ...options.init || {}, + ...(options.init || {}), }; process.env.PAYLOAD_DISABLE_ADMIN = 'true'; diff --git a/test/helpers/rest.ts b/test/helpers/rest.ts index ad73400359..df0e4b183a 100644 --- a/test/helpers/rest.ts +++ b/test/helpers/rest.ts @@ -8,46 +8,46 @@ import { devUser } from '../credentials'; require('isomorphic-fetch'); type Args = { - serverURL: string - defaultSlug: string -} + serverURL: string; + defaultSlug: string; +}; type LoginArgs = { - email: string - password: string - collection: string -} + email: string; + password: string; + collection: string; +}; type CreateArgs = { - slug?: string - data: T - auth?: boolean - file?: boolean -} + slug?: string; + data: T; + auth?: boolean; + file?: boolean; +}; type FindArgs = { - slug?: string - query?: Where - auth?: boolean -} + slug?: string; + query?: Where; + auth?: boolean; +}; type UpdateArgs = { - slug?: string - id: string - data: Partial - auth?: boolean - query?: any -} + slug?: string; + id: string; + data: Partial; + auth?: boolean; + query?: any; +}; type DeleteArgs = { - slug?: string - id: string - auth?: boolean -} + slug?: string; + id: string; + auth?: boolean; +}; type DocResponse = { - status: number - doc: T -} + status: number; + doc: T; +}; const headers = { 'Content-Type': 'application/json', @@ -148,14 +148,11 @@ export class RESTClient { if (args?.auth) { headers.Authorization = `JWT ${this.token}`; } - const response = await fetch( - `${this.serverURL}/api/${slug || this.defaultSlug}/${id}${formattedQs}`, - { - body: JSON.stringify(data), - headers, - method: 'put', - }, - ); + const response = await fetch(`${this.serverURL}/api/${slug || this.defaultSlug}/${id}${formattedQs}`, { + body: JSON.stringify(data), + headers, + method: 'put', + }); const { status } = response; const json = await response.json(); return { status, doc: json.doc }; diff --git a/test/hooks/collections/Hook/index.ts b/test/hooks/collections/Hook/index.ts index cb8bca3fd7..a9b3ad335e 100644 --- a/test/hooks/collections/Hook/index.ts +++ b/test/hooks/collections/Hook/index.ts @@ -7,55 +7,63 @@ const Hooks: CollectionConfig = { slug: hooksSlug, access: openAccess, hooks: { - beforeValidate: [({ data }) => (validateHookOrder('collectionBeforeValidate', data))], - beforeChange: [({ data }) => (validateHookOrder('collectionBeforeChange', data))], - afterChange: [({ doc }) => (validateHookOrder('collectionAfterChange', doc))], - beforeRead: [({ doc }) => (validateHookOrder('collectionBeforeRead', doc))], - afterRead: [({ doc }) => (validateHookOrder('collectionAfterRead', doc))], + beforeValidate: [({ data }) => validateHookOrder('collectionBeforeValidate', data)], + beforeChange: [({ data }) => validateHookOrder('collectionBeforeChange', data)], + afterChange: [({ doc }) => validateHookOrder('collectionAfterChange', doc)], + beforeRead: [({ doc }) => validateHookOrder('collectionBeforeRead', doc)], + afterRead: [({ doc }) => validateHookOrder('collectionAfterRead', doc)], }, fields: [ { name: 'fieldBeforeValidate', type: 'checkbox', hooks: { - beforeValidate: [({ data }) => { - data.fieldBeforeValidate = true; - validateHookOrder('fieldBeforeValidate', data); - return true; - }], + beforeValidate: [ + ({ data }) => { + data.fieldBeforeValidate = true; + validateHookOrder('fieldBeforeValidate', data); + return true; + }, + ], }, }, { name: 'fieldBeforeChange', type: 'checkbox', hooks: { - beforeChange: [({ data }) => { - data.fieldBeforeChange = true; - validateHookOrder('fieldBeforeChange', data); - return true; - }], + beforeChange: [ + ({ data }) => { + data.fieldBeforeChange = true; + validateHookOrder('fieldBeforeChange', data); + return true; + }, + ], }, }, { name: 'fieldAfterChange', type: 'checkbox', hooks: { - afterChange: [({ data }) => { - data.fieldAfterChange = true; - validateHookOrder('fieldAfterChange', data); - return true; - }], + afterChange: [ + ({ data }) => { + data.fieldAfterChange = true; + validateHookOrder('fieldAfterChange', data); + return true; + }, + ], }, }, { name: 'fieldAfterRead', type: 'checkbox', hooks: { - afterRead: [({ data }) => { - data.fieldAfterRead = true; - validateHookOrder('fieldAfterRead', data); - return true; - }], + afterRead: [ + ({ data }) => { + data.fieldAfterRead = true; + validateHookOrder('fieldAfterRead', data); + return true; + }, + ], }, }, { diff --git a/test/hooks/collections/Transform/index.ts b/test/hooks/collections/Transform/index.ts index faf98721e4..0b7cabe0ea 100644 --- a/test/hooks/collections/Transform/index.ts +++ b/test/hooks/collections/Transform/index.ts @@ -37,9 +37,7 @@ const TransformHooks: CollectionConfig = { }, ], hooks: { - beforeRead: [ - (operation) => operation.doc, - ], + beforeRead: [(operation) => operation.doc], beforeChange: [ (operation) => { operation.data.beforeChange = !operation.data.location?.coordinates; diff --git a/test/hooks/config.ts b/test/hooks/config.ts index dde8bc458b..ee351ded3d 100644 --- a/test/hooks/config.ts +++ b/test/hooks/config.ts @@ -4,10 +4,7 @@ import TransformHooks from './collections/Transform'; import Hooks, { hooksSlug } from './collections/Hook'; export default buildConfig({ - collections: [ - TransformHooks, - Hooks, - ], + collections: [TransformHooks, Hooks], onInit: async (payload) => { await payload.create({ collection: hooksSlug, diff --git a/test/uploads/config.ts b/test/uploads/config.ts index 50d67f51c4..dc4b8b8267 100644 --- a/test/uploads/config.ts +++ b/test/uploads/config.ts @@ -65,8 +65,7 @@ export default buildConfig({ }, ], }, - fields: [ - ], + fields: [], }, { slug: 'unstored-media', diff --git a/test/uploads/int.spec.ts b/test/uploads/int.spec.ts index 59e89ae001..18e941e58c 100644 --- a/test/uploads/int.spec.ts +++ b/test/uploads/int.spec.ts @@ -27,10 +27,7 @@ describe('Collections - Uploads', () => { describe('create', () => { it('creates from form data', async () => { const formData = new FormData(); - formData.append( - 'file', - fs.createReadStream(path.join(__dirname, './image.png')), - ); + formData.append('file', fs.createReadStream(path.join(__dirname, './image.png'))); const { status, doc } = await client.create({ file: true, @@ -62,10 +59,7 @@ describe('Collections - Uploads', () => { it('creates images that do not require all sizes', async () => { const formData = new FormData(); - formData.append( - 'file', - fs.createReadStream(path.join(__dirname, './small.png')), - ); + formData.append('file', fs.createReadStream(path.join(__dirname, './small.png'))); const { status, doc } = await client.create({ file: true, @@ -88,10 +82,7 @@ describe('Collections - Uploads', () => { it('creates media without storing a file', async () => { const formData = new FormData(); - formData.append( - 'file', - fs.createReadStream(path.join(__dirname, './small.png')), - ); + formData.append('file', fs.createReadStream(path.join(__dirname, './small.png'))); // unstored media const { status, doc } = await client.create({ @@ -125,10 +116,7 @@ describe('Collections - Uploads', () => { }); const formData = new FormData(); - formData.append( - 'file', - fs.createReadStream(path.join(__dirname, './small.png')), - ); + formData.append('file', fs.createReadStream(path.join(__dirname, './small.png'))); const { status, doc } = await client.update({ id: mediaDoc.id, @@ -147,10 +135,7 @@ describe('Collections - Uploads', () => { it('delete', async () => { const formData = new FormData(); - formData.append( - 'file', - fs.createReadStream(path.join(__dirname, './image.png')), - ); + formData.append('file', fs.createReadStream(path.join(__dirname, './image.png'))); const { doc } = await client.create({ file: true, diff --git a/test/versions/config.ts b/test/versions/config.ts index 9a335558fc..29fc689179 100644 --- a/test/versions/config.ts +++ b/test/versions/config.ts @@ -3,8 +3,10 @@ import { buildConfig } from '../buildConfig'; export const slug = 'slugname'; export default buildConfig({ - collections: [{ - slug, - fields: [], - }], + collections: [ + { + slug, + fields: [], + }, + ], }); diff --git a/test/versions/e2e.spec.ts b/test/versions/e2e.spec.ts new file mode 100644 index 0000000000..506caf0c55 --- /dev/null +++ b/test/versions/e2e.spec.ts @@ -0,0 +1,17 @@ +/** + * TODO: Versions, 3 separate collections + * - drafts + * - save draft before publishing + * - publish immediately + * - validation should be skipped when creating a draft + * + * - autosave + * - versions (no drafts) + * - version control shown + * - assert version counts increment + * - navigate to versions + * - versions view accurately shows number of versions + * - compare + * - restore version + * - specify locales to show + */ diff --git a/test/versions/index.template.ts b/test/versions/index.template.ts deleted file mode 100644 index e5d94ca8f3..0000000000 --- a/test/versions/index.template.ts +++ /dev/null @@ -1,58 +0,0 @@ -import type { Page } from '@playwright/test'; -import { expect, test } from '@playwright/test'; -import { AdminUrlUtil } from '../helpers/adminUrlUtil'; -import { initPayloadTest } from '../helpers/configHelpers'; -import { firstRegister } from '../helpers'; -import { slug } from './config'; - - -/** - * TODO: Versions, 3 separate collections - * - drafts - * - save draft before publishing - * - publish immediately - * - validation should be skipped when creating a draft - * - * - autosave - * - versions (no drafts) - * - version control shown - * - assert version counts increment - * - navigate to versions - * - versions view accurately shows number of versions - * - compare - * - restore version - * - specify locales to show - */ - -const { beforeAll, describe } = test; -let url: AdminUrlUtil; - -describe('suite name', () => { - let page: Page; - - beforeAll(async ({ browser }) => { - const { serverURL } = await initPayloadTest({ - __dirname, - init: { - local: false, - }, - }); - // await clearDocs(); // Clear any seeded data from onInit - - url = new AdminUrlUtil(serverURL, slug); - - const context = await browser.newContext(); - page = await context.newPage(); - - await firstRegister({ page, serverURL }); - }); - - // afterEach(async () => { - // }); - - describe('feature', () => { - it('testname', () => { - expect(1).toEqual(1); - }); - }); -});