fix(testing): omit indexHtmlFile option for cy >12.17.0 for ng ct (#18839)
This commit is contained in:
parent
86c21c6064
commit
829076d0e7
@ -104,15 +104,17 @@ ${e.stack ? e.stack : e}`
|
|||||||
...nxBaseCypressPreset(pathToConfig, { testingType: 'component' }),
|
...nxBaseCypressPreset(pathToConfig, { testingType: 'component' }),
|
||||||
// NOTE: cannot use a glob pattern since it will break cypress generated tsconfig.
|
// NOTE: cannot use a glob pattern since it will break cypress generated tsconfig.
|
||||||
specPattern: ['src/**/*.cy.ts', 'src/**/*.cy.js'],
|
specPattern: ['src/**/*.cy.ts', 'src/**/*.cy.js'],
|
||||||
// cypress defaults to a relative path from the workspaceRoot instead of projectRoot
|
// Cy v12.17.0+ does not work with aboslute paths for index file
|
||||||
// set as absolute path in case this changes internally to cypress, this path isn't OS dependent
|
// but does with relative pathing, since relative path is the default location, we can omit it
|
||||||
indexHtmlFile: joinPathFragments(
|
indexHtmlFile: requiresAbsolutePath()
|
||||||
ctContext.root,
|
? joinPathFragments(
|
||||||
ctProjectConfig.root,
|
ctContext.root,
|
||||||
'cypress',
|
ctProjectConfig.root,
|
||||||
'support',
|
'cypress',
|
||||||
'component-index.html'
|
'support',
|
||||||
),
|
'component-index.html'
|
||||||
|
)
|
||||||
|
: undefined,
|
||||||
devServer: {
|
devServer: {
|
||||||
// cypress uses string union type,
|
// cypress uses string union type,
|
||||||
// need to use const to prevent typing to string
|
// need to use const to prevent typing to string
|
||||||
@ -376,9 +378,7 @@ function isOffsetNeeded(
|
|||||||
ctProjectConfig: ProjectConfiguration
|
ctProjectConfig: ProjectConfiguration
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const { version = null } = require('cypress/package.json');
|
const supportsWorkspaceRoot = isCyVersionGreaterThanOrEqual('12.9.0');
|
||||||
|
|
||||||
const supportsWorkspaceRoot = !!version && gte(version, '12.9.0');
|
|
||||||
|
|
||||||
// if using cypress <v12.9.0 then we require the offset
|
// if using cypress <v12.9.0 then we require the offset
|
||||||
if (!supportsWorkspaceRoot) {
|
if (!supportsWorkspaceRoot) {
|
||||||
@ -413,3 +413,34 @@ function isOffsetNeeded(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if the cypress version is able to understand absolute paths to the indexHtmlFile option
|
||||||
|
* this is required for nx to work with cypress <v12.17.0 since the relative pathing is causes issues
|
||||||
|
* with invalid pathing.
|
||||||
|
* v12.17.0+ works with relative pathing
|
||||||
|
*
|
||||||
|
* if there is an error thrown then we assume it is an older version of cypress and use the absolute path
|
||||||
|
* as that was supported for longer.
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
function requiresAbsolutePath() {
|
||||||
|
try {
|
||||||
|
return !isCyVersionGreaterThanOrEqual('12.17.0');
|
||||||
|
} catch (e) {
|
||||||
|
if (process.env.NX_VERBOSE_LOGGING === 'true') {
|
||||||
|
logger.error(e);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the install cypress version is greater than or equal to the provided version.
|
||||||
|
* Does not catch errors as any custom logic for error handling is required on consumer side.
|
||||||
|
* */
|
||||||
|
function isCyVersionGreaterThanOrEqual(version: string) {
|
||||||
|
const { version: cyVersion = null } = require('cypress/package.json');
|
||||||
|
|
||||||
|
return !!cyVersion && gte(cyVersion, version);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user