From ba79b4446c01c121c45d0c9640afbbe125da50a5 Mon Sep 17 00:00:00 2001 From: Elliot DeNolf Date: Fri, 15 Jul 2022 12:51:43 -0700 Subject: [PATCH] test: refactor all test directories into one --- jest.config.js | 3 +- playwright.config.ts | 2 +- src/errors/errors.spec.ts | 29 -- src/tests/helpers/configHelpers.ts | 55 --- test/{e2e => }/access-control/config.ts | 26 +- .../e2e.spec.ts} | 33 +- .../{e2e => }/access-control/payload-types.ts | 10 + test/{int => }/array-update/config.ts | 0 .../int.spec.ts} | 4 +- test/{int => }/array-update/payload-types.ts | 0 test/{e2e => }/auth/config.ts | 0 test/auth/e2e.spec.ts | 69 +++ test/{e2e => }/auth/payload-types.ts | 0 test/buildConfig.ts | 37 ++ test/{int => }/collections-graphql/config.ts | 0 .../int.spec.ts} | 6 +- .../collections-graphql/payload-types.ts | 0 test/{int => }/collections-rest/config.ts | 4 +- .../int.spec.ts} | 8 +- .../collections-rest/payload-types.ts | 0 test/{e2e => }/collections/config.ts | 4 +- .../index.spec.ts => collections/e2e.spec.ts} | 10 +- test/{e2e => }/collections/payload-types.ts | 0 test/dev/server.ts | 1 - test/e2e/auth/index.spec.ts | 69 --- test/e2e/buildConfig.ts | 23 - test/{e2e => }/fields-array/config.ts | 0 .../e2e.spec.ts} | 6 +- test/{e2e => }/fields-array/payload-types.ts | 0 test/{e2e => }/fields-relationship/config.ts | 6 +- .../e2e.spec.ts} | 10 +- .../fields-relationship/payload-types.ts | 0 .../fields/collections/Array/index.ts | 2 +- .../fields/collections/Blocks/index.ts | 2 +- .../fields/collections/Collapsible/index.ts | 2 +- .../fields/collections/RichText/index.ts | 2 +- .../fields/collections/Select/index.ts | 2 +- .../fields/collections/Text/index.ts | 2 +- test/{e2e => }/fields/config.ts | 2 +- .../index.spec.ts => fields/e2e.spec.ts} | 4 +- test/{e2e => }/fields/payload-types.ts | 0 test/{e2e => }/helpers.ts | 4 +- test/helpers/configHelpers.ts | 1 + test/int/buildConfig.ts | 19 - test/int/uploads/index.spec.ts | 438 ------------------ test/jest.setup.ts | 3 + test/{e2e => }/localization/config.ts | 2 +- .../e2e.spec.ts} | 10 +- test/{e2e => }/localization/payload-types.ts | 0 test/uploads/config.ts | 4 +- test/uploads/e2e.spec.ts | 2 +- test/{e2e => }/versions/config.ts | 0 test/{e2e => }/versions/index.template.ts | 6 +- test/{e2e => }/versions/payload-types.ts | 0 54 files changed, 224 insertions(+), 698 deletions(-) delete mode 100644 src/errors/errors.spec.ts delete mode 100644 src/tests/helpers/configHelpers.ts rename test/{e2e => }/access-control/config.ts (72%) rename test/{e2e/access-control/index.spec.ts => access-control/e2e.spec.ts} (80%) rename test/{e2e => }/access-control/payload-types.ts (84%) rename test/{int => }/array-update/config.ts (100%) rename test/{int/array-update/index.spec.ts => array-update/int.spec.ts} (96%) rename test/{int => }/array-update/payload-types.ts (100%) rename test/{e2e => }/auth/config.ts (100%) create mode 100644 test/auth/e2e.spec.ts rename test/{e2e => }/auth/payload-types.ts (100%) create mode 100644 test/buildConfig.ts rename test/{int => }/collections-graphql/config.ts (100%) rename test/{int/collections-graphql/index.spec.ts => collections-graphql/int.spec.ts} (86%) rename test/{int => }/collections-graphql/payload-types.ts (100%) rename test/{int => }/collections-rest/config.ts (96%) rename test/{int/collections-rest/index.spec.ts => collections-rest/int.spec.ts} (98%) rename test/{int => }/collections-rest/payload-types.ts (100%) rename test/{e2e => }/collections/config.ts (88%) rename test/{e2e/collections/index.spec.ts => collections/e2e.spec.ts} (97%) rename test/{e2e => }/collections/payload-types.ts (100%) delete mode 100644 test/e2e/auth/index.spec.ts delete mode 100644 test/e2e/buildConfig.ts rename test/{e2e => }/fields-array/config.ts (100%) rename test/{e2e/fields-array/index.spec.ts => fields-array/e2e.spec.ts} (86%) rename test/{e2e => }/fields-array/payload-types.ts (100%) rename test/{e2e => }/fields-relationship/config.ts (97%) rename test/{e2e/fields-relationship/index.spec.ts => fields-relationship/e2e.spec.ts} (96%) rename test/{e2e => }/fields-relationship/payload-types.ts (100%) rename test/{e2e => }/fields/collections/Array/index.ts (87%) rename test/{e2e => }/fields/collections/Blocks/index.ts (95%) rename test/{e2e => }/fields/collections/Collapsible/index.ts (84%) rename test/{e2e => }/fields/collections/RichText/index.ts (95%) rename test/{e2e => }/fields/collections/Select/index.ts (92%) rename test/{e2e => }/fields/collections/Text/index.ts (77%) rename test/{e2e => }/fields/config.ts (97%) rename test/{e2e/fields/index.spec.ts => fields/e2e.spec.ts} (87%) rename test/{e2e => }/fields/payload-types.ts (100%) rename test/{e2e => }/helpers.ts (93%) delete mode 100644 test/int/buildConfig.ts delete mode 100644 test/int/uploads/index.spec.ts create mode 100644 test/jest.setup.ts rename test/{e2e => }/localization/config.ts (93%) rename test/{e2e/localization/index.spec.ts => localization/e2e.spec.ts} (92%) rename test/{e2e => }/localization/payload-types.ts (100%) rename test/{e2e => }/versions/config.ts (100%) rename test/{e2e => }/versions/index.template.ts (89%) rename test/{e2e => }/versions/payload-types.ts (100%) diff --git a/jest.config.js b/jest.config.js index ef2ce3552..40ac01b5d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,8 +2,9 @@ module.exports = { verbose: true, testEnvironment: 'node', testMatch: [ - '**/test/int/**/*spec.ts', + '**/test/**/*int.spec.ts', ], + globalSetup: './test/jest.setup.ts', testTimeout: 15000, moduleNameMapper: { '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '/src/webpack/mocks/fileMock.js', diff --git a/playwright.config.ts b/playwright.config.ts index f34fbc2ff..2b4a0f993 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -4,7 +4,7 @@ import type { PlaywrightTestConfig } from '@playwright/test'; const config: PlaywrightTestConfig = { // Look for test files in the "tests" directory, relative to this configuration file testDir: 'test', - testMatch: 'e2e.spec.ts', + testMatch: '*e2e.spec.ts', workers: 999, timeout: 600000, }; diff --git a/src/errors/errors.spec.ts b/src/errors/errors.spec.ts deleted file mode 100644 index 08c616f0f..000000000 --- a/src/errors/errors.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { APIError } from '.'; - -describe('Errors', () => { - describe('APIError', () => { - it('should handle an error message', () => { - const error = new APIError('my message', 400, false); - expect(error.message).toStrictEqual('my message'); - }); - - // it('should handle an array', () => { - // const errors = [ - // { - // error: 'some error description', - // }, - // { - // error: 'some error description 2', - // }, - // ]; - // const error = new APIError(errors, 400, false); - // expect(error.message).toStrictEqual(JSON.stringify(errors)); - // }); - - // it('should handle an object', () => { - // const myFancyErrorObject = { someProp: 'someDetail ' }; - // const error = new APIError(myFancyErrorObject, 400, false); - // expect(error.message).toStrictEqual(JSON.stringify(myFancyErrorObject)); - // }); - }); -}); diff --git a/src/tests/helpers/configHelpers.ts b/src/tests/helpers/configHelpers.ts deleted file mode 100644 index ca70a95f2..000000000 --- a/src/tests/helpers/configHelpers.ts +++ /dev/null @@ -1,55 +0,0 @@ -import merge from 'deepmerge'; -import path from 'path'; -import { v4 as uuid } from 'uuid'; -import { CollectionConfig } from '../../collections/config/types'; -import { Config, SanitizedConfig, InitOptions } from '../../config/types'; -import { buildConfig } from '../../config/build'; -import payload from '../..'; - - -const Admins: CollectionConfig = { - slug: 'admins', - auth: true, - fields: [ - // Email added by default - { - name: 'name', - type: 'text', - }, - ], -}; - -const baseConfig: Config = { - serverURL: 'http://localhost:3000', - admin: { - user: Admins.slug, - }, - collections: [ - Admins, - ], -}; - -export function generateTestConfig(overrides?: Partial): SanitizedConfig { - return buildConfig(merge(baseConfig, overrides)); -} - -type InitPayloadTestOptions = { initOptions?: Partial } -export function initPayloadTest(dirName: string, initOptions?: InitPayloadTestOptions): void { - process.env.PAYLOAD_CONFIG_PATH = path.resolve(dirName, './payload.config.ts'); - - payload.init({ - local: true, - mongoURL: `mongodb://localhost/${uuid()}`, - secret: uuid(), - // TODO: Figure out how to handle express - ...initOptions, - }); -} - - -export const openAccess: CollectionConfig['access'] = { - read: () => true, - create: () => true, - delete: () => true, - update: () => true, -}; diff --git a/test/e2e/access-control/config.ts b/test/access-control/config.ts similarity index 72% rename from test/e2e/access-control/config.ts rename to test/access-control/config.ts index 82fde1c3c..9f959f16d 100644 --- a/test/e2e/access-control/config.ts +++ b/test/access-control/config.ts @@ -1,10 +1,10 @@ -import { devUser } from '../../credentials'; +import { devUser } from '../credentials'; import { buildConfig } from '../buildConfig'; -import type { ReadOnlyCollection } from './payload-types'; export const slug = 'access-controls'; export const readOnlySlug = 'read-only-collection'; export const restrictedSlug = 'restricted'; +export const restrictedVersionsSlug = 'restricted-versions'; export default buildConfig({ collections: [ @@ -45,6 +45,19 @@ export default buildConfig({ delete: () => false, }, }, + { + slug: restrictedVersionsSlug, + versions: true, + fields: [ + { + name: 'name', + type: 'text', + }, + ], + access: { + readVersions: () => false, + }, + }, ], onInit: async (payload) => { await payload.create({ @@ -62,11 +75,18 @@ export default buildConfig({ }, }); - await payload.create({ + await payload.create({ collection: readOnlySlug, data: { name: 'read-only', }, }); + + await payload.create({ + collection: restrictedVersionsSlug, + data: { + name: 'versioned', + }, + }); }, }); diff --git a/test/e2e/access-control/index.spec.ts b/test/access-control/e2e.spec.ts similarity index 80% rename from test/e2e/access-control/index.spec.ts rename to test/access-control/e2e.spec.ts index c566be281..048d7c922 100644 --- a/test/e2e/access-control/index.spec.ts +++ b/test/access-control/e2e.spec.ts @@ -1,16 +1,15 @@ import type { Page } from '@playwright/test'; import { expect, test } from '@playwright/test'; -import payload from '../../../src'; -import { AdminUrlUtil } from '../../helpers/adminUrlUtil'; -import { initPayloadE2E } from '../../helpers/configHelpers'; +import payload from '../../src'; +import { AdminUrlUtil } from '../helpers/adminUrlUtil'; +import { initPayloadE2E } from '../helpers/configHelpers'; import { login } from '../helpers'; -import { readOnlySlug, restrictedSlug, slug } from './config'; -import type { ReadOnlyCollection } from './payload-types'; +import { restrictedVersionsSlug, readOnlySlug, restrictedSlug, slug } from './config'; +import type { ReadOnlyCollection, RestrictedVersion } from './payload-types'; /** * TODO: Access Control * prevent user from logging in (canAccessAdmin) - * no version controls is no access * * FSK: 'should properly prevent / allow public users from reading a restricted field' * @@ -24,6 +23,7 @@ describe('access control', () => { let url: AdminUrlUtil; let restrictedUrl: AdminUrlUtil; let readoOnlyUrl: AdminUrlUtil; + let restrictedVersionsUrl: AdminUrlUtil; beforeAll(async ({ browser }) => { const { serverURL } = await initPayloadE2E(__dirname); @@ -31,6 +31,7 @@ describe('access control', () => { url = new AdminUrlUtil(serverURL, slug); restrictedUrl = new AdminUrlUtil(serverURL, restrictedSlug); readoOnlyUrl = new AdminUrlUtil(serverURL, readOnlySlug); + restrictedVersionsUrl = new AdminUrlUtil(serverURL, restrictedVersionsSlug); const context = await browser.newContext(); page = await context.newPage(); @@ -121,7 +122,7 @@ describe('access control', () => { await expect(page.locator(`#card-${readOnlySlug}`)).not.toHaveClass('card__actions'); }); - test('edit view should not have buttons', async () => { + test('edit view should not have actions buttons', async () => { await page.goto(readoOnlyUrl.edit(existingDoc.id)); await expect(page.locator('.collection-edit__collection-actions li')).toHaveCount(0); }); @@ -131,6 +132,24 @@ describe('access control', () => { await expect(page.locator('#field-name')).toBeDisabled(); }); }); + + describe('readVersions', () => { + let existingDoc: RestrictedVersion; + + beforeAll(async () => { + existingDoc = await payload.create({ + collection: restrictedVersionsSlug, + data: { + name: 'name', + }, + }); + }); + + test('versions sidebar should not show', async () => { + await page.goto(restrictedVersionsUrl.edit(existingDoc.id)); + await expect(page.locator('.versions-count')).not.toBeVisible(); + }); + }); }); async function createDoc(data: any): Promise<{ id: string }> { diff --git a/test/e2e/access-control/payload-types.ts b/test/access-control/payload-types.ts similarity index 84% rename from test/e2e/access-control/payload-types.ts rename to test/access-control/payload-types.ts index d632a9727..95c8bba8e 100644 --- a/test/e2e/access-control/payload-types.ts +++ b/test/access-control/payload-types.ts @@ -35,6 +35,16 @@ export interface ReadOnlyCollection { createdAt: string; updatedAt: string; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "restricted-versions". + */ +export interface RestrictedVersion { + id: string; + name?: string; + createdAt: string; + updatedAt: string; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "users". diff --git a/test/int/array-update/config.ts b/test/array-update/config.ts similarity index 100% rename from test/int/array-update/config.ts rename to test/array-update/config.ts diff --git a/test/int/array-update/index.spec.ts b/test/array-update/int.spec.ts similarity index 96% rename from test/int/array-update/index.spec.ts rename to test/array-update/int.spec.ts index a02d60abd..8a30b7003 100644 --- a/test/int/array-update/index.spec.ts +++ b/test/array-update/int.spec.ts @@ -1,6 +1,6 @@ import mongoose from 'mongoose'; -import { initPayloadTest } from '../../helpers/configHelpers'; -import payload from '../../../src'; +import { initPayloadTest } from '../helpers/configHelpers'; +import payload from '../../src'; import config from './config'; import type { Array as ArrayCollection } from './payload-types'; diff --git a/test/int/array-update/payload-types.ts b/test/array-update/payload-types.ts similarity index 100% rename from test/int/array-update/payload-types.ts rename to test/array-update/payload-types.ts diff --git a/test/e2e/auth/config.ts b/test/auth/config.ts similarity index 100% rename from test/e2e/auth/config.ts rename to test/auth/config.ts diff --git a/test/auth/e2e.spec.ts b/test/auth/e2e.spec.ts new file mode 100644 index 000000000..f1cee1a48 --- /dev/null +++ b/test/auth/e2e.spec.ts @@ -0,0 +1,69 @@ +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: Auth + * change password + * unlock + * generate api key + * log out + */ + +const { beforeAll, describe } = test; +let url: AdminUrlUtil; + +// describe('authentication', () => { +// 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 }); +// }); + +// describe('Authentication', () => { +// test(should login and logout', () => { +// expect(1).toEqual(1); +// }); +// test(should logout', () => { +// expect(1).toEqual(1); +// }); +// test(should allow change password', () => { +// expect(1).toEqual(1); +// }); +// test(should reset password', () => { +// expect(1).toEqual(1); +// }); +// test(should lockout after reaching max login attempts', () => { +// expect(1).toEqual(1); +// }); +// test(should prevent login for locked user', () => { +// expect(1).toEqual(1); +// }); +// test(should unlock user', () => { +// expect(1).toEqual(1); +// }); +// test(should not login without verify', () => { +// expect(1).toEqual(1); +// }); +// test(should allow generate api keys', () => { +// expect(1).toEqual(1); +// }); +// }); +// }); diff --git a/test/e2e/auth/payload-types.ts b/test/auth/payload-types.ts similarity index 100% rename from test/e2e/auth/payload-types.ts rename to test/auth/payload-types.ts diff --git a/test/buildConfig.ts b/test/buildConfig.ts new file mode 100644 index 000000000..ac1bf56bc --- /dev/null +++ b/test/buildConfig.ts @@ -0,0 +1,37 @@ +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, + }, +}; + +export function buildConfig(overrides?: Partial): SanitizedConfig { + if (process.env.NODE_ENV === 'test') { + baseConfig.admin = { + ...baseConfig.admin || {}, + webpack: (config) => { + const existingConfig = typeof overrides?.admin?.webpack === 'function' ? overrides.admin.webpack(config) : config; + return { + ...existingConfig, + cache: { + type: 'memory', + }, + }; + }, + }; + } + + console.log(process.env.PAYLOAD_DISABLE_ADMIN); + if (process.env.PAYLOAD_DISABLE_ADMIN === 'true') { + console.log('disabling admin'); + if (typeof baseConfig.admin !== 'object') baseConfig.admin = {}; + baseConfig.admin.disable = true; + } + + + return buildPayloadConfig(merge(baseConfig, overrides || {})); +} diff --git a/test/int/collections-graphql/config.ts b/test/collections-graphql/config.ts similarity index 100% rename from test/int/collections-graphql/config.ts rename to test/collections-graphql/config.ts diff --git a/test/int/collections-graphql/index.spec.ts b/test/collections-graphql/int.spec.ts similarity index 86% rename from test/int/collections-graphql/index.spec.ts rename to test/collections-graphql/int.spec.ts index 71142b2d4..b2e13541f 100644 --- a/test/int/collections-graphql/index.spec.ts +++ b/test/collections-graphql/int.spec.ts @@ -1,8 +1,8 @@ import mongoose from 'mongoose'; -import { initPayloadTest } from '../../helpers/configHelpers'; +import { initPayloadTest } from '../helpers/configHelpers'; import config from './config'; -import payload from '../../../src'; -import { RESTClient } from '../../helpers/rest'; +import payload from '../../src'; +import { RESTClient } from '../helpers/rest'; import type { Post } from './payload-types'; const collection = config.collections[0]?.slug; diff --git a/test/int/collections-graphql/payload-types.ts b/test/collections-graphql/payload-types.ts similarity index 100% rename from test/int/collections-graphql/payload-types.ts rename to test/collections-graphql/payload-types.ts diff --git a/test/int/collections-rest/config.ts b/test/collections-rest/config.ts similarity index 96% rename from test/int/collections-rest/config.ts rename to test/collections-rest/config.ts index 27db8a7dd..1b40d11d3 100644 --- a/test/int/collections-rest/config.ts +++ b/test/collections-rest/config.ts @@ -1,5 +1,5 @@ -import type { CollectionConfig } from '../../../src/collections/config/types'; -import { devUser } from '../../credentials'; +import type { CollectionConfig } from '../../src/collections/config/types'; +import { devUser } from '../credentials'; import { buildConfig } from '../buildConfig'; import type { Post } from './payload-types'; diff --git a/test/int/collections-rest/index.spec.ts b/test/collections-rest/int.spec.ts similarity index 98% rename from test/int/collections-rest/index.spec.ts rename to test/collections-rest/int.spec.ts index b4fdbd9cd..68a222a78 100644 --- a/test/int/collections-rest/index.spec.ts +++ b/test/collections-rest/int.spec.ts @@ -1,11 +1,11 @@ import mongoose from 'mongoose'; -import { initPayloadTest } from '../../helpers/configHelpers'; +import { initPayloadTest } from '../helpers/configHelpers'; import type { Relation } from './config'; import config, { slug, relationSlug } from './config'; -import payload from '../../../src'; -import { RESTClient } from '../../helpers/rest'; -import { mapAsync } from '../../../src/utilities/mapAsync'; +import payload from '../../src'; +import { RESTClient } from '../helpers/rest'; import type { Post } from './payload-types'; +import { mapAsync } from '../../src/utilities/mapAsync'; let client: RESTClient; diff --git a/test/int/collections-rest/payload-types.ts b/test/collections-rest/payload-types.ts similarity index 100% rename from test/int/collections-rest/payload-types.ts rename to test/collections-rest/payload-types.ts diff --git a/test/e2e/collections/config.ts b/test/collections/config.ts similarity index 88% rename from test/e2e/collections/config.ts rename to test/collections/config.ts index 9552a3c55..239233a1c 100644 --- a/test/e2e/collections/config.ts +++ b/test/collections/config.ts @@ -1,5 +1,5 @@ -import { mapAsync } from '../../../src/utilities/mapAsync'; -import { devUser } from '../../credentials'; +import { mapAsync } from '../../src/utilities/mapAsync'; +import { devUser } from '../credentials'; import { buildConfig } from '../buildConfig'; export const slug = 'posts'; diff --git a/test/e2e/collections/index.spec.ts b/test/collections/e2e.spec.ts similarity index 97% rename from test/e2e/collections/index.spec.ts rename to test/collections/e2e.spec.ts index 34e08b8f7..634c3c19e 100644 --- a/test/e2e/collections/index.spec.ts +++ b/test/collections/e2e.spec.ts @@ -1,13 +1,13 @@ import type { Page } from '@playwright/test'; import { expect, test } from '@playwright/test'; -import payload from '../../../src'; -import { AdminUrlUtil } from '../../helpers/adminUrlUtil'; -import { initPayloadE2E } from '../../helpers/configHelpers'; +import payload from '../../src'; +import { AdminUrlUtil } from '../helpers/adminUrlUtil'; +import { initPayloadE2E } from '../helpers/configHelpers'; import { login, saveDocAndAssert } from '../helpers'; import type { Post } from './config'; import { slug } from './config'; -import { mapAsync } from '../../../src/utilities/mapAsync'; -import wait from '../../../src/utilities/wait'; +import { mapAsync } from '../../src/utilities/mapAsync'; +import wait from '../../src/utilities/wait'; const { afterEach, beforeAll, beforeEach, describe } = test; diff --git a/test/e2e/collections/payload-types.ts b/test/collections/payload-types.ts similarity index 100% rename from test/e2e/collections/payload-types.ts rename to test/collections/payload-types.ts diff --git a/test/dev/server.ts b/test/dev/server.ts index dce593b10..5dca4921c 100644 --- a/test/dev/server.ts +++ b/test/dev/server.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ import express from 'express'; import { v4 as uuid } from 'uuid'; import payload from '../../src'; diff --git a/test/e2e/auth/index.spec.ts b/test/e2e/auth/index.spec.ts deleted file mode 100644 index 54d564281..000000000 --- a/test/e2e/auth/index.spec.ts +++ /dev/null @@ -1,69 +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: Auth - * change password - * unlock - * generate api key - * log out - */ - -const { beforeAll, describe } = test; -let url: AdminUrlUtil; - -describe('authentication', () => { - 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 }); - }); - - describe('Authentication', () => { - test('should login and logout', () => { - expect(1).toEqual(1); - }); - test('should logout', () => { - expect(1).toEqual(1); - }); - test('should allow change password', () => { - expect(1).toEqual(1); - }); - test('should reset password', () => { - expect(1).toEqual(1); - }); - test('should lockout after reaching max login attempts', () => { - expect(1).toEqual(1); - }); - test('should prevent login for locked user', () => { - expect(1).toEqual(1); - }); - test('should unlock user', () => { - expect(1).toEqual(1); - }); - test('should not login without verify', () => { - expect(1).toEqual(1); - }); - test('should allow generate api keys', () => { - expect(1).toEqual(1); - }); - }); -}); diff --git a/test/e2e/buildConfig.ts b/test/e2e/buildConfig.ts deleted file mode 100644 index d48f0d8c8..000000000 --- a/test/e2e/buildConfig.ts +++ /dev/null @@ -1,23 +0,0 @@ -import merge from 'deepmerge'; -import { buildConfig as buildPayloadConfig } from '../../src/config/build'; -import type { Config, SanitizedConfig } from '../../src/config/types'; - -export function buildConfig(overrides?: Partial): SanitizedConfig { - const baseConfig: Config = { - typescript: { - outputFile: process.env.PAYLOAD_TS_OUTPUT_PATH, - }, - }; - if (process.env.NODE_ENV === 'test') { - baseConfig.admin = { - webpack: (config) => ({ - ...config, - cache: { - type: 'memory', - }, - }), - }; - } - - return buildPayloadConfig(merge(baseConfig, overrides || {})); -} diff --git a/test/e2e/fields-array/config.ts b/test/fields-array/config.ts similarity index 100% rename from test/e2e/fields-array/config.ts rename to test/fields-array/config.ts diff --git a/test/e2e/fields-array/index.spec.ts b/test/fields-array/e2e.spec.ts similarity index 86% rename from test/e2e/fields-array/index.spec.ts rename to test/fields-array/e2e.spec.ts index a728e8675..58c9c96ab 100644 --- a/test/e2e/fields-array/index.spec.ts +++ b/test/fields-array/e2e.spec.ts @@ -1,8 +1,8 @@ import type { Page } from '@playwright/test'; import { expect, test } from '@playwright/test'; -import wait from '../../../src/utilities/wait'; -import { AdminUrlUtil } from '../../helpers/adminUrlUtil'; -import { initPayloadTest } from '../../helpers/configHelpers'; +import wait from '../../src/utilities/wait'; +import { AdminUrlUtil } from '../helpers/adminUrlUtil'; +import { initPayloadTest } from '../helpers/configHelpers'; import { firstRegister } from '../helpers'; import { slug } from './config'; diff --git a/test/e2e/fields-array/payload-types.ts b/test/fields-array/payload-types.ts similarity index 100% rename from test/e2e/fields-array/payload-types.ts rename to test/fields-array/payload-types.ts diff --git a/test/e2e/fields-relationship/config.ts b/test/fields-relationship/config.ts similarity index 97% rename from test/e2e/fields-relationship/config.ts rename to test/fields-relationship/config.ts index dfe232e6e..e74f8f7e1 100644 --- a/test/e2e/fields-relationship/config.ts +++ b/test/fields-relationship/config.ts @@ -1,7 +1,7 @@ import type { CollectionConfig } from '../../../src/collections/config/types'; import { buildConfig } from '../buildConfig'; -import { devUser } from '../../credentials'; -import { mapAsync } from '../../../src/utilities/mapAsync'; +import { devUser } from '../credentials'; +import { mapAsync } from '../../src/utilities/mapAsync'; export const slug = 'fields-relationship'; @@ -14,7 +14,7 @@ export interface FieldsRelationship { id: string; relationship: RelationOne; relationshipHasMany: RelationOne[]; - relationshipHasManyMultiple: Array; + relationshipHasManyMultiple: Array; relationshipMultiple: Array; relationshipRestricted: RelationRestricted; relationshipWithTitle: RelationWithTitle; diff --git a/test/e2e/fields-relationship/index.spec.ts b/test/fields-relationship/e2e.spec.ts similarity index 96% rename from test/e2e/fields-relationship/index.spec.ts rename to test/fields-relationship/e2e.spec.ts index 2f1020a31..3d3602bc1 100644 --- a/test/e2e/fields-relationship/index.spec.ts +++ b/test/fields-relationship/e2e.spec.ts @@ -1,9 +1,9 @@ import type { Page } from '@playwright/test'; import { expect, test } from '@playwright/test'; -import payload from '../../../src'; -import { mapAsync } from '../../../src/utilities/mapAsync'; -import { AdminUrlUtil } from '../../helpers/adminUrlUtil'; -import { initPayloadE2E, initPayloadTest } from '../../helpers/configHelpers'; +import payload from '../../src'; +import { mapAsync } from '../../src/utilities/mapAsync'; +import { AdminUrlUtil } from '../helpers/adminUrlUtil'; +import { initPayloadE2E } from '../helpers/configHelpers'; import { login, saveDocAndAssert } from '../helpers'; import type { FieldsRelationship as CollectionWithRelationships, @@ -19,7 +19,7 @@ import { relationWithTitleSlug, slug, } from './config'; -import wait from '../../../src/utilities/wait'; +import wait from '../../src/utilities/wait'; const { beforeAll, describe } = test; diff --git a/test/e2e/fields-relationship/payload-types.ts b/test/fields-relationship/payload-types.ts similarity index 100% rename from test/e2e/fields-relationship/payload-types.ts rename to test/fields-relationship/payload-types.ts diff --git a/test/e2e/fields/collections/Array/index.ts b/test/fields/collections/Array/index.ts similarity index 87% rename from test/e2e/fields/collections/Array/index.ts rename to test/fields/collections/Array/index.ts index 52f312443..2cb793551 100644 --- a/test/e2e/fields/collections/Array/index.ts +++ b/test/fields/collections/Array/index.ts @@ -1,4 +1,4 @@ -import type { CollectionConfig } from '../../../../../src/collections/config/types'; +import type { CollectionConfig } from '../../../../src/collections/config/types'; const ArrayFields: CollectionConfig = { slug: 'array-fields', diff --git a/test/e2e/fields/collections/Blocks/index.ts b/test/fields/collections/Blocks/index.ts similarity index 95% rename from test/e2e/fields/collections/Blocks/index.ts rename to test/fields/collections/Blocks/index.ts index 9f7fcdbaa..d14e8002d 100644 --- a/test/e2e/fields/collections/Blocks/index.ts +++ b/test/fields/collections/Blocks/index.ts @@ -1,4 +1,4 @@ -import type { CollectionConfig } from '../../../../../src/collections/config/types'; +import type { CollectionConfig } from '../../../../src/collections/config/types'; const BlockFields: CollectionConfig = { slug: 'block-fields', diff --git a/test/e2e/fields/collections/Collapsible/index.ts b/test/fields/collections/Collapsible/index.ts similarity index 84% rename from test/e2e/fields/collections/Collapsible/index.ts rename to test/fields/collections/Collapsible/index.ts index 956fdd43e..fc8a0a25c 100644 --- a/test/e2e/fields/collections/Collapsible/index.ts +++ b/test/fields/collections/Collapsible/index.ts @@ -1,4 +1,4 @@ -import type { CollectionConfig } from '../../../../../src/collections/config/types'; +import type { CollectionConfig } from '../../../../src/collections/config/types'; const CollapsibleFields: CollectionConfig = { slug: 'collapsible-fields', diff --git a/test/e2e/fields/collections/RichText/index.ts b/test/fields/collections/RichText/index.ts similarity index 95% rename from test/e2e/fields/collections/RichText/index.ts rename to test/fields/collections/RichText/index.ts index da9f7d41c..2ca335517 100644 --- a/test/e2e/fields/collections/RichText/index.ts +++ b/test/fields/collections/RichText/index.ts @@ -1,4 +1,4 @@ -import type { CollectionConfig } from '../../../../../src/collections/config/types'; +import type { CollectionConfig } from '../../../../src/collections/config/types'; const RichTextFields: CollectionConfig = { slug: 'rich-text-fields', diff --git a/test/e2e/fields/collections/Select/index.ts b/test/fields/collections/Select/index.ts similarity index 92% rename from test/e2e/fields/collections/Select/index.ts rename to test/fields/collections/Select/index.ts index c090c411f..ac18f58b0 100644 --- a/test/e2e/fields/collections/Select/index.ts +++ b/test/fields/collections/Select/index.ts @@ -1,4 +1,4 @@ -import type { CollectionConfig } from '../../../../../src/collections/config/types'; +import type { CollectionConfig } from '../../../../src/collections/config/types'; const SelectFields: CollectionConfig = { slug: 'select-fields', diff --git a/test/e2e/fields/collections/Text/index.ts b/test/fields/collections/Text/index.ts similarity index 77% rename from test/e2e/fields/collections/Text/index.ts rename to test/fields/collections/Text/index.ts index 10adc4875..54c2e7f06 100644 --- a/test/e2e/fields/collections/Text/index.ts +++ b/test/fields/collections/Text/index.ts @@ -1,4 +1,4 @@ -import type { CollectionConfig } from '../../../../../src/collections/config/types'; +import type { CollectionConfig } from '../../../../src/collections/config/types'; const TextFields: CollectionConfig = { slug: 'text-fields', diff --git a/test/e2e/fields/config.ts b/test/fields/config.ts similarity index 97% rename from test/e2e/fields/config.ts rename to test/fields/config.ts index e2e0c49a4..8d1e433b9 100644 --- a/test/e2e/fields/config.ts +++ b/test/fields/config.ts @@ -1,5 +1,5 @@ import { buildConfig } from '../buildConfig'; -import { devUser } from '../../credentials'; +import { devUser } from '../credentials'; import ArrayFields, { arrayDoc } from './collections/Array'; import BlockFields, { blocksDoc } from './collections/Blocks'; import CollapsibleFields, { collapsibleDoc } from './collections/Collapsible'; diff --git a/test/e2e/fields/index.spec.ts b/test/fields/e2e.spec.ts similarity index 87% rename from test/e2e/fields/index.spec.ts rename to test/fields/e2e.spec.ts index 0916041aa..f90b6c49b 100644 --- a/test/e2e/fields/index.spec.ts +++ b/test/fields/e2e.spec.ts @@ -1,7 +1,7 @@ import type { Page } from '@playwright/test'; import { expect, test } from '@playwright/test'; -import { AdminUrlUtil } from '../../helpers/adminUrlUtil'; -import { initPayloadE2E } from '../../helpers/configHelpers'; +import { AdminUrlUtil } from '../helpers/adminUrlUtil'; +import { initPayloadE2E } from '../helpers/configHelpers'; import { login } from '../helpers'; import { textDoc } from './collections/Text'; diff --git a/test/e2e/fields/payload-types.ts b/test/fields/payload-types.ts similarity index 100% rename from test/e2e/fields/payload-types.ts rename to test/fields/payload-types.ts diff --git a/test/e2e/helpers.ts b/test/helpers.ts similarity index 93% rename from test/e2e/helpers.ts rename to test/helpers.ts index bf0ffc3c0..c664723f7 100644 --- a/test/e2e/helpers.ts +++ b/test/helpers.ts @@ -1,7 +1,7 @@ import type { Page } from '@playwright/test'; import { expect } from '@playwright/test'; -import wait from '../../src/utilities/wait'; -import { devUser } from '../credentials'; +import wait from '../src/utilities/wait'; +import { devUser } from './credentials'; type FirstRegisterArgs = { page: Page, diff --git a/test/helpers/configHelpers.ts b/test/helpers/configHelpers.ts index cecbbd7e0..7478ad197 100644 --- a/test/helpers/configHelpers.ts +++ b/test/helpers/configHelpers.ts @@ -28,6 +28,7 @@ export async function initPayloadTest(options: Options): Promise<{ serverURL: st ...options.init || {}, }; + process.env.PAYLOAD_DISABLE_ADMIN = 'true'; process.env.PAYLOAD_CONFIG_PATH = path.resolve(options.__dirname, './config.ts'); const port = await getPort(); diff --git a/test/int/buildConfig.ts b/test/int/buildConfig.ts deleted file mode 100644 index 793a30966..000000000 --- a/test/int/buildConfig.ts +++ /dev/null @@ -1,19 +0,0 @@ -import merge from 'deepmerge'; -import { buildConfig as buildPayloadConfig } from '../../src/config/build'; -import type { Config, SanitizedConfig } from '../../src/config/types'; - -export function buildConfig(overrides?: Partial): SanitizedConfig { - const baseConfig: Config = { - typescript: { - outputFile: process.env.PAYLOAD_TS_OUTPUT_PATH, - }, - }; - - if (process.env.NODE_ENV === 'test') { - baseConfig.admin = { - disable: true, - }; - } - - return buildPayloadConfig(merge(baseConfig, overrides || {})); -} diff --git a/test/int/uploads/index.spec.ts b/test/int/uploads/index.spec.ts deleted file mode 100644 index 3fe5dae91..000000000 --- a/test/int/uploads/index.spec.ts +++ /dev/null @@ -1,438 +0,0 @@ -import fs from 'fs'; -import path from 'path'; -import FormData from 'form-data'; -import { GraphQLClient } from 'graphql-request'; -import { promisify } from 'util'; -import getConfig from '../../config/load'; -import { email, password } from '../../mongoose/testCredentials'; - -const stat = promisify(fs.stat); - -require('isomorphic-fetch'); - -const config = getConfig(); -const api = `${config.serverURL}${config.routes.api}`; - -let client; -let token; -let headers; - -describe('Collections - Uploads', () => { - beforeAll(async (done) => { - const response = await fetch(`${api}/admins/login`, { - body: JSON.stringify({ - email, - password, - }), - headers: { - 'Content-Type': 'application/json', - }, - method: 'post', - }); - - const data = await response.json(); - - ({ token } = data); - headers = { - Authorization: `JWT ${token}`, - }; - - done(); - }); - - describe('REST', () => { - const mediaDir = path.join(__dirname, '../../../demo', 'media'); - beforeAll(async () => { - // Clear demo/media directory - const mediaDirExists = await fileExists(mediaDir); - if (!mediaDirExists) return; - fs.readdir(mediaDir, (err, files) => { - if (err) throw err; - - // eslint-disable-next-line no-restricted-syntax - for (const file of files) { - fs.unlink(path.join(mediaDir, file), (unlinkErr) => { - if (unlinkErr) throw unlinkErr; - }); - } - }); - }); - - describe('create', () => { - it('creates', async () => { - const formData = new FormData(); - formData.append( - 'file', - fs.createReadStream(path.join(__dirname, '../../..', 'tests/api/assets/image.png')), - ); - formData.append('alt', 'test media'); - formData.append('locale', 'en'); - const response = await fetch(`${api}/media`, { - body: formData as unknown as BodyInit, - headers, - method: 'post', - }); - - const data = await response.json(); - - expect(response.status).toBe(201); - - // Check for files - expect(await fileExists(path.join(mediaDir, 'image.png'))).toBe(true); - expect(await fileExists(path.join(mediaDir, 'image-16x16.png'))).toBe(true); - expect(await fileExists(path.join(mediaDir, 'image-320x240.png'))).toBe(true); - expect(await fileExists(path.join(mediaDir, 'image-640x480.png'))).toBe(true); - - // Check api response - expect(data).toMatchObject({ - doc: { - alt: 'test media', - filename: 'image.png', - mimeType: 'image/png', - sizes: { - icon: { - filename: 'image-16x16.png', - width: 16, - height: 16, - }, - mobile: { - filename: 'image-320x240.png', - width: 320, - height: 240, - }, - tablet: { - filename: 'image-640x480.png', - width: 640, - height: 480, - }, - }, - - // We have a hook to check if upload sizes - // are properly bound to the Payload `req`. - // This field should be automatically set - // if they are found. - foundUploadSizes: true, - }, - }); - }); - - it('creates images that do not require all sizes', async () => { - const formData = new FormData(); - formData.append( - 'file', - fs.createReadStream(path.join(__dirname, '../../..', 'tests/api/assets/small.png')), - ); - formData.append('alt', 'test media'); - formData.append('locale', 'en'); - const response = await fetch(`${api}/media`, { - body: formData as unknown as BodyInit, - headers, - method: 'post', - }); - - const data = await response.json(); - - expect(response.status).toBe(201); - - expect(await fileExists(path.join(mediaDir, 'small.png'))).toBe(true); - expect(await fileExists(path.join(mediaDir, 'small-16x16.png'))).toBe(true); - expect(await fileExists(path.join(mediaDir, 'small-320x240.png'))).toBe(true); - expect(await fileExists(path.join(mediaDir, 'small-640x480.png'))).toBe(false); - - // Check api response - expect(data).toMatchObject({ - doc: { - alt: 'test media', - filename: 'small.png', - mimeType: 'image/png', - sizes: { - icon: { - filename: 'small-16x16.png', - width: 16, - height: 16, - }, - }, - - // We have a hook to check if upload sizes - // are properly bound to the Payload `req`. - // This field should be automatically set - // if they are found. - foundUploadSizes: true, - }, - }); - }); - - it('creates media without storing a file', async () => { - const formData = new FormData(); - formData.append( - 'file', - fs.createReadStream(path.join(__dirname, '../../..', 'tests/api/assets/image.png')), - ); - formData.append('alt', 'test media'); - formData.append('locale', 'en'); - - const response = await fetch(`${api}/unstored-media`, { - body: formData as unknown as BodyInit, - headers, - method: 'post', - }); - - const data = await response.json(); - - expect(response.status).toBe(201); - - // Check for files - expect(await !fileExists(path.join(mediaDir, 'image.png'))).toBe(false); - expect(await !fileExists(path.join(mediaDir, 'image-640x480.png'))).toBe(false); - - // Check api response - expect(data).toMatchObject({ - doc: { - alt: 'test media', - filename: 'image.png', - mimeType: 'image/png', - sizes: { - tablet: { - filename: 'image-640x480.png', - width: 640, - height: 480, - }, - }, - }, - }); - }); - - it('creates with same name', async () => { - const formData = new FormData(); - formData.append( - 'file', - fs.createReadStream(path.join(__dirname, '../../..', 'tests/api/assets/samename.png')), - ); - formData.append('alt', 'test media'); - formData.append('locale', 'en'); - - const firstResponse = await fetch(`${api}/media`, { - body: formData as unknown as BodyInit, - headers, - method: 'post', - }); - - expect(firstResponse.status).toBe(201); - - const sameForm = new FormData(); - sameForm.append( - 'file', - fs.createReadStream(path.join(__dirname, '../../..', 'tests/api/assets/samename.png')), - ); - sameForm.append('alt', 'test media'); - sameForm.append('locale', 'en'); - - const response = await fetch(`${api}/media`, { - body: sameForm as unknown as BodyInit, - headers, - method: 'post', - }); - - expect(response.status).toBe(201); - const data = await response.json(); - - // Check for files - expect(await fileExists(path.join(mediaDir, 'samename-1.png'))).toBe(true); - expect(await fileExists(path.join(mediaDir, 'samename-1-16x16.png'))).toBe(true); - expect(await fileExists(path.join(mediaDir, 'samename-1-320x240.png'))).toBe(true); - expect(await fileExists(path.join(mediaDir, 'samename-1-640x480.png'))).toBe(true); - - expect(data).toMatchObject({ - doc: { - alt: 'test media', - filename: 'samename-1.png', - mimeType: 'image/png', - sizes: { - icon: { - filename: 'samename-1-16x16.png', - width: 16, - height: 16, - }, - mobile: { - filename: 'samename-1-320x240.png', - width: 320, - height: 240, - }, - tablet: { - filename: 'samename-1-640x480.png', - width: 640, - height: 480, - }, - }, - }, - }); - }); - }); - - it('update', async () => { - const formData = new FormData(); - formData.append( - 'file', - fs.createReadStream(path.join(__dirname, '../../..', 'tests/api/assets/update.png')), - ); - formData.append('alt', 'test media'); - formData.append('locale', 'en'); - - const response = await fetch(`${api}/media`, { - body: formData as unknown as BodyInit, - headers, - method: 'post', - }); - - const data = await response.json(); - - expect(response.status).toBe(201); - - const updateFormData = new FormData(); - const newAlt = 'my new alt'; - - updateFormData.append('filename', data.doc.filename); - updateFormData.append('alt', newAlt); - const updateResponse = await fetch(`${api}/media/${data.doc.id}`, { - body: updateFormData as unknown as BodyInit, - headers, - method: 'put', - }); - - - const updateResponseData = await updateResponse.json(); - expect(updateResponse.status).toBe(200); - - // Check that files weren't affected - expect(await fileExists(path.join(mediaDir, 'update.png'))).toBe(true); - expect(await fileExists(path.join(mediaDir, 'update-16x16.png'))).toBe(true); - expect(await fileExists(path.join(mediaDir, 'update-320x240.png'))).toBe(true); - expect(await fileExists(path.join(mediaDir, 'update-640x480.png'))).toBe(true); - - // Check api response - expect(updateResponseData).toMatchObject({ - doc: { - alt: newAlt, - filename: 'update.png', - mimeType: 'image/png', - sizes: { - icon: { - filename: 'update-16x16.png', - width: 16, - height: 16, - }, - mobile: { - filename: 'update-320x240.png', - width: 320, - height: 240, - }, - tablet: { - filename: 'update-640x480.png', - width: 640, - height: 480, - }, - maintainedAspectRatio: {}, - }, - }, - }); - }); - - it('delete', async () => { - const formData = new FormData(); - formData.append( - 'file', - fs.createReadStream(path.join(__dirname, '../../..', 'tests/api/assets/delete.png')), - ); - formData.append('alt', 'test media'); - formData.append('locale', 'en'); - - const createResponse = await fetch(`${api}/media`, { - body: formData as unknown as BodyInit, - headers, - method: 'post', - }); - - const createData = await createResponse.json(); - expect(createResponse.status).toBe(201); - const docId = createData.doc.id; - - const response = await fetch(`${api}/media/${docId}`, { - headers, - method: 'delete', - }); - - const data = await response.json(); - expect(response.status).toBe(200); - expect(data.id).toBe(docId); - - const imageExists = await fileExists(path.join(mediaDir, 'delete.png')); - expect(imageExists).toBe(false); - }); - }); - - describe('GraphQL', () => { - // graphql cannot submit formData to create files, we only need to test getting relationship data on upload fields - let media; - let image; - const alt = 'alt text'; - beforeAll(async (done) => { - client = new GraphQLClient(`${api}${config.routes.graphQL}`, { - headers: { Authorization: `JWT ${token}` }, - }); - - // create media using REST - const formData = new FormData(); - formData.append( - 'file', - fs.createReadStream(path.join(__dirname, '../../..', 'tests/api/assets/image.png')), - ); - formData.append('alt', alt); - formData.append('locale', 'en'); - const mediaResponse = await fetch(`${api}/media`, { - body: formData as unknown as BodyInit, - headers, - method: 'post', - }); - const mediaData = await mediaResponse.json(); - media = mediaData.doc; - - // create image that relates to media - headers['Content-Type'] = 'application/json'; - const imageResponse = await fetch(`${api}/images`, { - body: JSON.stringify({ - upload: media.id, - }), - headers, - method: 'post', - }); - const data = await imageResponse.json(); - image = data.doc; - - done(); - }); - - it('should query uploads relationship fields', async () => { - // language=graphQL - const query = `query { - Image(id: "${image.id}") { - id - upload { - alt - } - } - }`; - - const response = await client.request(query); - expect(response.Image.upload.alt).toStrictEqual(alt); - }); - }); -}); - -async function fileExists(fileName: string): Promise { - try { - await stat(fileName); - return true; - } catch (err) { - return false; - } -} diff --git a/test/jest.setup.ts b/test/jest.setup.ts new file mode 100644 index 000000000..b3d4f05e8 --- /dev/null +++ b/test/jest.setup.ts @@ -0,0 +1,3 @@ +module.exports = () => { + process.env.PAYLOAD_DISABLE_ADMIN = 'true'; +}; diff --git a/test/e2e/localization/config.ts b/test/localization/config.ts similarity index 93% rename from test/e2e/localization/config.ts rename to test/localization/config.ts index 577cd5822..c274acbf4 100644 --- a/test/e2e/localization/config.ts +++ b/test/localization/config.ts @@ -1,4 +1,4 @@ -import { mapAsync } from '../../../src/utilities/mapAsync'; +import { mapAsync } from '../../src/utilities/mapAsync'; import { buildConfig } from '../buildConfig'; export const slug = 'localized-posts'; diff --git a/test/e2e/localization/index.spec.ts b/test/localization/e2e.spec.ts similarity index 92% rename from test/e2e/localization/index.spec.ts rename to test/localization/e2e.spec.ts index a12177fb7..968e451ee 100644 --- a/test/e2e/localization/index.spec.ts +++ b/test/localization/e2e.spec.ts @@ -1,10 +1,10 @@ import type { Page } from '@playwright/test'; import { expect, test } from '@playwright/test'; -import payload from '../../../src'; -import type { TypeWithTimestamps } from '../../../src/collections/config/types'; -import { mapAsync } from '../../../src/utilities/mapAsync'; -import { AdminUrlUtil } from '../../helpers/adminUrlUtil'; -import { initPayloadTest } from '../../helpers/configHelpers'; +import payload from '../../src'; +import type { TypeWithTimestamps } from '../../src/collections/config/types'; +import { mapAsync } from '../../src/utilities/mapAsync'; +import { AdminUrlUtil } from '../helpers/adminUrlUtil'; +import { initPayloadTest } from '../helpers/configHelpers'; import { firstRegister, saveDocAndAssert } from '../helpers'; import type { LocalizedPost } from './config'; import { slug } from './config'; diff --git a/test/e2e/localization/payload-types.ts b/test/localization/payload-types.ts similarity index 100% rename from test/e2e/localization/payload-types.ts rename to test/localization/payload-types.ts diff --git a/test/uploads/config.ts b/test/uploads/config.ts index bbea8ea68..9db355caa 100644 --- a/test/uploads/config.ts +++ b/test/uploads/config.ts @@ -1,6 +1,6 @@ import path from 'path'; import fs from 'fs'; -import { buildConfig } from '../e2e/buildConfig'; +import { buildConfig } from '../buildConfig'; import { devUser } from '../credentials'; import getFileByPath from '../../src/uploads/getFileByPath'; @@ -17,7 +17,7 @@ export default buildConfig({ resolve: { ...config.resolve, alias: { - ...config.resolve.alias, + ...config?.resolve?.alias, fs: mockModulePath, }, }, diff --git a/test/uploads/e2e.spec.ts b/test/uploads/e2e.spec.ts index 11826f207..5966303ef 100644 --- a/test/uploads/e2e.spec.ts +++ b/test/uploads/e2e.spec.ts @@ -6,7 +6,7 @@ import type { Media } from './payload-types'; import payload from '../../src'; import { AdminUrlUtil } from '../helpers/adminUrlUtil'; import { initPayloadE2E } from '../helpers/configHelpers'; -import { login, saveDocAndAssert } from '../e2e/helpers'; +import { login, saveDocAndAssert } from '../helpers'; import wait from '../../src/utilities/wait'; const { beforeAll, describe } = test; diff --git a/test/e2e/versions/config.ts b/test/versions/config.ts similarity index 100% rename from test/e2e/versions/config.ts rename to test/versions/config.ts diff --git a/test/e2e/versions/index.template.ts b/test/versions/index.template.ts similarity index 89% rename from test/e2e/versions/index.template.ts rename to test/versions/index.template.ts index 7eebd1498..e5d94ca8f 100644 --- a/test/e2e/versions/index.template.ts +++ b/test/versions/index.template.ts @@ -1,7 +1,7 @@ import type { Page } from '@playwright/test'; import { expect, test } from '@playwright/test'; -import { AdminUrlUtil } from '../../helpers/adminUrlUtil'; -import { initPayloadTest } from '../../helpers/configHelpers'; +import { AdminUrlUtil } from '../helpers/adminUrlUtil'; +import { initPayloadTest } from '../helpers/configHelpers'; import { firstRegister } from '../helpers'; import { slug } from './config'; @@ -51,7 +51,7 @@ describe('suite name', () => { // }); describe('feature', () => { - test('testname', () => { + it('testname', () => { expect(1).toEqual(1); }); }); diff --git a/test/e2e/versions/payload-types.ts b/test/versions/payload-types.ts similarity index 100% rename from test/e2e/versions/payload-types.ts rename to test/versions/payload-types.ts