Files
payload/test/helpers/getNextRootDir.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

58 lines
1.2 KiB
TypeScript

import fs from 'fs'
import path, { resolve } from 'path'
import { fileURLToPath } from 'url'
import { adminRoute as rootAdminRoute } from '../admin-root/shared.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
/**
* The root directory for e2e tests is either the monorepo root (normal e2e) or the test directory (test e2e).
*/
export function getNextRootDir(testSuite?: string) {
let adminRoute = '/admin'
/*
* Handle test suites that have their own app directory
*/
if (testSuite) {
const testSuiteDir = resolve(dirname, `../${testSuite}`)
let hasNextConfig = false
try {
fs.accessSync(`${testSuiteDir}/next.config.mjs`, fs.constants.F_OK)
hasNextConfig = true
} catch (err) {
// Swallow err - no config found
}
if (testSuite === 'admin-root') {
adminRoute = rootAdminRoute
}
if (hasNextConfig) {
return {
rootDir: testSuiteDir,
adminRoute,
}
}
}
/*
* Handle normal cases
*/
if (process.env.PAYLOAD_TEST_PROD === 'true') {
return {
rootDir: path.resolve(dirname, '..'),
adminRoute,
}
}
return {
rootDir: path.resolve(dirname, '..', '..'),
adminRoute,
}
}