bahmutov / cypress-esbuild-preprocessor

Bundle Cypress specs using esbuild
MIT License
72 stars 11 forks source link

Invalid path when loading bundled spec #280

Open eplatek-safyr opened 1 year ago

eplatek-safyr commented 1 year ago

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

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

{
  "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

{
  "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"
  }
}
vrknetha commented 1 year ago

Just delete all node modules and package.lock.json once and run. It worked for me

trungly commented 9 months ago

I have this same problem, and deleting node_modules and package-lock.json did not resolve it. @eplatek-safyr, were you ever able to resolve this?