From adec044e023051aed2484fa38b9a86d2d805eeca Mon Sep 17 00:00:00 2001 From: James Date: Mon, 1 Apr 2024 15:55:38 -0400 Subject: [PATCH] chore: returns runE2E --- test/runE2E.ts | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 95 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 173 insertions(+), 22 deletions(-) create mode 100644 test/runE2E.ts diff --git a/test/runE2E.ts b/test/runE2E.ts new file mode 100644 index 0000000000..81dba165e3 --- /dev/null +++ b/test/runE2E.ts @@ -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) +} diff --git a/tsconfig.json b/tsconfig.json index 7062457954..bf0b6a52a6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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" + ] +} \ No newline at end of file