Giter Site home page Giter Site logo

typescript-jest-cypress-together-typing-issue-demo's Introduction

TypeScript Jest Cypress Together Typing Issue Demo

由于jest和cypress都有global的expect,所以当一个项目中同时存在jest与cypress时, 哪怕它们分别在自己的目录,也会存在expect冲突的问题,即总是在某一方测里的expect类型不对。

由于typescript在编译时期对于typing的定位和选择很难调试,所以这个问题花费了我很多时间, 基本上靠各种示例调整各种参数。最后在这个示例的帮助下,终于成功:

https://github.com/cypress-io/cypress-and-jest-typescript-example

解决方法:

  1. 在根目录下的tsconfig.json,主要设置的是jest需要的类型,所以其中有"types": ["jest"]
  2. 根目录下tsconfig.json中的"include": ["src/**/*"]是为了让tsc --noEmit通过,否则typescript会同时编译cypress测试,会再次遇到cypress问题
  3. cypress目录下的tsconfig.json需要重新指定include的文件
  4. "types": ["cypress"]似乎可要可不要
  5. cypress/plugins/index.js中使用的@cypress/webpack-preprocessor对于这个问题无影响

注意:

  1. cypress中不能import 'cypress'(我曾尝试使用该方法来解决typing的问题),因为会导入一些额外的东西,导致cypress测试报错:
    Error: Can't resolve 'child_process' in ...
    
npm install
npm run test:open

npm run test:run

typescript-jest-cypress-together-typing-issue-demo's People

Contributors

freewind avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.