UNPKG

@nx/angular

Version:

The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: - Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Playwright and Cypre

53 lines (52 loc) 2.59 kB
"use strict"; // This is a temporary workaround to prevent cypress erroring // as Angular attempt to figure out how to fix HMR when styles.js // is attached to the index.html with type=module Object.defineProperty(exports, "__esModule", { value: true }); exports.addCypressOnErrorWorkaround = addCypressOnErrorWorkaround; const devkit_1 = require("@nx/devkit"); const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup"); function addCypressOnErrorWorkaround(tree, schema) { if (!schema.e2eProjectName) { return; } const e2eProjectName = schema.e2eProjectName; let e2eProject; try { e2eProject = (0, devkit_1.readProjectConfiguration)(tree, e2eProjectName); } catch { devkit_1.logger.warn((0, devkit_1.stripIndents) `Could not find an associated e2e project for ${schema.appName} with name ${e2eProjectName}. If there is an associated e2e project for this application, and it uses Cypress, you will need to add a workaround to allow Cypress to test correctly. An error will be thrown in the console when you serve the application, coming from styles.js. It is an error that can be safely ignored and will not reach production due to how production builds of Angular are created. You can find how to implement that workaround here: https://docs.cypress.io/api/events/catalog-of-events#Uncaught-Exceptions `); return; } if (e2eProject.targets?.e2e?.executor !== '@nx/cypress:cypress') { try { // don't ensure package is installed, if it's not installed, we don't need to add the workaround const { CYPRESS_CONFIG_FILE_NAME_PATTERN, } = require('@nx/cypress/src/utils/config'); if (!(0, devkit_1.glob)(tree, [`${e2eProject.root}/${CYPRESS_CONFIG_FILE_NAME_PATTERN}`]) .length) { // Not a cypress e2e project, skip return; } } catch { // assume cypress is not installed return; } } const commandToAdd = `Cypress.on('uncaught:exception', err => { if (err.message.includes(\`Cannot use 'import.meta' outside a module\`)) { return false; } return true; });`; const pathToCommandsFile = (0, devkit_1.joinPathFragments)((0, ts_solution_setup_1.getProjectSourceRoot)(e2eProject, tree), 'support/e2e.ts'); const commandsContent = tree.exists(pathToCommandsFile) ? tree.read(pathToCommandsFile, 'utf-8') : ''; tree.write(pathToCommandsFile, `${commandsContent}\n${commandToAdd}`); }