chore: hoists tests out of payload package

This commit is contained in:
James
2023-09-01 14:45:41 -04:00
parent 893ca87225
commit 0f3b364e46
215 changed files with 254 additions and 257 deletions

36
test/generateTypes.ts Normal file
View File

@@ -0,0 +1,36 @@
import fs from 'fs'
import path from 'path'
import { generateTypes } from '../packages/payload/src/bin/generateTypes'
const [testConfigDir] = process.argv.slice(2)
let testDir
if (testConfigDir) {
testDir = path.resolve(__dirname, testConfigDir)
setPaths(testDir)
generateTypes()
} else {
// Generate types for entire directory
testDir = __dirname
fs.readdirSync(__dirname, { withFileTypes: true })
.filter((f) => f.isDirectory())
.forEach((dir) => {
const suiteDir = path.resolve(testDir, dir.name)
const configFound = setPaths(suiteDir)
if (configFound) generateTypes()
})
}
// Set config path and TS output path using test dir
function setPaths(dir) {
const configPath = path.resolve(dir, 'config.ts')
const outputPath = path.resolve(dir, 'payload-types.ts')
if (fs.existsSync(configPath)) {
process.env.PAYLOAD_CONFIG_PATH = configPath
process.env.PAYLOAD_TS_OUTPUT_PATH = outputPath
return true
}
return false
}