bahmutov / bahmutov/cypress-esbuild-preprocessor
Invalid path when loading bundled spec
- Dominant language
- JavaScript
- Stars
- 83
- Forks
- 13
- Avg merge
- 12h 21m
- Merged PRs (30d)
- 2
Description
Hi,
When cypress is loaded and I try to open the spec in the app, I get the following error:
`Error: ENOENT: no such file or directory, stat '/home/elias/.config/Cypress/cy/production/projects/tests-535beb165404f40fd3d30b63481a8024/bundles/cypress/e2e/all.spec.ts'`
when I check the folder, the folder exists and the following file is found:
`Error: ENOENT: no such file or directory, stat '/home/elias/.config/Cypress/cy/production/projects/tests-535beb165404f40fd3d30b63481a8024/bundles/cypress/e2e/all.spec.ts.js'`
so the file exists, but with the `.ts.js` extension (not `.ts`)
How to solve this so cypress can resolve the file path correctly ?
Environment: ubuntu 22, node 18
`cypress.config.ts`
```typescript
import createBundler from "@bahmutov/cypress-esbuild-preprocessor"
import { defineConfig } from "cypress"
import plugins from "./cypress/plugins/index"
export default defineConfig({
projectId: "xxxxx",
component: {
devServer: {
framework: "react",
bundler: "vite",
},
},
defaultCommandTimeout: 10000,
requestTimeout: 10000,
pageLoadTimeout: 10000,
reporter: "mochawesome",
reporterOptions: {
reportDir: "cypress/results",
overwrite: false,
html: false,
json: true,
},
waitForAnimations: false,
numTestsKeptInMemory: 10,
videoUploadOnPasses: false,
videoCompression: 15,
e2e: {
async setupNodeEvents(on, config) {
on("file:preprocessor", createBundler())
const result = plugins(on, config) as Cypress.PluginConfigOptions
return {
...result,
excludeSpecPattern:
process.env.CI || config.isTextTerminal
? ["cypress/e2e/all.spec.ts"]
: [],
}
},
baseUrl: process.env.CI ? "http://localhost:2222" : "http://localhost:3000",
specPattern: "cypress/e2e/*.spec.ts",
},
})
```
`tsconfig.json`
```json
{
"compilerOptions": {
"target": "es2019",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"noUnusedLocals": true,
"allowUnusedLabels": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noFallthroughCasesInSwitch": true,
"types": ["node"],
"skipDefaultLibCheck": true,
"skipLibCheck": true
},
"include": ["e2e"],
"exclude": ["**/node_modules", "**/.*/"],
"references": [
{ "path": "../../packages/@some/types" }
]
}
```
`package.json`
```json
{
"name": "tests",
"version": "0.0.0",
"license": "UNLICENSED",
"private": true,
"scripts": {
"clean": "rimraf -rf .turbo ./dist tsconfig.tsbuildinfo",
"e2e-tests": "cypress open",
"e2e-run": "cypress run",
"report": "node -r esbuild-register scripts/cypress.ts",
"lint": "eslint \"./cypress/**/*.ts\" --quiet",
"format": "yarn lint --fix --quiet"
},
"dependencies": {
"@bahmutov/cypress-esbuild-preprocessor": "^2.2.0",
"@some/types": "*",
"expect": "^29.5.0",
"mocha": "^10.2.0"
},
"devDependencies": {
"@auth0/auth0-spa-js": "2.0.7",
"cypress": "^12.14.0",
"cypress-file-upload": "^5.0.8",
"eslint-config-lyra-presets": "*",
"eslint-plugin-no-autofix": "^1.2.3",
"eslint-plugin-no-only-tests": "^3.1.0",
"mochawesome": "7.1.3",
"mochawesome-merge": "4.3.0",
"mochawesome-report-generator": "6.2.0"
}
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with cypress.config.ts, especially the file:preprocessor handler, specPattern, and excludeSpecPattern, then compare them with the @bahmutov/cypress-esbuild-preprocessor dependency in package.json. Reproduce with Cypress open on Ubuntu and inspect why the bundled .ts.js path is later requested as .ts; done means the spec opens without an ENOENT error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cypress, javascript, node.js, typescript
- Domain
- testing, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100