samedi 8 août 2020

typescript autocomplete for mocha and chai outside cypress folder

I'm trying to config cypress and typescript to allow run tests on the same folder of my project instead of the default integrations folder.

I made it works running the tests, but I just cannot find a way to allow the mocha and chai autocomplete work on the test file, it keep trying to get the default jest config from CRA.

I tried to remove jest ejecting the project but it don't work, the only thing I got was the describe, it and expect to be like any.

The stranger thing was that sometimes, I didn't know why, it gets the right config, after so much debugging I realize that if I change something inside /cypress/plugins or /cypress/support the autocomplete start to work, but it's lost when I restart vscode.

With that behavior I start to think that vscode initially don't get the tsconfig.json inside cypress folder. Since nothing makes reference to that file/folder it makes sense, make even more sense knowing that when I save something inside that two folders above the autocomplete start to work.

But I still don't know what to do to allow autocomplete without needing to change something inside /cypress every session. Does someone know how can I make this work?

I add that config on cypress.json

{
  "integrationFolder": "./src",
  "testFiles": [
    "**/*.spec.ts",
    "**/*.spec.tsx"
  ]
}

my root tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": false,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react",
    "baseUrl": "src"
  },
  "include": [
    "src"
  ],
  "exclude": [
    "**/*.spec.ts",
    "**/*.spec.tsx"
  ]
}

and the cypress tsconfig.json

{
  "extends: "../tsconfig.json",
  "compilerOptions": {
    "isolatedModules": false,
    "strict": true,
    "baseUrl": "../node_modules",
    "target": "es5",
    "lib": ["es5", "dom"],
    "types": ["cypress"],
    "noEmit": false
  },
  "include": [
    "../node_modules/cypress",
    "../src/**/*.spec.ts",
    "../src/**/*.spec.tsx"
  ],
  "exclude": []
}

Aucun commentaire:

Enregistrer un commentaire