chore: returns runE2E

This commit is contained in:
James
2024-04-01 15:55:38 -04:00
parent b9868cc709
commit adec044e02
2 changed files with 173 additions and 22 deletions

100
test/runE2E.ts Normal file
View File

@@ -0,0 +1,100 @@
import glob from 'glob'
import minimist from 'minimist'
import path from 'path'
import shelljs from 'shelljs'
import slash from 'slash'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(__filename)
shelljs.env.DISABLE_LOGGING = 'true'
const playwrightBin = path.resolve(dirname, '../node_modules/.bin/playwright')
const testRunCodes: { code: number; suiteName: string }[] = []
const { _: args, bail, part } = minimist(process.argv.slice(2))
const suiteName = args[0]
// Run all
if (!suiteName) {
let files = glob.sync(`${path.resolve(dirname).replace(/\\/g, '/')}/**/*e2e.spec.ts`)
const totalFiles = files.length
if (part) {
if (!part.includes('/')) {
throw new Error('part must be in the format of "1/2"')
}
const [partToRun, totalParts] = part.split('/').map((n) => parseInt(n))
if (partToRun > totalParts) {
throw new Error('part cannot be greater than totalParts')
}
const partSize = Math.ceil(files.length / totalParts)
const start = (partToRun - 1) * partSize
const end = start + partSize
files = files.slice(start, end)
}
if (files.length !== totalFiles) {
console.log(`\n\nExecuting part ${part}: ${files.length} of ${totalFiles} E2E tests...\n\n`)
} else {
console.log(`\n\nExecuting all ${files.length} E2E tests...\n\n`)
}
console.log(`${files.join('\n')}\n`)
files.forEach((file) => {
clearWebpackCache()
executePlaywright(file, bail)
})
} else {
// Run specific suite
clearWebpackCache()
let suitePath: string
if (suiteName.includes('/')) {
// Used for fields/lexical.e2e.spec.ts which is run from CI as fields/lexical
const suiteNameSplit = suiteName.split('/')
suitePath = path.resolve(dirname, suiteNameSplit[0], suiteNameSplit[1] + '.e2e.spec.ts')
} else {
suitePath = path.resolve(dirname, suiteName, 'e2e.spec.ts')
}
executePlaywright(suitePath)
}
console.log('\nRESULTS:')
testRunCodes.forEach((tr) => {
console.log(`\tSuite: ${tr.suiteName}, Success: ${tr.code === 0}`)
})
console.log('\n')
if (testRunCodes.some((tr) => tr.code > 0)) process.exit(1)
function executePlaywright(suitePath: string, bail = false) {
console.log(`Executing ${suitePath}...`)
const playwrightCfg = path.resolve(
dirname,
`${bail ? 'playwright.bail.config.ts' : 'playwright.config.ts'}`,
)
const cmd = slash(`${playwrightBin} test ${suitePath} -c ${playwrightCfg}`)
console.log('\n', cmd)
const { stdout, code } = shelljs.exec(cmd)
const suite = path.basename(path.dirname(suitePath))
const results = { suiteName: suite, code }
if (code) {
if (bail) {
console.error(`TEST FAILURE DURING ${suite} suite.`)
process.exit(1)
}
}
testRunCodes.push(results)
return stdout
}
function clearWebpackCache() {
const webpackCachePath = path.resolve(dirname, '../node_modules/.cache/webpack')
shelljs.rm('-rf', webpackCachePath)
}

View File

@@ -11,7 +11,11 @@
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"jsx": "preserve",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"noEmit": true,
"outDir": "./dist",
"resolveJsonModule": true,
@@ -19,7 +23,11 @@
"skipLibCheck": true,
"sourceMap": true,
"strict": false,
"types": ["jest", "node", "@types/jest"],
"types": [
"jest",
"node",
"@types/jest"
],
"incremental": true,
"isolatedModules": true,
"plugins": [
@@ -28,26 +36,65 @@
}
],
"paths": {
"@payload-config": ["./test/_community/config.ts"],
"@payloadcms/live-preview": ["./packages/live-preview/src"],
"@payloadcms/live-preview-react": ["./packages/live-preview-react/src/index.ts"],
"@payloadcms/ui/assets": ["./packages/ui/src/assets/index.ts"],
"@payloadcms/ui/elements/*": ["./packages/ui/src/elements/*/index.tsx"],
"@payloadcms/ui/fields/*": ["./packages/ui/src/fields/*/index.tsx"],
"@payloadcms/ui/forms/*": ["./packages/ui/src/forms/*/index.tsx"],
"@payloadcms/ui/graphics/*": ["./packages/ui/src/graphics/*/index.tsx"],
"@payloadcms/ui/hooks/*": ["./packages/ui/src/hooks/*.ts"],
"@payloadcms/ui/icons/*": ["./packages/ui/src/icons/*/index.tsx"],
"@payloadcms/ui/providers/*": ["./packages/ui/src/providers/*/index.tsx"],
"@payloadcms/ui/templates/*": ["./packages/ui/src/templates/*/index.tsx"],
"@payloadcms/ui/utilities/*": ["./packages/ui/src/utilities/*.ts"],
"@payloadcms/ui/scss": ["./packages/ui/src/scss.scss"],
"@payloadcms/ui/scss/app.scss": ["./packages/ui/src/scss/app.scss"],
"@payloadcms/next/*": ["./packages/next/src/*"],
"@payloadcms/next": ["./packages/next/src/exports/*"]
"@payload-config": [
"./test/access-control/config.ts"
],
"@payloadcms/live-preview": [
"./packages/live-preview/src"
],
"@payloadcms/live-preview-react": [
"./packages/live-preview-react/src/index.ts"
],
"@payloadcms/ui/assets": [
"./packages/ui/src/assets/index.ts"
],
"@payloadcms/ui/elements/*": [
"./packages/ui/src/elements/*/index.tsx"
],
"@payloadcms/ui/fields/*": [
"./packages/ui/src/fields/*/index.tsx"
],
"@payloadcms/ui/forms/*": [
"./packages/ui/src/forms/*/index.tsx"
],
"@payloadcms/ui/graphics/*": [
"./packages/ui/src/graphics/*/index.tsx"
],
"@payloadcms/ui/hooks/*": [
"./packages/ui/src/hooks/*.ts"
],
"@payloadcms/ui/icons/*": [
"./packages/ui/src/icons/*/index.tsx"
],
"@payloadcms/ui/providers/*": [
"./packages/ui/src/providers/*/index.tsx"
],
"@payloadcms/ui/templates/*": [
"./packages/ui/src/templates/*/index.tsx"
],
"@payloadcms/ui/utilities/*": [
"./packages/ui/src/utilities/*.ts"
],
"@payloadcms/ui/scss": [
"./packages/ui/src/scss.scss"
],
"@payloadcms/ui/scss/app.scss": [
"./packages/ui/src/scss/app.scss"
],
"@payloadcms/next/*": [
"./packages/next/src/*"
],
"@payloadcms/next": [
"./packages/next/src/exports/*"
]
}
},
"exclude": ["dist", "build", "temp", "node_modules"],
"exclude": [
"dist",
"build",
"temp",
"node_modules"
],
"composite": true,
"references": [
{
@@ -108,5 +155,9 @@
"path": "./packages/ui"
}
],
"include": ["next-env.d.ts", ".next/types/**/*.ts", "scripts/**/*.ts"]
}
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"scripts/**/*.ts"
]
}