@o3r/testing
Version:
The module provides testing (e2e, unit test) utilities to help you build your own E2E pipeline integrating visual testing.
66 lines • 2.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.playwrightDependencies = void 0;
exports.updatePlaywright = updatePlaywright;
const path = require("node:path");
const core_1 = require("@angular-devkit/core");
const schematics_1 = require("@angular-devkit/schematics");
const schematics_2 = require("@o3r/schematics");
/**
* List of dependencies required by playwright
*/
exports.playwrightDependencies = [
'@playwright/test',
'@types/node',
'rimraf'
];
/**
* Add Playwright to Otter application
* @param options {@link RuleFactory.options}
*/
function updatePlaywright(options) {
return (tree, context) => {
const workingDirectory = (options?.projectName && (0, schematics_2.getWorkspaceConfig)(tree)?.projects[options.projectName]?.root) || '.';
// update gitignore
const gitignorePath = '.gitignore';
if (tree.exists(gitignorePath)) {
let gitignore = tree.readText(gitignorePath);
if (!gitignore.includes('dist*') && !gitignore.includes('dist-e2e-playwright') && !gitignore.includes('playwright-reports')) {
gitignore
+= `
# Playwright
dist-e2e-playwright
playwright-reports
test-results
`;
tree.overwrite(gitignorePath, gitignore);
}
}
// register scripts
const packageJsonPath = path.posix.join(workingDirectory, 'package.json');
if (tree.exists(packageJsonPath)) {
const packageJson = tree.readJson(packageJsonPath);
packageJson.scripts ||= {};
packageJson.scripts['test:playwright'] ||= 'playwright test --config=e2e-playwright/playwright-config.ts';
tree.overwrite(packageJsonPath, JSON.stringify(packageJson, null, 2));
}
// generate files
if (!tree.exists(path.posix.join(workingDirectory, 'e2e-playwright', 'playwright-config.ts'))) {
const startCommand = `${(0, schematics_2.getPackageManager)()} run start`;
const project = options?.projectName ? (0, schematics_2.getWorkspaceConfig)(tree)?.projects[options.projectName] : undefined;
const serverPort = project?.architect?.serve?.options?.port || '4200';
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./playwright/templates'), [
(0, schematics_1.template)({
...core_1.strings,
serverPort,
startCommand
}),
(0, schematics_1.renameTemplateFiles)(),
(0, schematics_1.move)(workingDirectory)
]);
return (0, schematics_1.mergeWith)(templateSource, schematics_1.MergeStrategy.Overwrite)(tree, context);
}
return tree;
};
}
//# sourceMappingURL=index.js.map