chore: fix live-preview tests against prod (#9122)

Live preview e2e tests had no CSS when tested against prod.

For all our other tests, we have a separate test/app directory that
imports CSS. Otherwise, the root-level /app directory is used.

For live-preview, we currently always run against test/live-preview/app,
that has no CSS import.

This PR adds a new test/live-preview/prod/app directory that imports CSS
and is used when we run tests against prod.

In order for this to work, I had to make import map generation smarter
This commit is contained in:
Alessio Gravili
2024-11-11 19:28:55 -07:00
committed by GitHub
parent d8391389ab
commit 9c559d7304
99 changed files with 3873 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ const [testConfigDir] = process.argv.slice(2)
import type { SanitizedConfig } from 'payload'
import fs from 'fs'
import { generateImportMap } from 'payload'
import { fileURLToPath } from 'url'
@@ -21,11 +22,24 @@ async function run() {
const config: SanitizedConfig = await (await import(pathWithConfig)).default
process.env.ROOT_DIR =
testConfigDir === 'live-preview' || testConfigDir === 'admin-root'
? testDir
: path.resolve(dirname, '..')
let rootDir = ''
if (testConfigDir === 'live-preview' || testConfigDir === 'admin-root') {
rootDir = testDir
if (process.env.PAYLOAD_TEST_PROD === 'true') {
// If in prod mode, there may be a testSuite/prod folder. If so, use that as the rootDir
const prodDir = path.resolve(testDir, 'prod')
try {
fs.accessSync(prodDir, fs.constants.F_OK)
rootDir = prodDir
} catch (err) {
// Swallow err - no prod folder
}
}
} else {
rootDir = path.resolve(dirname, '..')
}
process.env.ROOT_DIR = rootDir
await generateImportMap(config, { log: true, force: true })
}
}