项目作者: bahmutov

项目描述 :
An example of Create-React-App v3 using TypeScript with Cypress unit tests
高级语言: TypeScript
项目地址: git://github.com/bahmutov/try-cra-app-typescript.git
创建时间: 2020-04-03T13:27:28Z
项目社区:https://github.com/bahmutov/try-cra-app-typescript

开源协议:

下载


try-cra-app-typescript

ci status cypress version @cypress/react-4.16.4-brightgreen" alt="@cypress/react version"> check-code-coverage

This project was bootstrapped with Create React App using TypeScript template

  1. $ npx create-react-app try-cra-app-typescript --template typescript
  2. info Direct dependencies
  3. ├─ cra-template-typescript@1.0.3
  4. ├─ react-dom@16.13.1
  5. ├─ react-scripts@3.4.1
  6. └─ react@16.13.1

Then add Cypress and cypress-react-unit-test

  1. $ yarn add -D cypress cypress-react-unit-test
  2. info Direct dependencies
  3. ├─ cypress-react-unit-test@3.0.1
  4. └─ cypress@4.3.0

Create cypress.json and point at the unit testing settings: support and plugins to read the create-react-app webpack config and load tests from src folder.

Create src/App.cy-spec.tsx. Run using yarn cypress open and you should see the working component test.

Working unit test

The test vs the original React Testing Library test file (nothing like type clashes between Mocha and Jest assertions, right)

Code

Code coverage

The component tests collect code coverage automatically. You should see messages in the command log.

Code coverage messages

When running on CI, the collected coverage information is checked using check-code-coverage utility. If the code coverage is not being collected, run Cypress with environment variable to see logs:

  1. DEBUG=cypress-react-unit-test,find-webpack