Files
payloadcms/test/runE2E.ts
Alberto Maghini a345ef0d31 feat: admin UI logout extensibility (#1274)
* added Logout documentation

* updated type and schema

* updated logout component, route and inactivityRoute references

* added custom Logout component into test admin instance

* fixed windows path management

* added dotenv usage

* added check on testSuiteDir and provided more meaningful error message

* fixed object destructure

* updated from logout.route to logoutRoute

* extracted getSanitizedLogoutRoutes method

* added unit tests

* updated references

* updated doc

* reviewed casing and added defaults

* updated usage

* restored workers previous value

* fixed config validation

* updated docs and schema

* updated reference to logoutRoute and inactivityRoute

* updated test ref

Co-authored-by: Alberto Maghini (MSC Technology Italia) <alberto.maghini@msc.com>
Co-authored-by: Alberto Maghini <alberto@newesis.com>
2022-11-14 14:55:31 -05:00

66 lines
1.9 KiB
TypeScript

/* eslint-disable import/no-extraneous-dependencies, no-console */
import path from 'path';
import shelljs from 'shelljs';
import glob from 'glob';
import slash from 'slash';
shelljs.env.DISABLE_LOGGING = 'true';
const playwrightBin = path.resolve(__dirname, '../node_modules/.bin/playwright');
const testRunCodes: { suiteName: string; code: number }[] = [];
const args = process.argv.slice(2);
const suiteName = args[0];
// Run all
if (!suiteName || args[0].startsWith('-')) {
const bail = args.includes('--bail');
const files = glob.sync(`${path.resolve(__dirname).replace(/\\/g, '/')}/**/*e2e.spec.ts`);
console.log(`\n\nExecuting all ${files.length} E2E tests...`);
files.forEach((file) => {
clearWebpackCache();
executePlaywright(file, bail);
});
} else {
// Run specific suite
clearWebpackCache();
const 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);
}