Files
payload/test/helpers/initPayloadInt.ts
Alessio Gravili ebd43c7763 feat: pre-compile ui and richtext-lexical with react compiler (#7688)
This noticeably improves performance in the admin panel, for example
when there are multiple richtext editors on one page (& likely
performance in other areas too, though I mainly tested rich text).

The babel plugin currently only optimizes files with a 'use client'
directive at the top - thus we have to make sure to add use client
wherever possible, even if it's imported by a parent client component.

There's one single component that broke when it was compiled using the
React compiler (it stopped being reactive and failed one of our admin
e2e tests):
150808f608
opting out of it completely fixed that issue

Fixes https://github.com/payloadcms/payload/issues/7366
2024-08-19 17:31:36 -04:00

30 lines
1.2 KiB
TypeScript

import type { Payload, SanitizedConfig } from 'payload'
import { getPayloadHMR } from '@payloadcms/next/utilities'
import path from 'path'
import { runInit } from '../runInit.js'
import { NextRESTClient } from './NextRESTClient.js'
/**
* Initialize Payload configured for integration tests
*/
export async function initPayloadInt(
dirname: string,
testSuiteNameOverride?: string,
): Promise<{ config: SanitizedConfig; payload: Payload; restClient: NextRESTClient }> {
const testSuiteName = testSuiteNameOverride ?? path.basename(dirname)
await runInit(testSuiteName, false, true)
console.log('importing config', path.resolve(dirname, 'config.ts'))
const { default: config } = await import(path.resolve(dirname, 'config.ts'))
console.log('starting payload')
// need to use getPayloadHMR and not getPayload, as getPayloadHMR will be used in next handlers. If we use getPayload
// here, payload would be cached somewhere else
const payload = await getPayloadHMR({ config })
console.log('initializing rest client')
const restClient = new NextRESTClient(payload.config)
console.log('initPayloadInt done')
return { config: payload.config, payload, restClient }
}