cypress: Custom location of cypress.config.ts crash on spec update in component tests

Current behavior

The onSpecsChange handler in the CypressCTWebpackPlugin file calculates the location of the indexHtmlFile based on the project root, not the location of the cypress.config.ts file. If the config file is located at a location other than the project root, trying to update the spec file while it’s opened in the runner results in a crash with an error provided in the logs section below (rarely it doesn’t fail on the first attempt but then fails on the second one).

Desired behavior

The indexHtmlFile location is calculated based on the location of the cypress.config.ts file where it’s declared. not the project root which may be a completely different path

Test code to reproduce

I cannot provide our project code, however, you can scaffold any component testing structure where the config file is not located in the project root and try to update the spec that’s being run by the runner at the moment

For example, our structure is as follows

package.json,
package-lock.json
src,
test
  cypress
    specs
    cypress.config.ts
    support
      component-index.html
    ...otherFiles

and indexHtmlFile in the cypress.config.ts file is set to support/component-index.html

Cypress Version

12.9.0

Node version

v18.15.0

Operating System

macOS Ventura 13.3

Debug Logs

Error: ENOENT: no such file or directory, utime '/Users/{user}/work/{repo}/support/component-index.html'
    at utimesSync (node:fs:2061:3)
    at EventEmitter.CypressCTWebpackPlugin.onSpecsChange (/Users/{user}/Library/Caches/Cypress/12.9.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/webpack-dev-server/dist/CypressCTWebpackPlugin.js:70:13)
    at EventEmitter.emit (node:events:513:28)
    at EventEmitter.emit (node:domain:489:12)
    at EventEmitter. (/Users/{user}/Library/Caches/Cypress/12.9.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/dev-server.js:9:21)
    at EventEmitter.emit (node:events:513:28)
    at EventEmitter.emit (node:domain:489:12)
    at process. (/Users/{user}/Library/Caches/Cypress/12.9.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:33:22)
    at process.emit (node:events:513:28)
    at process.emit (node:domain:489:12)
    at process.emit.sharedData.processEmitHook.installedValue [as emit] (/Users/{user}/Library/Caches/Cypress/12.9.0/Cypress.app/Contents/Resources/app/node_modules/@cspotcode/source-map-support/source-map-support.js:745:40)
    at emit (node:internal/child_process:937:14)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

Other

This issue was actually already reported but discussion stopped: https://github.com/cypress-io/cypress/issues/24398#issuecomment-1450641033 I did some debugging and found the issue at the path /Users/{user}/Library/Caches/Cypress/12.9.0/Cypress.app/Contents/Resources/app/node_modules/@cypress/webpack-dev-server/dist/CypressCTWebpackPlugin.js line 70 where the project root (which is always the project root folder where package.json and package-lock.json are located) and the indexHtmlFile property in our case is indexHtmlFile: support/component-index.html are concatenated and the result is /Users/{user}/work/{repo-name}/support/component-index.html which doesn’t exist in our project structure image From what I gathered, changes done in this PR influence this

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 5
  • Comments: 20 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Next release this will be shipped! Finally.

https://github.com/cypress-io/cypress/blob/71c5b864ea84c73b561ffaa15eadb94cb7de6422/npm/webpack-dev-server/src/CypressCTWebpackPlugin.ts#L122

This is the problem. The obvious issue is how do we know where to look? I wonder if we can create a temporary file, include it in the webpack compilation, then just touch that.

Yep, thanks @nikolayeasygenerator, routing this to the CT team

Uh oh - I think you are right, the fix in https://github.com/cypress-io/cypress/pull/25861 (fixes one issue) introduced another. We should be able to calculate the component-index.html without relying on projectRoot in the way we do today. Great debugging.