GithubHelp home page GithubHelp logo

isabella232 / instrument-cra Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cypress-io/instrument-cra

0.0 0.0 0.0 2.57 MB

Little module for CRA applications to instrument code without ejecting react-scripts

License: MIT License

JavaScript 79.71% CSS 7.07% HTML 12.89% Shell 0.32%

instrument-cra's Introduction

@cypress/instrument-cra renovate-app badge CircleCI

Little module for CRA applications to instrument code without ejecting react-scripts

Install and use

yarn add @cypress/instrument-cra

Then change your npm start script to require this module before starting the dev server

{
  "scripts": {
    "start": "react-scripts -r @cypress/instrument-cra start",
  }
}

This module assumes standard Create-React-App v3 JavaScript application with source files in the "src" folder.

When the app starts with yarn start, you should see the coverage information under window.__coverage__ information.

Coverage object

The instrumentation is done using Istanbul.js via babel-plugin-istanbul and is compatible with @cypress/code-coverage plugin.

Exclude files

If you want to exclude files from coverage, for example src/serviceWorker.js, add an object named nyc to package.json following the nyc CLI configuration.

{
  "nyc": {
    "exclude": "src/serviceWorker.js"
  }
}

Instrument a fork

To instrument a fork of react-scripts, provide the path to the new webpack.config.js in your package.json as cypressWebpackConfigPath, e.g.:

{
  "cypressWebpackConfigPath": "./node_modules/@my-org/my-react-scripts-fork/config/webpack.config.js"
}

Force instrumentation

Usually, the code is only instrumented in the development environment. If you want to force the instrumentation, set the environment variable

CYPRESS_INSTRUMENT_PRODUCTION=true

Debugging

Run with environment variable DEBUG=instrument-cra to see the verbose logs

Notes

If you try to start the application, and react-scripts shows an error There might be a problem with the project dependency tree., just create a local file .env with. The problem is due to several versions of babel-loader dependency between this plugin and your application.

SKIP_PREFLIGHT_CHECK=true

Examples

In this repository

External

License

MIT License, see LICENSE

instrument-cra's People

Contributors

bahmutov avatar bitjson avatar felixh10r avatar jennifer-shehane avatar renovate-bot avatar renovate[bot] 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.