Coder Social home page Coder Social logo

cypress-and-jest-typescript-example's Introduction

cypress-and-jest-typescript-example renovate-app badge CircleCI

Example using Jest and Cypress with TypeScript in a single repo

If you are using Jest and Cypress types in the same project, they might conflict because both test runners use globals like expect. This project shows how to isolate Cypress TypeScript definitions from Jest TS definitions in the same project.

See the root level tsconfig.json and jest.config.js. The Cypress types are isolated from the root in the file cypress/tsconfig.json. The root tsconfig explicitly only includes libs with Jest globals (without Cypress)

Linting

While writing the production code, we want to limit ourselves to the src TS files without including the spec files. While linting, we want to lint all files. Thus we create a separate tsconfig.lint.json file that includes all src files, but sets noEmit: true compiler option. The command npm run lint thus lints src folder, without Cypress files.

To lint Cypress specs, we have a separate lint command that points at cypress/tsconfig.json file.

{
  "scripts": {
    "build": "tsc",
    "lint": "tsc --project tsconfig.lint.json",
    "lint:cypress": "tsc --project cypress/tsconfig.json"
  }
}

Additional information

See the excellent advice on setting TypeScript for Jest and Cypress in TypeScript Deep Dive e-book by Basarat Syed

Questions or problems

If you hit a problem using Jest and Cypress in the same project, please open an issue in this repository. Include a fork of this repository that shows the problem.

CircleCI workflow

The file .circleci/config.yml shows how to run Cypress and Jest tests using Cypress CircleCI Orb

GitHub Actions workflow

This repo shows how to install dependencies and how to run Jest test in separate jobs on GitHub Actions. See the workflow file .github/workflows/ci.yml for several different approaches

Tip: you can learn more about running Cypress tests on continuous integration services from Cypress CI guide and Cypress on CI workshop.

License

This project is licensed under the terms of the MIT license.

cypress-and-jest-typescript-example's People

Contributors

pinpointdev90 avatar

Watchers

 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.