DocumentationEcosystemPluginsBabel Plugin Canyon

babel-plugin-canyon

A Babel plugin used to detect CI environment variables. It works with istanbuljs to complete code instrumentation.

Usage

Installation:

npm install --save-dev babel-plugin-canyon

Add these configurations in babel.config.js:

module.exports = {
  plugins:
    process.env.CI_COMMIT_REF_NAME === 'test-coverage'? ['istanbul', 'canyon'] : []
}

It will do two things:

  1. Detect CI pipeline variables.
  2. Check the instrumentation products generated by istanbul in the previous step and save them locally (when keepMap is false).

Configuration

babel.config.js

module.exports = {
  plugins: [
    'istanbul',
    [
      'canyon',
      {
        // #region == Step 1: CI variable configuration or manual explicit configuration
        dsn: 'http://yourdomain.com/coverage/client', // The coverage reporting address. The key for detecting CI pipeline variables is DSN.
        reporter: 'your_token', // User token, used to distinguish different users. The key for detecting CI pipeline variables is REPORTER.
        // #endregion
        // #region == Step 2: CI Provider auto-detection, generally doesn't need manual configuration. For details, please refer to the Support Provider documentation.
        projectID: '230614', // Repository ID
        sha: 'xxxxxxxxx', // Git Commit SHA
        branch: 'master', // Git repository branch
        // #endregion
        // #region == Step 3: Additional configuration for coverage (optional)
        reportID: 'case_id', // Used to distinguish different test cases
        compareTarget: 'develop', // The comparison target, used as the baseline of the current SHA, for calculating the coverage of changed lines.
        // #endregion
        // #region == Step 4: Separation of hit and map data (optional)
        keepMap: true, // Keep the coverage map. Optional, the default value is `true`. When it's `false`, a `.canyon_output` file will be generated!!!
        // #endregion
        // #region == Step 5: Other configurations (optional)
        instrumentCwd: '/path/to', // The working directory for instrumentation. It may need to be manually configured in multi-repository mode.
        provider: 'gitlab', // The source code provider (optional), the default is `gitlab`.
        oneByOne: false, // Configure the proxy server. Optional, the default is `false`. When it's `true`, the initial coverage data of each file will be reported one by one during compilation. It can also be the proxy server configuration.
        // #endregion
      }
    ]
  ]
}
Configuration ItemDescriptionWhether RequiredDefault Value
dsnThe coverage reporting address. The key for detecting CI pipeline variables is DSN.Yes (depending on whether to fill in during CI variable configuration or manual explicit configuration)None
reporterUser token, used to distinguish different users. The key for detecting CI pipeline variables is REPORTER.Yes (depending on whether to fill in during CI variable configuration or manual explicit configuration)None
projectIDRepository IDGenerally doesn’t need manual configuration (auto-detected by CI Provider)None
shaGit Commit SHAGenerally doesn’t need manual configuration (auto-detected by CI Provider)None
branchGit repository branchGenerally doesn’t need manual configuration (auto-detected by CI Provider)None
reportIDUsed to distinguish different test casesOptionalNone
compareTargetThe comparison target, used as the baseline of the current SHA, for calculating the coverage of changed lines.OptionalNone
keepMapKeep the coverage map. Optional, the default value is true. When it’s false, a .canyon_output file will be generated.Optionaltrue
instrumentCwdThe working directory for instrumentation. It may need to be manually configured in multi-repository mode.Optionalprocess.cwd()
providerThe source code provider (optional), the default is gitlab.Optionalgitlab
oneByOneConfigure the proxy server. Optional, the default is false. When it’s true, the initial coverage data of each file will be reported one by one during compilation. It can also be the proxy server configuration.Optionalfalse