chore: replace all __dirname's in test dir
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { CollectionConfig } from '../../../../packages/payload/src/collections/config/types'
|
||||
import type { CollectionConfig } from '../../../../packages/payload/src/collections/config/types.js'
|
||||
|
||||
export const mediaSlug = 'media'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { CollectionConfig } from '../../../../packages/payload/src/collections/config/types.d.ts'
|
||||
import type { CollectionConfig } from '../../../../packages/payload/src/collections/config/types.js'
|
||||
|
||||
import { mediaSlug } from '../Media/index.js'
|
||||
|
||||
@@ -51,6 +51,5 @@ export const PostsCollection: CollectionConfig = {
|
||||
],
|
||||
},
|
||||
],
|
||||
versions: true,
|
||||
slug: postsSlug,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { GlobalConfig } from '../../../../packages/payload/src/globals/config/types'
|
||||
import type { GlobalConfig } from '../../../../packages/payload/src/globals/config/types.js'
|
||||
|
||||
export const menuSlug = 'menu'
|
||||
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
import type { FieldAccess } from '../../packages/payload/src/fields/config/types'
|
||||
import type { FieldAccess } from '../../packages/payload/src/fields/config/types.js'
|
||||
|
||||
import { buildConfigWithDefaults } from '../buildConfigWithDefaults'
|
||||
import { devUser } from '../credentials'
|
||||
import { firstArrayText, secondArrayText } from './shared'
|
||||
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
|
||||
import { devUser } from '../credentials.js'
|
||||
import {
|
||||
docLevelAccessSlug,
|
||||
firstArrayText,
|
||||
hiddenAccessSlug,
|
||||
hiddenFieldsSlug,
|
||||
readOnlySlug,
|
||||
relyOnRequestHeadersSlug,
|
||||
restrictedSlug,
|
||||
restrictedVersionsSlug,
|
||||
secondArrayText,
|
||||
siblingDataSlug,
|
||||
slug,
|
||||
unrestrictedSlug,
|
||||
userRestrictedSlug,
|
||||
} from './shared'
|
||||
} from './shared.js'
|
||||
|
||||
const openAccess = {
|
||||
create: () => true,
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { Page } from '@playwright/test'
|
||||
import type { Payload } from 'payload'
|
||||
|
||||
import { expect, test } from '@playwright/test'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { ReadOnlyCollection, RestrictedVersion } from './payload-types'
|
||||
|
||||
@@ -18,6 +19,8 @@ import {
|
||||
slug,
|
||||
unrestrictedSlug,
|
||||
} from './shared'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
/**
|
||||
* TODO: Access Control
|
||||
@@ -39,7 +42,7 @@ describe('access control', () => {
|
||||
let serverURL: string
|
||||
|
||||
beforeAll(async ({ browser }) => {
|
||||
;({ payload, serverURL } = await initPayloadE2E({ config, dirname: __dirname }))
|
||||
;({ payload, serverURL } = await initPayloadE2E({ config, dirname }))
|
||||
|
||||
url = new AdminUrlUtil(serverURL, slug)
|
||||
restrictedUrl = new AdminUrlUtil(serverURL, restrictedSlug)
|
||||
|
||||
@@ -36,6 +36,8 @@ import {
|
||||
slugPluralLabel,
|
||||
} from './shared'
|
||||
import {
|
||||
customIdCollectionId,
|
||||
customIdCollectionSlug,
|
||||
customViews2CollectionSlug,
|
||||
geoCollectionSlug,
|
||||
globalSlug,
|
||||
@@ -44,8 +46,6 @@ import {
|
||||
noApiViewCollectionSlug,
|
||||
noApiViewGlobalSlug,
|
||||
postsCollectionSlug,
|
||||
customIdCollectionSlug,
|
||||
customIdCollectionId,
|
||||
} from './slugs'
|
||||
|
||||
const { beforeAll, beforeEach, describe } = test
|
||||
@@ -55,6 +55,11 @@ const description = 'Description'
|
||||
|
||||
let payload: Payload
|
||||
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
describe('admin', () => {
|
||||
let page: Page
|
||||
let geoUrl: AdminUrlUtil
|
||||
@@ -63,7 +68,7 @@ describe('admin', () => {
|
||||
let serverURL: string
|
||||
|
||||
beforeAll(async ({ browser }) => {
|
||||
;({ payload, serverURL } = await initPayloadE2E({ config, dirname: __dirname }))
|
||||
;({ payload, serverURL } = await initPayloadE2E({ config, dirname }))
|
||||
geoUrl = new AdminUrlUtil(serverURL, geoCollectionSlug)
|
||||
url = new AdminUrlUtil(serverURL, postsCollectionSlug)
|
||||
customViewsURL = new AdminUrlUtil(serverURL, customViews2CollectionSlug)
|
||||
@@ -537,7 +542,7 @@ describe('admin', () => {
|
||||
test('should allow custom ID field nested inside an unnamed tab', async () => {
|
||||
await page.goto(url.collection('customIdTab') + '/' + customIdCollectionId)
|
||||
|
||||
const idField = await page.locator('#field-id')
|
||||
const idField = page.locator('#field-id')
|
||||
|
||||
await expect(idField).toHaveValue(customIdCollectionId)
|
||||
})
|
||||
@@ -545,7 +550,7 @@ describe('admin', () => {
|
||||
test('should allow custom ID field nested inside a row', async () => {
|
||||
await page.goto(url.collection('customIdRow') + '/' + customIdCollectionId)
|
||||
|
||||
const idField = await page.locator('#field-id')
|
||||
const idField = page.locator('#field-id')
|
||||
|
||||
await expect(idField).toHaveValue(customIdCollectionId)
|
||||
})
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { Page } from '@playwright/test'
|
||||
|
||||
import { expect, test } from '@playwright/test'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import payload from '../../packages/payload/src'
|
||||
import { initPageConsoleErrorCatch, login, saveDocAndAssert } from '../helpers'
|
||||
@@ -8,6 +10,8 @@ import { AdminUrlUtil } from '../helpers/adminUrlUtil'
|
||||
import { initPayloadE2E } from '../helpers/configHelpers'
|
||||
import config from './config'
|
||||
import { apiKeysSlug, slug } from './shared'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
/**
|
||||
* TODO: Auth
|
||||
@@ -29,7 +33,7 @@ describe('auth', () => {
|
||||
let apiURL: string
|
||||
|
||||
beforeAll(async ({ browser }) => {
|
||||
;({ serverURL } = await initPayloadE2E({ config, dirname: __dirname }))
|
||||
;({ serverURL } = await initPayloadE2E({ config, dirname }))
|
||||
url = new AdminUrlUtil(serverURL, slug)
|
||||
|
||||
const context = await browser.newContext()
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { CollectionConfig } from '../../packages/payload/src/collections/config/types'
|
||||
|
||||
import { buildConfigWithDefaults } from '../buildConfigWithDefaults'
|
||||
import { devUser } from '../credentials'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
export interface Relation {
|
||||
id: string
|
||||
@@ -355,7 +358,7 @@ export default buildConfigWithDefaults({
|
||||
},
|
||||
}
|
||||
},
|
||||
schemaOutputFile: path.resolve(__dirname, 'schema.graphql'),
|
||||
schemaOutputFile: path.resolve(dirname, 'schema.graphql'),
|
||||
},
|
||||
onInit: async (payload) => {
|
||||
await payload.create({
|
||||
|
||||
@@ -4,9 +4,13 @@ import * as CommentJson from 'comment-json'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import shelljs from 'shelljs'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { promisify } from 'util'
|
||||
|
||||
import { initNext } from '../../packages/create-payload-app/src/lib/init-next'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const readFile = promisify(fs.readFile)
|
||||
|
||||
const nextCreateCommands: Partial<Record<'noSrcDir' | 'srcDir', string>> = {
|
||||
@@ -24,16 +28,13 @@ describe('create-payload-app', () => {
|
||||
|
||||
describe('Next.js app template files', () => {
|
||||
it('should exist in dist', () => {
|
||||
const distPath = path.resolve(
|
||||
__dirname,
|
||||
'../../packages/create-payload-app/dist/app/(payload)',
|
||||
)
|
||||
const distPath = path.resolve(dirname, '../../packages/create-payload-app/dist/app/(payload)')
|
||||
expect(fs.existsSync(distPath)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe.each(Object.keys(nextCreateCommands))(`--init-next with %s`, (nextCmdKey) => {
|
||||
const projectDir = path.resolve(__dirname, 'test-app')
|
||||
const projectDir = path.resolve(dirname, 'test-app')
|
||||
|
||||
beforeEach(() => {
|
||||
if (fs.existsSync(projectDir)) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { PostgresAdapter } from '../../packages/db-postgres/src/types'
|
||||
import type { Payload } from '../../packages/payload/src'
|
||||
@@ -13,18 +14,20 @@ import { devUser } from '../credentials'
|
||||
import removeFiles from '../helpers/removeFiles'
|
||||
import { startMemoryDB } from '../startMemoryDB'
|
||||
import configPromise from './config'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
let payload: Payload
|
||||
let user: TypeWithID & Record<string, unknown>
|
||||
const collection = 'posts'
|
||||
const title = 'title'
|
||||
process.env.PAYLOAD_CONFIG_PATH = path.join(__dirname, 'config.ts')
|
||||
process.env.PAYLOAD_CONFIG_PATH = path.join(dirname, 'config.ts')
|
||||
|
||||
describe('database', () => {
|
||||
beforeAll(async () => {
|
||||
const config = await startMemoryDB(configPromise)
|
||||
payload = await getPayload({ config })
|
||||
payload.db.migrationDir = path.join(__dirname, './migrations')
|
||||
payload.db.migrationDir = path.join(dirname, './migrations')
|
||||
|
||||
const loginResult = await payload.login({
|
||||
collection: 'users',
|
||||
@@ -51,7 +54,7 @@ describe('database', () => {
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
removeFiles(path.join(__dirname, './migrations'))
|
||||
removeFiles(path.join(dirname, './migrations'))
|
||||
})
|
||||
|
||||
it('should run migrate:create', async () => {
|
||||
|
||||
@@ -8,12 +8,17 @@ import config from './config'
|
||||
|
||||
const { beforeAll, describe } = test
|
||||
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
describe('field error states', () => {
|
||||
let serverURL: string
|
||||
let page: Page
|
||||
|
||||
beforeAll(async ({ browser }) => {
|
||||
;({ serverURL } = await initPayloadE2E({ config, dirname: __dirname }))
|
||||
;({ serverURL } = await initPayloadE2E({ config, dirname }))
|
||||
const context = await browser.newContext()
|
||||
page = await context.newPage()
|
||||
initPageConsoleErrorCatch(page)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { Page } from '@playwright/test'
|
||||
|
||||
import { expect, test } from '@playwright/test'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { Payload } from '../../packages/payload/src'
|
||||
import type {
|
||||
@@ -26,6 +28,8 @@ import {
|
||||
slug,
|
||||
} from './collectionSlugs'
|
||||
import config from './config'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const { beforeAll, beforeEach, describe } = test
|
||||
|
||||
@@ -44,7 +48,7 @@ describe('fields - relationship', () => {
|
||||
let serverURL: string
|
||||
|
||||
beforeAll(async ({ browser }) => {
|
||||
;({ payload, serverURL } = await initPayloadE2E({ config, dirname: __dirname }))
|
||||
;({ payload, serverURL } = await initPayloadE2E({ config, dirname }))
|
||||
|
||||
url = new AdminUrlUtil(serverURL, slug)
|
||||
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { CollectionConfig } from '../../../../packages/payload/src/collections/config/types'
|
||||
|
||||
import { uploadsSlug } from '../../slugs'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const Uploads: CollectionConfig = {
|
||||
slug: uploadsSlug,
|
||||
upload: {
|
||||
staticDir: path.resolve(__dirname, './uploads'),
|
||||
staticDir: path.resolve(dirname, './uploads'),
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { CollectionConfig } from '../../../../packages/payload/src/collections/config/types'
|
||||
|
||||
import { uploads2Slug } from '../../slugs'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const Uploads2: CollectionConfig = {
|
||||
slug: uploads2Slug,
|
||||
upload: {
|
||||
staticDir: path.resolve(__dirname, './uploads2'),
|
||||
staticDir: path.resolve(dirname, './uploads2'),
|
||||
},
|
||||
labels: {
|
||||
singular: 'Upload 2',
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { CollectionConfig } from '../../../../packages/payload/src/collections/config/types'
|
||||
|
||||
import { uploads3Slug } from '../../slugs'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const Uploads3: CollectionConfig = {
|
||||
slug: uploads3Slug,
|
||||
upload: {
|
||||
staticDir: path.resolve(__dirname, './uploads3'),
|
||||
staticDir: path.resolve(dirname, './uploads3'),
|
||||
},
|
||||
labels: {
|
||||
singular: 'Upload 3',
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { Payload } from 'payload'
|
||||
|
||||
import { expect, test } from '@playwright/test'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { RelationshipField, TextField } from './payload-types'
|
||||
|
||||
@@ -28,6 +29,8 @@ import {
|
||||
tabsFieldsSlug,
|
||||
textFieldsSlug,
|
||||
} from './slugs'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const { afterEach, beforeAll, beforeEach, describe } = test
|
||||
|
||||
@@ -39,7 +42,7 @@ let serverURL: string
|
||||
|
||||
describe('fields', () => {
|
||||
beforeAll(async ({ browser }) => {
|
||||
;({ payload, serverURL } = await initPayloadE2E({ config, dirname: __dirname }))
|
||||
;({ payload, serverURL } = await initPayloadE2E({ config, dirname }))
|
||||
|
||||
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
|
||||
await client.login()
|
||||
@@ -1845,7 +1848,7 @@ describe('fields', () => {
|
||||
// create a jpg upload
|
||||
await page
|
||||
.locator('.file-field__upload input[type="file"]')
|
||||
.setInputFiles(path.resolve(__dirname, './collections/Upload/payload.jpg'))
|
||||
.setInputFiles(path.resolve(dirname, './collections/Upload/payload.jpg'))
|
||||
await expect(page.locator('.file-field .file-field__filename')).toHaveValue('payload.jpg')
|
||||
await page.locator('#action-save').click()
|
||||
await wait(200)
|
||||
@@ -1871,7 +1874,7 @@ describe('fields', () => {
|
||||
await page.locator('.field-type.upload .upload__toggler.doc-drawer__toggler').click()
|
||||
await page
|
||||
.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'))
|
||||
await page.locator('[id^=doc-drawer_uploads_1_] #action-save').click()
|
||||
await wait(200)
|
||||
await expect(page.locator('.Toastify')).toContainText('successfully')
|
||||
@@ -1897,7 +1900,7 @@ describe('fields', () => {
|
||||
await page.locator('.field-type.upload .upload__toggler.doc-drawer__toggler').click()
|
||||
await page
|
||||
.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'))
|
||||
await page.locator('[id^=doc-drawer_uploads_1_] #action-save').click()
|
||||
await wait(200)
|
||||
await expect(page.locator('.Toastify')).toContainText('successfully')
|
||||
@@ -1920,7 +1923,7 @@ describe('fields', () => {
|
||||
// create file in uploads 3 collection
|
||||
await page
|
||||
.locator('.file-field__upload input[type="file"]')
|
||||
.setInputFiles(path.resolve(__dirname, './collections/Upload/payload.jpg'))
|
||||
.setInputFiles(path.resolve(dirname, './collections/Upload/payload.jpg'))
|
||||
await expect(page.locator('.file-field .file-field__filename')).toContainText('payload.jpg')
|
||||
await page.locator('#action-save').click()
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ import type { Page } from '@playwright/test'
|
||||
import type { SerializedEditorState, SerializedParagraphNode, SerializedTextNode } from 'lexical'
|
||||
|
||||
import { expect, test } from '@playwright/test'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { Payload } from '../../packages/payload/src'
|
||||
import type { SerializedBlockNode } from '../../packages/richtext-lexical/src'
|
||||
@@ -15,6 +17,8 @@ import { lexicalDocData } from './collections/Lexical/data'
|
||||
import config from './config'
|
||||
import { clearAndSeedEverything } from './seed'
|
||||
import { lexicalFieldsSlug } from './slugs'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const { beforeAll, describe, beforeEach } = test
|
||||
|
||||
@@ -37,7 +41,7 @@ async function navigateToLexicalFields() {
|
||||
|
||||
describe('lexical', () => {
|
||||
beforeAll(async ({ browser }) => {
|
||||
;({ payload, serverURL } = await initPayloadE2E({ config, dirname: __dirname }))
|
||||
;({ payload, serverURL } = await initPayloadE2E({ config, dirname }))
|
||||
client = new RESTClient(null, { serverURL, defaultSlug: 'rich-text-fields' })
|
||||
await client.login()
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import { type Payload } from '../../packages/payload/src'
|
||||
import getFileByPath from '../../packages/payload/src/uploads/getFileByPath'
|
||||
@@ -44,6 +45,8 @@ import {
|
||||
uploadsSlug,
|
||||
usersSlug,
|
||||
} from './slugs'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
export async function clearAndSeedEverything(_payload: Payload) {
|
||||
return await seedDB({
|
||||
@@ -172,6 +175,6 @@ export async function clearAndSeedEverything(_payload: Payload) {
|
||||
},
|
||||
shouldResetDB: true,
|
||||
snapshotKey: 'fieldsTest',
|
||||
uploadsDir: path.resolve(__dirname, './collections/Upload/uploads'),
|
||||
uploadsDir: path.resolve(dirname, './collections/Upload/uploads'),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -6,16 +6,20 @@ import { setTestEnvPaths } from './helpers/setTestEnvPaths'
|
||||
|
||||
const [testConfigDir] = process.argv.slice(2)
|
||||
|
||||
import { fileURLToPath } from 'url'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
let testDir
|
||||
if (testConfigDir) {
|
||||
testDir = path.resolve(__dirname, testConfigDir)
|
||||
testDir = path.resolve(dirname, testConfigDir)
|
||||
setTestEnvPaths(testDir)
|
||||
generateGraphQLSchema()
|
||||
} else {
|
||||
// Generate graphql schema for entire directory
|
||||
testDir = __dirname
|
||||
testDir = dirname
|
||||
|
||||
fs.readdirSync(__dirname, { withFileTypes: true })
|
||||
fs.readdirSync(dirname, { withFileTypes: true })
|
||||
.filter((f) => f.isDirectory())
|
||||
.forEach((dir) => {
|
||||
const suiteDir = path.resolve(testDir, dir.name)
|
||||
|
||||
@@ -6,16 +6,20 @@ import { setTestEnvPaths } from './helpers/setTestEnvPaths'
|
||||
|
||||
const [testConfigDir] = process.argv.slice(2)
|
||||
|
||||
import { fileURLToPath } from 'url'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
let testDir
|
||||
if (testConfigDir) {
|
||||
testDir = path.resolve(__dirname, testConfigDir)
|
||||
testDir = path.resolve(dirname, testConfigDir)
|
||||
setTestEnvPaths(testDir)
|
||||
generateTypes()
|
||||
} else {
|
||||
// Generate types for entire directory
|
||||
testDir = __dirname
|
||||
testDir = dirname
|
||||
|
||||
fs.readdirSync(__dirname, { withFileTypes: true })
|
||||
fs.readdirSync(dirname, { withFileTypes: true })
|
||||
.filter((f) => f.isDirectory())
|
||||
.forEach((dir) => {
|
||||
const suiteDir = path.resolve(testDir, dir.name)
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import { buildConfigWithDefaults } from '../buildConfigWithDefaults'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
export default buildConfigWithDefaults({
|
||||
graphQL: {
|
||||
schemaOutputFile: path.resolve(__dirname, 'schema.graphql'),
|
||||
schemaOutputFile: path.resolve(dirname, 'schema.graphql'),
|
||||
},
|
||||
typescript: {
|
||||
outputFile: path.resolve(__dirname, 'schema.ts'),
|
||||
outputFile: path.resolve(dirname, 'schema.ts'),
|
||||
},
|
||||
collections: [
|
||||
{
|
||||
|
||||
@@ -2,6 +2,8 @@ import type { Page } from '@playwright/test'
|
||||
import type { Payload } from 'payload'
|
||||
|
||||
import { expect, test } from '@playwright/test'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import { exactText, initPageConsoleErrorCatch, saveDocAndAssert } from '../helpers'
|
||||
import { AdminUrlUtil } from '../helpers/adminUrlUtil'
|
||||
@@ -9,6 +11,8 @@ import { initPayloadE2E } from '../helpers/configHelpers'
|
||||
import config from './config'
|
||||
import { mobileBreakpoint } from './shared'
|
||||
import { startLivePreviewDemo } from './startLivePreviewDemo'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const { beforeAll, describe } = test
|
||||
|
||||
@@ -38,7 +42,7 @@ describe('Live Preview', () => {
|
||||
}
|
||||
|
||||
beforeAll(async ({ browser }) => {
|
||||
;({ serverURL, payload } = await initPayloadE2E({ config, dirname: __dirname }))
|
||||
;({ serverURL, payload } = await initPayloadE2E({ config, dirname }))
|
||||
url = new AdminUrlUtil(serverURL, 'pages')
|
||||
const context = await browser.newContext()
|
||||
page = await context.newPage()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { Payload } from '../../packages/payload/src'
|
||||
import type { Media, Page, Post, Tenant } from './payload-types'
|
||||
@@ -15,6 +16,8 @@ import { Pages } from './collections/Pages'
|
||||
import { postsSlug } from './collections/Posts'
|
||||
import configPromise from './config'
|
||||
import { tenantsSlug } from './shared'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const schemaJSON = fieldSchemaToJSON(Pages.fields)
|
||||
|
||||
@@ -55,7 +58,7 @@ describe('Collections - Live Preview', () => {
|
||||
})
|
||||
|
||||
// Create image
|
||||
const filePath = path.resolve(__dirname, './seed/image-1.jpg')
|
||||
const filePath = path.resolve(dirname, './seed/image-1.jpg')
|
||||
const file = await getFileByPath(filePath)
|
||||
file.name = 'image-1.jpg'
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { Config } from '../../../packages/payload/src/config/types'
|
||||
|
||||
@@ -15,9 +16,11 @@ import { post3 } from './post-3'
|
||||
import { postsPage } from './posts-page'
|
||||
import { tenant1 } from './tenant-1'
|
||||
import { tenant2 } from './tenant-2'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
export const seed: Config['onInit'] = async (payload) => {
|
||||
const uploadsDir = path.resolve(__dirname, './media')
|
||||
const uploadsDir = path.resolve(dirname, './media')
|
||||
removeFiles(path.normalize(uploadsDir))
|
||||
|
||||
await payload.create({
|
||||
@@ -41,7 +44,7 @@ export const seed: Config['onInit'] = async (payload) => {
|
||||
|
||||
const media = await payload.create({
|
||||
collection: 'media',
|
||||
filePath: path.resolve(__dirname, 'image-1.jpg'),
|
||||
filePath: path.resolve(dirname, 'image-1.jpg'),
|
||||
data: {
|
||||
alt: 'Image 1',
|
||||
},
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { spawn } from 'child_process'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { Payload } from '../../packages/payload/src'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const installNodeModules = async (args: { payload: Payload }): Promise<void> => {
|
||||
const { payload } = args
|
||||
@@ -11,7 +14,7 @@ const installNodeModules = async (args: { payload: Payload }): Promise<void> =>
|
||||
return new Promise(function (resolve) {
|
||||
// Install the node modules for the Next.js app
|
||||
const installation = spawn('yarn', ['install'], {
|
||||
cwd: path.resolve(__dirname, './next-app'),
|
||||
cwd: path.resolve(dirname, './next-app'),
|
||||
})
|
||||
|
||||
installation.stdout.on('data', (data) => {
|
||||
@@ -42,7 +45,7 @@ const bootNextApp = async (args: { payload: Payload }): Promise<void> => {
|
||||
return new Promise(function (resolve, reject) {
|
||||
// Boot up the Next.js app
|
||||
const app = spawn('yarn', ['dev'], {
|
||||
cwd: path.resolve(__dirname, './next-app'),
|
||||
cwd: path.resolve(dirname, './next-app'),
|
||||
})
|
||||
|
||||
app.stdout.on('data', (data) => {
|
||||
|
||||
@@ -2,6 +2,8 @@ import type { Page } from '@playwright/test'
|
||||
import type { Payload } from 'payload'
|
||||
|
||||
import { expect, test } from '@playwright/test'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { LocalizedPost } from './payload-types'
|
||||
|
||||
@@ -21,6 +23,8 @@ import {
|
||||
spanishLocale,
|
||||
withRequiredLocalizedFields,
|
||||
} from './shared'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
/**
|
||||
* TODO: Localization
|
||||
@@ -49,7 +53,7 @@ describe('Localization', () => {
|
||||
beforeAll(async ({ browser }) => {
|
||||
;({ payload, serverURL } = await initPayloadE2E({
|
||||
config,
|
||||
dirname: __dirname,
|
||||
dirname,
|
||||
}))
|
||||
|
||||
url = new AdminUrlUtil(serverURL, localizedPostsSlug)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* eslint-disable jest/require-top-level-describe */
|
||||
import * as AWS from '@aws-sdk/client-s3'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { Payload } from '../../packages/payload/src'
|
||||
|
||||
@@ -8,6 +9,8 @@ import { getPayload } from '../../packages/payload/src'
|
||||
import { describeIfInCIOrHasLocalstack } from '../helpers'
|
||||
import { startMemoryDB } from '../startMemoryDB'
|
||||
import configPromise from './config'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
let payload: Payload
|
||||
|
||||
@@ -43,7 +46,7 @@ describe('@payloadcms/plugin-cloud-storage', () => {
|
||||
const upload = await payload.create({
|
||||
collection: 'media',
|
||||
data: {},
|
||||
filePath: path.resolve(__dirname, '../uploads/image.png'),
|
||||
filePath: path.resolve(dirname, '../uploads/image.png'),
|
||||
})
|
||||
|
||||
expect(upload.id).toBeTruthy()
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import type { Page } from '@playwright/test'
|
||||
|
||||
import { expect, test } from '@playwright/test'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { Page as PayloadPage } from './payload-types'
|
||||
import { AdminUrlUtil } from '../helpers/adminUrlUtil'
|
||||
import { initPayloadE2E } from '../helpers/configHelpers'
|
||||
|
||||
import payload from '../../packages/payload/src'
|
||||
import { initPageConsoleErrorCatch } from '../helpers'
|
||||
import { AdminUrlUtil } from '../helpers/adminUrlUtil'
|
||||
import { initPayloadE2E } from '../helpers/configHelpers'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const { beforeAll, describe } = test
|
||||
let url: AdminUrlUtil
|
||||
@@ -16,10 +22,10 @@ let draftChildId: string
|
||||
let childId: string
|
||||
|
||||
type Args = {
|
||||
slug: string
|
||||
title?: string
|
||||
parent?: string
|
||||
status?: 'published' | 'draft'
|
||||
slug: string
|
||||
status?: 'draft' | 'published'
|
||||
title?: string
|
||||
}
|
||||
|
||||
async function createPage({
|
||||
@@ -31,8 +37,8 @@ async function createPage({
|
||||
return payload.create({
|
||||
collection: 'pages',
|
||||
data: {
|
||||
title: title,
|
||||
slug: slug,
|
||||
title,
|
||||
slug,
|
||||
_status: status,
|
||||
parent,
|
||||
},
|
||||
@@ -41,7 +47,7 @@ async function createPage({
|
||||
|
||||
describe('Nested Docs Plugin', () => {
|
||||
beforeAll(async ({ browser }) => {
|
||||
const { serverURL } = await initPayloadE2E(__dirname)
|
||||
const { serverURL } = await initPayloadE2E(dirname)
|
||||
url = new AdminUrlUtil(serverURL, 'pages')
|
||||
|
||||
const context = await browser.newContext()
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { CollectionConfig } from '../../../packages/payload/src/collections/config/types'
|
||||
|
||||
import { mediaSlug } from '../shared'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
export const Media: CollectionConfig = {
|
||||
slug: mediaSlug,
|
||||
upload: {
|
||||
staticDir: path.resolve(__dirname, '../media'),
|
||||
staticDir: path.resolve(dirname, '../media'),
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { Payload } from 'payload'
|
||||
|
||||
import { expect, test } from '@playwright/test'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { Page as PayloadPage } from './payload-types'
|
||||
|
||||
@@ -12,6 +13,8 @@ import { AdminUrlUtil } from '../helpers/adminUrlUtil'
|
||||
import { initPayloadE2E } from '../helpers/configHelpers'
|
||||
import config from '../uploads/config'
|
||||
import { mediaSlug } from './shared'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const { beforeAll, describe } = test
|
||||
let url: AdminUrlUtil
|
||||
@@ -21,14 +24,14 @@ let payload: Payload
|
||||
|
||||
describe('SEO Plugin', () => {
|
||||
beforeAll(async ({ browser }) => {
|
||||
const { serverURL } = await initPayloadE2E({ config, dirname: __dirname })
|
||||
const { serverURL } = await initPayloadE2E({ config, dirname })
|
||||
url = new AdminUrlUtil(serverURL, 'pages')
|
||||
|
||||
const context = await browser.newContext()
|
||||
page = await context.newPage()
|
||||
initPageConsoleErrorCatch(page)
|
||||
|
||||
const filePath = path.resolve(__dirname, './image-1.jpg')
|
||||
const filePath = path.resolve(dirname, './image-1.jpg')
|
||||
const file = await getFileByPath(filePath)
|
||||
|
||||
const mediaDoc = await payload.create({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { Payload } from '../../packages/payload/src'
|
||||
|
||||
@@ -8,6 +9,8 @@ import removeFiles from '../helpers/removeFiles'
|
||||
import { startMemoryDB } from '../startMemoryDB'
|
||||
import configPromise from './config'
|
||||
import { mediaSlug } from './shared'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
let payload: Payload
|
||||
|
||||
@@ -16,14 +19,14 @@ describe('@payloadcms/plugin-seo', () => {
|
||||
let mediaDoc = null
|
||||
|
||||
beforeAll(async () => {
|
||||
const uploadsDir = path.resolve(__dirname, './media')
|
||||
const uploadsDir = path.resolve(dirname, './media')
|
||||
removeFiles(path.normalize(uploadsDir))
|
||||
|
||||
const config = await startMemoryDB(configPromise)
|
||||
payload = await getPayload({ config })
|
||||
|
||||
// Create image
|
||||
const filePath = path.resolve(__dirname, './image-1.jpg')
|
||||
const filePath = path.resolve(dirname, './image-1.jpg')
|
||||
const file = await getFileByPath(filePath)
|
||||
|
||||
mediaDoc = await payload.create({
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import type { Page } from '@playwright/test'
|
||||
|
||||
import { expect, test } from '@playwright/test'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import { closeNav, initPageConsoleErrorCatch, openNav } from '../helpers'
|
||||
import { initPayloadE2E } from '../helpers/configHelpers'
|
||||
import config from './config'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const { beforeAll, describe } = test
|
||||
|
||||
@@ -13,7 +17,7 @@ describe('refresh-permissions', () => {
|
||||
let page: Page
|
||||
|
||||
beforeAll(async ({ browser }) => {
|
||||
;({ serverURL } = await initPayloadE2E({ config, dirname: __dirname }))
|
||||
;({ serverURL } = await initPayloadE2E({ config, dirname }))
|
||||
const context = await browser.newContext()
|
||||
page = await context.newPage()
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ import slash from 'slash'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
const dirname = path.dirname(__filename)
|
||||
|
||||
shelljs.env.DISABLE_LOGGING = 'true'
|
||||
|
||||
const playwrightBin = path.resolve(__dirname, '../node_modules/.bin/playwright')
|
||||
const playwrightBin = path.resolve(dirname, '../node_modules/.bin/playwright')
|
||||
|
||||
const testRunCodes: { code: number; suiteName: string }[] = []
|
||||
const { _: args, bail, part } = minimist(process.argv.slice(2))
|
||||
@@ -18,7 +18,7 @@ const suiteName = args[0]
|
||||
|
||||
// Run all
|
||||
if (!suiteName) {
|
||||
let files = glob.sync(`${path.resolve(__dirname).replace(/\\/g, '/')}/**/*e2e.spec.ts`)
|
||||
let files = glob.sync(`${path.resolve(dirname).replace(/\\/g, '/')}/**/*e2e.spec.ts`)
|
||||
|
||||
const totalFiles = files.length
|
||||
|
||||
@@ -53,7 +53,7 @@ if (!suiteName) {
|
||||
} else {
|
||||
// Run specific suite
|
||||
clearWebpackCache()
|
||||
const suitePath = path.resolve(__dirname, suiteName, 'e2e.spec.ts')
|
||||
const suitePath = path.resolve(dirname, suiteName, 'e2e.spec.ts')
|
||||
executePlaywright(suitePath)
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ if (testRunCodes.some((tr) => tr.code > 0)) process.exit(1)
|
||||
function executePlaywright(suitePath: string, bail = false) {
|
||||
console.log(`Executing ${suitePath}...`)
|
||||
const playwrightCfg = path.resolve(
|
||||
__dirname,
|
||||
dirname,
|
||||
'..',
|
||||
`${bail ? 'playwright.bail.config.ts' : 'playwright.config.ts'}`,
|
||||
)
|
||||
@@ -89,6 +89,6 @@ function executePlaywright(suitePath: string, bail = false) {
|
||||
}
|
||||
|
||||
function clearWebpackCache() {
|
||||
const webpackCachePath = path.resolve(__dirname, '../node_modules/.cache/webpack')
|
||||
const webpackCachePath = path.resolve(dirname, '../node_modules/.cache/webpack')
|
||||
shelljs.rm('-rf', webpackCachePath)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { Payload } from 'payload'
|
||||
|
||||
import { expect, test } from '@playwright/test'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { Media } from './payload-types'
|
||||
|
||||
@@ -14,6 +15,8 @@ import { RESTClient } from '../helpers/rest'
|
||||
import { adminThumbnailSrc } from './collections/admin-thumbnail'
|
||||
import config from './config'
|
||||
import { adminThumbnailSlug, audioSlug, mediaSlug, relationSlug } from './shared'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const { beforeAll, describe } = test
|
||||
|
||||
@@ -31,7 +34,7 @@ describe('uploads', () => {
|
||||
let audioDoc: Media
|
||||
|
||||
beforeAll(async ({ browser }) => {
|
||||
;({ payload, serverURL } = await initPayloadE2E({ config, dirname: __dirname }))
|
||||
;({ payload, serverURL } = await initPayloadE2E({ config, dirname }))
|
||||
client = new RESTClient(null, { defaultSlug: 'users', serverURL })
|
||||
await client.login()
|
||||
|
||||
@@ -88,7 +91,7 @@ describe('uploads', () => {
|
||||
test('should create file upload', async () => {
|
||||
await page.goto(mediaURL.create)
|
||||
|
||||
await page.setInputFiles('input[type="file"]', path.resolve(__dirname, './image.png'))
|
||||
await page.setInputFiles('input[type="file"]', path.resolve(dirname, './image.png'))
|
||||
|
||||
const filename = page.locator('.file-field__filename')
|
||||
|
||||
@@ -201,7 +204,7 @@ describe('uploads', () => {
|
||||
await expect(page.locator('[id^=doc-drawer_media_2_]')).toBeVisible()
|
||||
await page
|
||||
.locator('[id^=doc-drawer_media_2_] .file-field__upload input[type="file"]')
|
||||
.setInputFiles(path.resolve(__dirname, './image.png'))
|
||||
.setInputFiles(path.resolve(dirname, './image.png'))
|
||||
await page.locator('[id^=doc-drawer_media_2_] button#action-save').click()
|
||||
await wait(200)
|
||||
await expect(page.locator('.Toastify')).toContainText('successfully')
|
||||
@@ -227,7 +230,7 @@ describe('uploads', () => {
|
||||
|
||||
test('Should detect correct mimeType', async () => {
|
||||
await page.goto(mediaURL.create)
|
||||
await page.setInputFiles('input[type="file"]', path.resolve(__dirname, './image.png'))
|
||||
await page.setInputFiles('input[type="file"]', path.resolve(dirname, './image.png'))
|
||||
await saveDocAndAssert(page)
|
||||
|
||||
const imageID = page.url().split('/').pop()
|
||||
@@ -265,7 +268,7 @@ describe('uploads', () => {
|
||||
const fileChooserPromise = page.waitForEvent('filechooser')
|
||||
await page.getByText('Select a file').click()
|
||||
const fileChooser = await fileChooserPromise
|
||||
await fileChooser.setFiles(path.join(__dirname, 'test-image.jpg'))
|
||||
await fileChooser.setFiles(path.join(dirname, 'test-image.jpg'))
|
||||
await page.locator('.file-field__edit').click()
|
||||
|
||||
// set crop
|
||||
|
||||
@@ -2,6 +2,7 @@ import { File as FileBuffer } from 'buffer'
|
||||
import NodeFormData from 'form-data'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { promisify } from 'util'
|
||||
|
||||
import type { Payload } from '../../packages/payload/src'
|
||||
@@ -20,6 +21,8 @@ import {
|
||||
unstoredMediaSlug,
|
||||
usersSlug,
|
||||
} from './shared'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const getMimeType = (
|
||||
filePath: string,
|
||||
@@ -64,7 +67,7 @@ const bufferToFileBlob = async (filePath: string): Promise<File> =>
|
||||
|
||||
// Convert type FileBuffer > unknown > File
|
||||
// The File type expects webkitRelativePath, we don't have that
|
||||
resolve(new FileBuffer([data], filename, { type: type }) as unknown as File)
|
||||
resolve(new FileBuffer([data], filename, { type }) as unknown as File)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -85,7 +88,7 @@ describe('Collections - Uploads', () => {
|
||||
describe('create', () => {
|
||||
it('creates from form data given a png', async () => {
|
||||
const formData = new FormData()
|
||||
const filePath = path.join(__dirname, './image.png')
|
||||
const filePath = path.join(dirname, './image.png')
|
||||
|
||||
formData.append('file', await bufferToFileBlob(filePath))
|
||||
|
||||
@@ -98,7 +101,7 @@ describe('Collections - Uploads', () => {
|
||||
expect(response.status).toBe(201)
|
||||
|
||||
const { sizes } = doc
|
||||
const expectedPath = path.join(__dirname, './media')
|
||||
const expectedPath = path.join(dirname, './media')
|
||||
|
||||
// Check for files
|
||||
expect(await fileExists(path.join(expectedPath, doc.filename))).toBe(true)
|
||||
@@ -122,7 +125,7 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
it('creates from form data given an svg', async () => {
|
||||
const formData = new FormData()
|
||||
const filePath = path.join(__dirname, './image.svg')
|
||||
const filePath = path.join(dirname, './image.svg')
|
||||
formData.append('file', await bufferToFileBlob(filePath))
|
||||
|
||||
const response = await restClient.POST(`/${mediaSlug}`, {
|
||||
@@ -134,7 +137,7 @@ describe('Collections - Uploads', () => {
|
||||
expect(response.status).toBe(201)
|
||||
|
||||
// Check for files
|
||||
expect(await fileExists(path.join(__dirname, './media', doc.filename))).toBe(true)
|
||||
expect(await fileExists(path.join(dirname, './media', doc.filename))).toBe(true)
|
||||
|
||||
// Check api response
|
||||
expect(doc.mimeType).toEqual('image/svg+xml')
|
||||
@@ -146,7 +149,7 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
it('should have valid image url', async () => {
|
||||
const formData = new FormData()
|
||||
const fileBlob = await bufferToFileBlob(path.join(__dirname, './image.svg'))
|
||||
const fileBlob = await bufferToFileBlob(path.join(dirname, './image.svg'))
|
||||
formData.append('file', fileBlob)
|
||||
|
||||
const response = await restClient.POST(`/${mediaSlug}`, {
|
||||
@@ -156,7 +159,7 @@ describe('Collections - Uploads', () => {
|
||||
const { doc } = await response.json()
|
||||
|
||||
expect(response.status).toBe(201)
|
||||
const expectedPath = path.join(__dirname, './media')
|
||||
const expectedPath = path.join(dirname, './media')
|
||||
expect(await fileExists(path.join(expectedPath, doc.filename))).toBe(true)
|
||||
|
||||
expect(doc.url).not.toContain('undefined')
|
||||
@@ -164,7 +167,7 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
it('creates images that do not require all sizes', async () => {
|
||||
const formData = new FormData()
|
||||
const fileBlob = await bufferToFileBlob(path.join(__dirname, './small.png'))
|
||||
const fileBlob = await bufferToFileBlob(path.join(dirname, './small.png'))
|
||||
formData.append('file', fileBlob)
|
||||
|
||||
const response = await restClient.POST(`/${mediaSlug}`, {
|
||||
@@ -175,7 +178,7 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
expect(response.status).toBe(201)
|
||||
|
||||
const expectedPath = path.join(__dirname, './media')
|
||||
const expectedPath = path.join(dirname, './media')
|
||||
|
||||
// Check for files
|
||||
expect(await fileExists(path.join(expectedPath, doc.filename))).toBe(true)
|
||||
@@ -189,7 +192,7 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
it('creates images from a different format', async () => {
|
||||
const formData = new FormData()
|
||||
const fileBlob = await bufferToFileBlob(path.join(__dirname, './image.jpg'))
|
||||
const fileBlob = await bufferToFileBlob(path.join(dirname, './image.jpg'))
|
||||
formData.append('file', fileBlob)
|
||||
|
||||
const response = await restClient.POST(`/${mediaSlug}`, {
|
||||
@@ -200,7 +203,7 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
expect(response.status).toBe(201)
|
||||
|
||||
const expectedPath = path.join(__dirname, './media')
|
||||
const expectedPath = path.join(dirname, './media')
|
||||
|
||||
// Check for files
|
||||
expect(await fileExists(path.join(expectedPath, doc.filename))).toBe(true)
|
||||
@@ -217,7 +220,7 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
it('creates media without storing a file', async () => {
|
||||
const formData = new FormData()
|
||||
const fileBlob = await bufferToFileBlob(path.join(__dirname, './unstored.png'))
|
||||
const fileBlob = await bufferToFileBlob(path.join(dirname, './unstored.png'))
|
||||
formData.append('file', fileBlob)
|
||||
|
||||
// unstored media
|
||||
@@ -230,14 +233,14 @@ describe('Collections - Uploads', () => {
|
||||
expect(response.status).toBe(201)
|
||||
|
||||
// Check for files
|
||||
expect(await fileExists(path.join(__dirname, './media', doc.filename))).toBe(false)
|
||||
expect(await fileExists(path.join(dirname, './media', doc.filename))).toBe(false)
|
||||
|
||||
// Check api response
|
||||
expect(doc.filename).toBeDefined()
|
||||
})
|
||||
|
||||
it('should enlarge images if resize options `withoutEnlargement` is set to false', async () => {
|
||||
const small = await getFileByPath(path.resolve(__dirname, './small.png'))
|
||||
const small = await getFileByPath(path.resolve(dirname, './small.png'))
|
||||
|
||||
const result = await payload.create({
|
||||
collection: enlargeSlug,
|
||||
@@ -248,7 +251,7 @@ describe('Collections - Uploads', () => {
|
||||
expect(result).toBeTruthy()
|
||||
|
||||
const { sizes } = result as unknown as Enlarge
|
||||
const expectedPath = path.join(__dirname, './media/enlarge')
|
||||
const expectedPath = path.join(dirname, './media/enlarge')
|
||||
|
||||
// Check for files
|
||||
expect(await fileExists(path.join(expectedPath, small.name))).toBe(true)
|
||||
@@ -282,7 +285,7 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
// This test makes sure that the image resizing is not prevented if only one dimension is larger (due to payload preventing enlargement by default)
|
||||
it('should resize images if one desired dimension is smaller and the other is larger', async () => {
|
||||
const small = await getFileByPath(path.resolve(__dirname, './small.png'))
|
||||
const small = await getFileByPath(path.resolve(dirname, './small.png'))
|
||||
|
||||
const result = (await payload.create({
|
||||
collection: enlargeSlug,
|
||||
@@ -293,7 +296,7 @@ describe('Collections - Uploads', () => {
|
||||
expect(result).toBeTruthy()
|
||||
|
||||
const { sizes } = result
|
||||
const expectedPath = path.join(__dirname, './media/enlarge')
|
||||
const expectedPath = path.join(dirname, './media/enlarge')
|
||||
|
||||
// Check for files
|
||||
expect(await fileExists(path.join(expectedPath, sizes.widthLowerHeightLarger.filename))).toBe(
|
||||
@@ -310,8 +313,8 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
it('should not reduce images if resize options `withoutReduction` is set to true', async () => {
|
||||
const formData = new NodeFormData()
|
||||
formData.append('file', fs.createReadStream(path.join(__dirname, './small.png')))
|
||||
const small = await getFileByPath(path.resolve(__dirname, './small.png'))
|
||||
formData.append('file', fs.createReadStream(path.join(dirname, './small.png')))
|
||||
const small = await getFileByPath(path.resolve(dirname, './small.png'))
|
||||
|
||||
const result = await payload.create({
|
||||
collection: reduceSlug,
|
||||
@@ -322,7 +325,7 @@ describe('Collections - Uploads', () => {
|
||||
expect(result).toBeTruthy()
|
||||
|
||||
const { sizes } = result as unknown as Enlarge
|
||||
const expectedPath = path.join(__dirname, './media/reduce')
|
||||
const expectedPath = path.join(dirname, './media/reduce')
|
||||
|
||||
// Check for files
|
||||
expect(await fileExists(path.join(expectedPath, small.name))).toBe(true)
|
||||
@@ -352,7 +355,7 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
it('update', async () => {
|
||||
// Create image
|
||||
const filePath = path.resolve(__dirname, './image.png')
|
||||
const filePath = path.resolve(dirname, './image.png')
|
||||
const file = await getFileByPath(filePath)
|
||||
file.name = 'renamed.png'
|
||||
|
||||
@@ -363,7 +366,7 @@ describe('Collections - Uploads', () => {
|
||||
})) as unknown as Media
|
||||
|
||||
const formData = new FormData()
|
||||
formData.append('file', await bufferToFileBlob(path.join(__dirname, './small.png')))
|
||||
formData.append('file', await bufferToFileBlob(path.join(dirname, './small.png')))
|
||||
|
||||
const response = await restClient.PATCH(`/${mediaSlug}/${mediaDoc.id}`, {
|
||||
body: formData,
|
||||
@@ -372,7 +375,7 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
|
||||
const expectedPath = path.join(__dirname, './media')
|
||||
const expectedPath = path.join(dirname, './media')
|
||||
|
||||
// Check that previously existing files were removed
|
||||
expect(await fileExists(path.join(expectedPath, mediaDoc.filename))).toBe(false)
|
||||
@@ -381,7 +384,7 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
it('update - update many', async () => {
|
||||
// Create image
|
||||
const filePath = path.resolve(__dirname, './image.png')
|
||||
const filePath = path.resolve(dirname, './image.png')
|
||||
const file = await getFileByPath(filePath)
|
||||
file.name = 'renamed.png'
|
||||
|
||||
@@ -392,7 +395,7 @@ describe('Collections - Uploads', () => {
|
||||
})) as unknown as Media
|
||||
|
||||
const formData = new FormData()
|
||||
formData.append('file', await bufferToFileBlob(path.join(__dirname, './small.png')))
|
||||
formData.append('file', await bufferToFileBlob(path.join(dirname, './small.png')))
|
||||
|
||||
const response = await restClient.PATCH(`/${mediaSlug}`, {
|
||||
body: formData,
|
||||
@@ -408,7 +411,7 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
|
||||
const expectedPath = path.join(__dirname, './media')
|
||||
const expectedPath = path.join(dirname, './media')
|
||||
|
||||
// Check that previously existing files were removed
|
||||
expect(await fileExists(path.join(expectedPath, mediaDoc.filename))).toBe(false)
|
||||
@@ -417,7 +420,7 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
it('should remove existing media on re-upload', async () => {
|
||||
// Create temp file
|
||||
const filePath = path.resolve(__dirname, './temp.png')
|
||||
const filePath = path.resolve(dirname, './temp.png')
|
||||
const file = await getFileByPath(filePath)
|
||||
file.name = 'temp.png'
|
||||
|
||||
@@ -427,13 +430,13 @@ describe('Collections - Uploads', () => {
|
||||
file,
|
||||
})) as unknown as Media
|
||||
|
||||
const expectedPath = path.join(__dirname, './media')
|
||||
const expectedPath = path.join(dirname, './media')
|
||||
|
||||
// Check that the temp file was created
|
||||
expect(await fileExists(path.join(expectedPath, mediaDoc.filename))).toBe(true)
|
||||
|
||||
// Replace the temp file with a new one
|
||||
const newFilePath = path.resolve(__dirname, './temp-renamed.png')
|
||||
const newFilePath = path.resolve(dirname, './temp-renamed.png')
|
||||
const newFile = await getFileByPath(newFilePath)
|
||||
newFile.name = 'temp-renamed.png'
|
||||
|
||||
@@ -451,7 +454,7 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
it('should remove existing media on re-upload - update many', async () => {
|
||||
// Create temp file
|
||||
const filePath = path.resolve(__dirname, './temp.png')
|
||||
const filePath = path.resolve(dirname, './temp.png')
|
||||
const file = await getFileByPath(filePath)
|
||||
file.name = 'temp.png'
|
||||
|
||||
@@ -461,13 +464,13 @@ describe('Collections - Uploads', () => {
|
||||
file,
|
||||
})) as unknown as Media
|
||||
|
||||
const expectedPath = path.join(__dirname, './media')
|
||||
const expectedPath = path.join(dirname, './media')
|
||||
|
||||
// Check that the temp file was created
|
||||
expect(await fileExists(path.join(expectedPath, mediaDoc.filename))).toBe(true)
|
||||
|
||||
// Replace the temp file with a new one
|
||||
const newFilePath = path.resolve(__dirname, './temp-renamed.png')
|
||||
const newFilePath = path.resolve(dirname, './temp-renamed.png')
|
||||
const newFile = await getFileByPath(newFilePath)
|
||||
newFile.name = 'temp-renamed-second.png'
|
||||
|
||||
@@ -487,9 +490,9 @@ describe('Collections - Uploads', () => {
|
||||
})
|
||||
|
||||
it('should remove extra sizes on update', async () => {
|
||||
const filePath = path.resolve(__dirname, './image.png')
|
||||
const filePath = path.resolve(dirname, './image.png')
|
||||
const file = await getFileByPath(filePath)
|
||||
const small = await getFileByPath(path.resolve(__dirname, './small.png'))
|
||||
const small = await getFileByPath(path.resolve(dirname, './small.png'))
|
||||
|
||||
const { id } = await payload.create({
|
||||
collection: mediaSlug,
|
||||
@@ -509,9 +512,9 @@ describe('Collections - Uploads', () => {
|
||||
})
|
||||
|
||||
it('should remove extra sizes on update - update many', async () => {
|
||||
const filePath = path.resolve(__dirname, './image.png')
|
||||
const filePath = path.resolve(dirname, './image.png')
|
||||
const file = await getFileByPath(filePath)
|
||||
const small = await getFileByPath(path.resolve(__dirname, './small.png'))
|
||||
const small = await getFileByPath(path.resolve(dirname, './small.png'))
|
||||
|
||||
const { id } = await payload.create({
|
||||
collection: mediaSlug,
|
||||
@@ -533,7 +536,7 @@ describe('Collections - Uploads', () => {
|
||||
})
|
||||
|
||||
it('should allow update removing a relationship', async () => {
|
||||
const filePath = path.resolve(__dirname, './image.png')
|
||||
const filePath = path.resolve(dirname, './image.png')
|
||||
const file = await getFileByPath(filePath)
|
||||
file.name = 'renamed.png'
|
||||
|
||||
@@ -562,7 +565,7 @@ describe('Collections - Uploads', () => {
|
||||
})
|
||||
|
||||
it('should allow update removing a relationship - update many', async () => {
|
||||
const filePath = path.resolve(__dirname, './image.png')
|
||||
const filePath = path.resolve(dirname, './image.png')
|
||||
const file = await getFileByPath(filePath)
|
||||
file.name = 'renamed.png'
|
||||
|
||||
@@ -594,7 +597,7 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
it('delete', async () => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', await bufferToFileBlob(path.join(__dirname, './image.png')))
|
||||
formData.append('file', await bufferToFileBlob(path.join(dirname, './image.png')))
|
||||
|
||||
const { doc } = await restClient
|
||||
.POST(`/${mediaSlug}`, {
|
||||
@@ -606,12 +609,12 @@ describe('Collections - Uploads', () => {
|
||||
const response2 = await restClient.DELETE(`/${mediaSlug}/${doc.id}`)
|
||||
expect(response2.status).toBe(200)
|
||||
|
||||
expect(await fileExists(path.join(__dirname, doc.filename))).toBe(false)
|
||||
expect(await fileExists(path.join(dirname, doc.filename))).toBe(false)
|
||||
})
|
||||
|
||||
it('delete - update many', async () => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', await bufferToFileBlob(path.join(__dirname, './image.png')))
|
||||
formData.append('file', await bufferToFileBlob(path.join(dirname, './image.png')))
|
||||
|
||||
const { doc } = await restClient
|
||||
.POST(`/${mediaSlug}`, {
|
||||
@@ -634,7 +637,7 @@ describe('Collections - Uploads', () => {
|
||||
|
||||
expect(errors).toHaveLength(0)
|
||||
|
||||
expect(await fileExists(path.join(__dirname, doc.filename))).toBe(false)
|
||||
expect(await fileExists(path.join(dirname, doc.filename))).toBe(false)
|
||||
})
|
||||
|
||||
describe('filesRequiredOnCreate', () => {
|
||||
@@ -643,7 +646,7 @@ describe('Collections - Uploads', () => {
|
||||
expect(
|
||||
async () =>
|
||||
await payload.create({
|
||||
// @ts-ignore
|
||||
// @ts-expect-error
|
||||
collection: 'optional-file',
|
||||
data: {},
|
||||
}),
|
||||
@@ -653,7 +656,7 @@ describe('Collections - Uploads', () => {
|
||||
it('should throw an error if no file and filesRequiredOnCreate is true', async () => {
|
||||
await expect(async () =>
|
||||
payload.create({
|
||||
// @ts-ignore
|
||||
// @ts-expect-error
|
||||
collection: 'required-file',
|
||||
data: {},
|
||||
}),
|
||||
|
||||
@@ -27,6 +27,8 @@ import type { Page } from '@playwright/test'
|
||||
import type { Payload } from 'payload'
|
||||
|
||||
import { expect, test } from '@playwright/test'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import wait from '../../packages/payload/src/utilities/wait'
|
||||
import { globalSlug } from '../admin/slugs'
|
||||
@@ -52,6 +54,8 @@ import {
|
||||
draftGlobalSlug,
|
||||
postCollectionSlug,
|
||||
} from './slugs'
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const { beforeAll, beforeEach, describe } = test
|
||||
|
||||
@@ -67,7 +71,7 @@ describe('versions', () => {
|
||||
let postURL: AdminUrlUtil
|
||||
|
||||
beforeAll(async ({ browser }) => {
|
||||
;({ payload, serverURL } = await initPayloadE2E({ config, dirname: __dirname }))
|
||||
;({ payload, serverURL } = await initPayloadE2E({ config, dirname }))
|
||||
const context = await browser.newContext()
|
||||
page = await context.newPage()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user