From 6655b5a1afaa10d98348e7f854519a5713447032 Mon Sep 17 00:00:00 2001 From: Caleb Ukle Date: Fri, 25 Aug 2023 09:50:10 -0500 Subject: [PATCH] fix(testing): omit indexHtmlFile option for cy >12.17.0 cypress currently reappends the cwd to the absolute path resulting in invalid paths switch to use a relative path based from the cypress config location to the support file but since the file is in the default locaiton it can be omitted for later cypress verions --- packages/angular/plugins/component-testing.ts | 55 +++++++++++++++---- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/packages/angular/plugins/component-testing.ts b/packages/angular/plugins/component-testing.ts index d71d4f6200733..8b754d9a4da94 100644 --- a/packages/angular/plugins/component-testing.ts +++ b/packages/angular/plugins/component-testing.ts @@ -104,15 +104,17 @@ ${e.stack ? e.stack : e}` ...nxBaseCypressPreset(pathToConfig, { testingType: 'component' }), // NOTE: cannot use a glob pattern since it will break cypress generated tsconfig. specPattern: ['src/**/*.cy.ts', 'src/**/*.cy.js'], - // cypress defaults to a relative path from the workspaceRoot instead of projectRoot - // set as absolute path in case this changes internally to cypress, this path isn't OS dependent - indexHtmlFile: joinPathFragments( - ctContext.root, - ctProjectConfig.root, - 'cypress', - 'support', - 'component-index.html' - ), + // Cy v12.17.0+ does not work with aboslute paths for index file + // but does with relative pathing, since relative path is the default location, we can omit it + indexHtmlFile: requiresAbsolutePath() + ? joinPathFragments( + ctContext.root, + ctProjectConfig.root, + 'cypress', + 'support', + 'component-index.html' + ) + : undefined, devServer: { // cypress uses string union type, // need to use const to prevent typing to string @@ -376,9 +378,7 @@ function isOffsetNeeded( ctProjectConfig: ProjectConfiguration ) { try { - const { version = null } = require('cypress/package.json'); - - const supportsWorkspaceRoot = !!version && gte(version, '12.9.0'); + const supportsWorkspaceRoot = isCyVersionGreaterThanOrEqual('12.9.0'); // if using cypress