UNPKG

@nx/cypress

Version:

The Nx Plugin for Cypress contains executors and generators allowing your workspace to use the powerful Cypress integration testing capabilities.

87 lines (86 loc) 3.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CY_FILE_MATCHER = void 0; exports.getTempTailwindPath = getTempTailwindPath; exports.isCtProjectUsingBuildProject = isCtProjectUsingBuildProject; exports.getProjectConfigByPath = getProjectConfigByPath; exports.createExecutorContext = createExecutorContext; const devkit_1 = require("@nx/devkit"); const path_1 = require("path"); const fs_1 = require("fs"); const find_project_for_path_1 = require("nx/src/project-graph/utils/find-project-for-path"); const project_graph_1 = require("nx/src/project-graph/project-graph"); const configuration_1 = require("nx/src/config/configuration"); exports.CY_FILE_MATCHER = new RegExp(/\.cy\.[tj]sx?$/); /** * return a path to a temp css file * temp file is scoped to the project root * i.e. <context.root>/tmp/<project-root>/ct-styles.css */ function getTempTailwindPath(context) { if (!context.projectName) { throw new Error('No project name found in context'); } const project = context?.projectGraph.nodes[context.projectName]; if (!project) { throw new Error(`No project found in project graph for ${context.projectName}`); } if (project?.data?.root) { return (0, path_1.join)(context.root, 'tmp', project.data.root, 'ct-styles.css'); } } /** * Checks if the childProjectName is a descendent of the parentProjectName * in the project graph **/ function isCtProjectUsingBuildProject(graph, parentProjectName, childProjectName, seen = new Set()) { if (seen.has(parentProjectName)) { return false; } seen.add(parentProjectName); const isProjectDirectDep = graph.dependencies[parentProjectName].some((p) => p.target === childProjectName); if (isProjectDirectDep) { return true; } const maybeIntermediateProjects = graph.dependencies[parentProjectName].filter((p) => !graph.externalNodes[p.target]); for (const maybeIntermediateProject of maybeIntermediateProjects) { if (isCtProjectUsingBuildProject(graph, maybeIntermediateProject.target, childProjectName, seen)) { return true; } } return false; } function getProjectConfigByPath(graph, configPath) { const configFileFromWorkspaceRoot = (0, path_1.relative)(devkit_1.workspaceRoot, configPath); const normalizedPathFromWorkspaceRoot = (0, devkit_1.normalizePath)((0, fs_1.lstatSync)(configPath).isFile() ? configFileFromWorkspaceRoot.replace((0, path_1.extname)(configPath), '') : configFileFromWorkspaceRoot); const projectRootMappings = (0, find_project_for_path_1.createProjectRootMappings)(graph.nodes); const componentTestingProjectName = (0, find_project_for_path_1.findProjectForPath)(normalizedPathFromWorkspaceRoot, projectRootMappings); if (!componentTestingProjectName || !graph.nodes[componentTestingProjectName]?.data) { throw new Error((0, devkit_1.stripIndents) `Unable to find the project configuration that includes ${normalizedPathFromWorkspaceRoot}. Found project name? ${componentTestingProjectName}. Graph has data? ${!!graph.nodes[componentTestingProjectName]?.data}`); } // make sure name is set since it can be undefined graph.nodes[componentTestingProjectName].data.name ??= componentTestingProjectName; return graph.nodes[componentTestingProjectName].data; } function createExecutorContext(graph, targets, projectName, targetName, configurationName) { const projectsConfigurations = (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(graph); const nxJsonConfiguration = (0, configuration_1.readNxJson)(); return { cwd: process.cwd(), projectGraph: graph, target: targets[targetName], targetName, configurationName, root: devkit_1.workspaceRoot, isVerbose: false, projectName, projectsConfigurations, nxJsonConfiguration, }; }