Current behavior
Any relative request from inside a component test will include /__cypress/iframe and will therefore be mapped to /__cypress/src/index.html and forwarded to the ct-dev-server. A header is provided including the original request path, however it would be quite hacky to use this to parse the relative path, as it would need to be matched against the test-file it was last called with.
Desired behavior
Cypress should be able to distinguish between the initial request used to kickstart the test-runner that needs to be mapped to the index.html and subsequent relative requests, that need to be forwarded to the dev-server as relative requests.
i.e. a request to ./data/image.png in a test with absolute path c:/project/cypress/component/test.cy.jsx currently resolves to /__cypress/iframe/c:/project/cypress/component/data/image.png but should resolve to /__cypress/src/data/image.png
Test code to reproduce
it('image with relative path should load', () => {
cy.mount(<img src="./path/to/image.png" />)
cy.get('img').should('be.visible').then(($img) => {
expect($img[0].naturalWidth).to.be.greaterThan(0);
})
})
I have a failing testcase in my custom dev-server here:
https://github.com/fochlac/cypress-ct-custom-devserver/blob/main/cypress/component/Test.cy.tsx#L13-L27
However I have also reproduced the issue using the webpack dev server in an private repository. Since the offending code is in the iframe controller this should also affect the vite-devserver:
https://github.com/cypress-io/cypress/blob/7630caed820c685295ff2fb52c98455ab0cf7bf6/packages/server/lib/controllers/iframes.ts#L44C1-L62
A workaround would be to use the __cypress_spec_path -header and match it against subsequent requests to properly map relative requests to the output folder, but that is super hacky.
Cypress Version
12.x
Node version
16.16
Operating System
windows / unix
Debug Logs
GET /__cypress/iframes/C:/gitHub/cypress-ct-custom-devserver/cypress/component/Test.cy.tsx 304 2.459 ms -
GET /__cypress/iframes/C:/gitHub/cypress-ct-custom-devserver/cypress/component/data/image.jpg 304 2.484 ms
Other
No response
Current behavior
Any relative request from inside a component test will include
/__cypress/iframeand will therefore be mapped to/__cypress/src/index.htmland forwarded to the ct-dev-server. A header is provided including the original request path, however it would be quite hacky to use this to parse the relative path, as it would need to be matched against the test-file it was last called with.Desired behavior
Cypress should be able to distinguish between the initial request used to kickstart the test-runner that needs to be mapped to the index.html and subsequent relative requests, that need to be forwarded to the dev-server as relative requests.
i.e. a request to
./data/image.pngin a test with absolute pathc:/project/cypress/component/test.cy.jsxcurrently resolves to/__cypress/iframe/c:/project/cypress/component/data/image.pngbut should resolve to/__cypress/src/data/image.pngTest code to reproduce
I have a failing testcase in my custom dev-server here:
https://github.com/fochlac/cypress-ct-custom-devserver/blob/main/cypress/component/Test.cy.tsx#L13-L27
However I have also reproduced the issue using the webpack dev server in an private repository. Since the offending code is in the iframe controller this should also affect the vite-devserver:
https://github.com/cypress-io/cypress/blob/7630caed820c685295ff2fb52c98455ab0cf7bf6/packages/server/lib/controllers/iframes.ts#L44C1-L62
A workaround would be to use the
__cypress_spec_path-header and match it against subsequent requests to properly map relative requests to the output folder, but that is super hacky.Cypress Version
12.x
Node version
16.16
Operating System
windows / unix
Debug Logs
Other
No response