Merge branch 'alpha' of https://github.com/payloadcms/payload into chore/alpha-remove-schemaOutputFile

This commit is contained in:
PatrikKozak
2024-03-11 14:05:33 -04:00
103 changed files with 2505 additions and 630 deletions

View File

@@ -7,7 +7,6 @@ import { fileURLToPath } from 'url'
import { initPageConsoleErrorCatch } from '../helpers.js'
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2E } from '../helpers/configHelpers.js'
import config from './config.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
@@ -19,7 +18,7 @@ describe('Admin Panel', () => {
let url: AdminUrlUtil
beforeAll(async ({ browser }) => {
const { serverURL } = await initPayloadE2E({ config, dirname })
const { serverURL } = await initPayloadE2E({ dirname })
url = new AdminUrlUtil(serverURL, 'posts')
const context = await browser.newContext()

View File

@@ -2,7 +2,7 @@ import { v4 as uuid } from 'uuid'
import { mapAsync } from '../../packages/payload/src/utilities/mapAsync.js'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
import { devUser } from '../credentials.js.'
import { devUser } from '../credentials.js'
import { AuthDebug } from './AuthDebug.js'
import { apiKeysSlug, namedSaveToJWTValue, saveToJWTKey, slug } from './shared.js'

View File

@@ -1 +0,0 @@
import '@testing-library/jest-dom'

View File

@@ -1,3 +1,4 @@
import { sql } from 'drizzle-orm'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'

View File

@@ -1,37 +1,60 @@
import { spawn } from 'child_process'
import getPort from 'get-port'
//import { nextDev } from 'next/dist/cli/next-dev.js'
import { nextDev } from 'next/dist/cli/next-dev.js'
import path from 'path'
import type { SanitizedConfig } from '../../packages/payload/src/config/types.js'
import type { Payload } from '../../packages/payload/src/index.js'
import wait from '../../packages/payload/src/utilities/wait.js'
import { getPayload } from '../../packages/payload/src/index.js'
import { bootAdminPanel } from './bootAdminPanel.mjs'
type InitializedPayload = { payload: Payload; serverURL: string }
export async function initPayloadE2E(args: {
config: Promise<SanitizedConfig>
type Args = {
dirname: string
}): Promise<InitializedPayload> {
const { config, dirname } = args
}
console.log('dirname', dirname)
type Result = {
serverURL: string
}
// process.env.TURBOPACK = '1' // Not working due to turbopack pulling in mongoose, pg
export async function initPayloadE2E({ dirname }: Args): Promise<Result> {
const port = await getPort()
const serverURL = `http://localhost:${port}`
process.env.PAYLOAD_CONFIG_PATH = path.resolve(dirname, './config.js')
process.env.PAYLOAD_DROP_DATABASE = 'true'
//process.env.NODE_ENV = 'test'
process.env.PORT = String(port)
const payload = await getPayload({ config })
// @ts-expect-error
process.env.NODE_ENV = 'test'
nextDev({
_: [path.resolve(dirname, '../../')],
'--port': port,
// Turbo doesn't seem to be reading
// our tsconfig paths, commented out for now
// '--turbo': '1',
})
await wait(3000)
return { serverURL }
}
export async function initPayloadSpawn({ dirname }: Args): Promise<Result> {
const port = await getPort()
const serverURL = `http://localhost:${port}`
//process.env.APP_ENV = 'test'
//process.env.__NEXT_TEST_MODE = 'jest'
// Tried using a child process to get
// turbopack to pick up our tsconfig aliases
// but this didn't make a difference.
// Keeping it here so we can continue to try.
spawn('pnpm', ['dev', '--turbo'], {
cwd: path.resolve(dirname, '../../'),
env: {
...process.env,
NODE_ENV: 'test',
PORT: String(port),
PAYLOAD_CONFIG_PATH: path.resolve(dirname, '../../config.js'),
PAYLOAD_DROP_DATABASE: 'true',
},
})
//await nextDev({ _: [path.resolve(dirname, '../../')], port }) // Running nextDev directly does not work for ports other than 3000
await bootAdminPanel({ port, appDir: path.resolve(dirname, '../../') })
return { serverURL, payload }
await wait(3000)
return { serverURL }
}

View File

@@ -833,9 +833,17 @@ describe('Localization', () => {
}
`
const { en, es } = await client.request(query, null, {
Authorization: `JWT ${token}`,
})
const { data: multipleLocaleData } = await restClient
.GRAPHQL_POST({
body: JSON.stringify({ query }),
query: { locale: 'en' },
headers: {
Authorization: `JWT ${token}`,
},
})
.then((res) => res.json())
const { en, es } = multipleLocaleData
expect(en.title).toStrictEqual(englishTitle)
expect(es.title).toStrictEqual(spanishTitle)

View File

@@ -11,7 +11,6 @@ import type {
} from './payload-types.js'
import { getPayload } from '../../packages/payload/src/index.js'
import { devUser } from '../credentials.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js'
@@ -27,16 +26,9 @@ import {
usersSlug,
} from './shared.js'
let apiUrl
let jwt
let restClient: NextRESTClient
let payload: Payload
const headers = {
'Content-Type': 'application/json',
}
const { email, password } = devUser
type EasierChained = { id: string; relation: EasierChained }
describe('Relationships', () => {
@@ -757,14 +749,11 @@ describe('Relationships', () => {
],
},
},
headers: {
Authorization: `JWT ${token}`,
},
})
.then((res) => res.json())
expect(queryOne.result.docs).toHaveLength(1)
expect(queryTwo.result.docs).toHaveLength(1)
expect(queryOne.docs).toHaveLength(1)
expect(queryTwo.docs).toHaveLength(1)
})
})
})

View File

@@ -54,7 +54,6 @@ export default buildConfigWithDefaults({
slug: 'gif-resize',
fields: [],
upload: {
staticURL: '/media-gif',
staticDir: path.resolve(process.cwd(), 'test/uploads/media-gif'),
mimeTypes: ['image/gif'],
resizeOptions: {
@@ -85,7 +84,6 @@ export default buildConfigWithDefaults({
slug: 'no-image-sizes',
fields: [],
upload: {
staticURL: '/no-image-sizes',
staticDir: path.resolve(process.cwd(), 'test/uploads/no-image-sizes'),
mimeTypes: ['image/png', 'image/jpg', 'image/jpeg'],
resizeOptions: {
@@ -99,7 +97,6 @@ export default buildConfigWithDefaults({
slug: 'object-fit',
fields: [],
upload: {
staticURL: '/object-fit',
staticDir: path.resolve(process.cwd(), 'test/uploads/object-fit'),
mimeTypes: ['image/png', 'image/jpg', 'image/jpeg'],
imageSizes: [
@@ -135,7 +132,6 @@ export default buildConfigWithDefaults({
fields: [],
upload: {
focalPoint: false,
staticURL: '/crop-only',
staticDir: path.resolve(process.cwd(), 'test/uploads/crop-only'),
mimeTypes: ['image/png', 'image/jpg', 'image/jpeg'],
imageSizes: [
@@ -162,7 +158,6 @@ export default buildConfigWithDefaults({
fields: [],
upload: {
crop: false,
staticURL: '/focal-only',
staticDir: path.resolve(process.cwd(), 'test/uploads/focal-only'),
mimeTypes: ['image/png', 'image/jpg', 'image/jpeg'],
imageSizes: [
@@ -189,7 +184,6 @@ export default buildConfigWithDefaults({
fields: [],
upload: {
staticDir: path.resolve(process.cwd(), 'test/uploads/media'),
staticURL: '/test/uploads/media',
// crop: false,
// focalPoint: false,
formatOptions: {
@@ -286,7 +280,6 @@ export default buildConfigWithDefaults({
slug: enlargeSlug,
fields: [],
upload: {
staticURL: '/enlarge',
staticDir: path.resolve(process.cwd(), 'test/uploads/media/enlarge'),
mimeTypes: [
'image/png',
@@ -334,7 +327,6 @@ export default buildConfigWithDefaults({
slug: reduceSlug,
fields: [],
upload: {
staticURL: '/reduce',
staticDir: path.resolve(process.cwd(), 'test/uploads/media/reduce'),
imageSizes: [
{
@@ -376,27 +368,20 @@ export default buildConfigWithDefaults({
slug: 'media-trim',
fields: [],
upload: {
staticURL: '/media-trim',
staticDir: path.resolve(process.cwd(), 'test/uploads/media-trim'),
mimeTypes: ['image/png', 'image/jpg', 'image/jpeg'],
trimOptions: {
threshold: 0,
},
trimOptions: 0,
imageSizes: [
{
name: 'trimNumber',
height: undefined,
trimOptions: {
threshold: 0,
},
trimOptions: 0,
width: 1024,
},
{
name: 'trimString',
height: undefined,
trimOptions: {
threshold: 0,
},
trimOptions: 0,
width: 1024,
},
{
@@ -416,7 +401,6 @@ export default buildConfigWithDefaults({
fields: [],
upload: {
disableLocalStorage: true,
staticURL: '/media',
},
},
{
@@ -424,7 +408,6 @@ export default buildConfigWithDefaults({
fields: [],
upload: {
// Either use another web server like `npx serve -l 4000` (http://localhost:4000) or use the static server from the previous collection to serve the media folder (http://localhost:3000/media)
staticURL: 'http://localhost:3000/media',
staticDir: path.resolve(process.cwd(), 'test/uploads/media'),
},
},
@@ -437,14 +420,12 @@ export default buildConfigWithDefaults({
upload: {
filesRequiredOnCreate: false,
staticDir: path.resolve(process.cwd(), 'test/uploads/optional'),
staticURL: '/optional',
},
},
{
slug: 'required-file',
fields: [],
upload: {
staticURL: '/required',
staticDir: path.resolve(process.cwd(), 'test/uploads/required'),
filesRequiredOnCreate: true,
},

View File

@@ -114,7 +114,7 @@ describe('Collections - Uploads', () => {
// Check api response
expect(doc.mimeType).toEqual('image/png')
expect(sizes.maintainedAspectRatio.url).toContain('/media/image')
expect(sizes.maintainedAspectRatio.url).toContain('/api/media/file/image')
expect(sizes.maintainedAspectRatio.url).toContain('.png')
expect(sizes.maintainedAspectRatio.width).toEqual(1024)
expect(sizes.maintainedAspectRatio.height).toEqual(1024)