Skip to Content
DocumentationEcosystembabel-plugin-canyon

babel-plugin-canyon

Source

A Babel plugin for detecting CI environment variables. 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"] : [], // Note the plugin order, canyon plugin should be after istanbul plugin };

It does two things:

  1. Detect CI pipeline variables
  2. Check the previous step’s istanbul instrumentation product and save it 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", // 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 automatic detection, generally no manual configuration needed, please check the Support Provider documentation for details projectID: "230614", // Repository ID sha: "xxxxxxxxx", // Git Commit SHA branch: "master", // Git repository branch // #endregion // #region == Step 3: Coverage additional feature configuration (optional) reportID: "case_id", // Used to distinguish different test cases compareTarget: "develop", // Comparison target, used as the baseline for the current SHA, for calculating the coverage of changed lines // #endregion // #region == Step 4: hit and map data separation (optional) keepMap: true, // Keep coverage map, optional, default is true, when false, it will generate .canyon_output file!!! // #endregion // #region == Step 5: Other configurations (optional) instrumentCwd: "/path/to", // Instrumentation working directory, may need manual configuration in multi-repository mode provider: "gitlab", // Source code provider (optional), default is gitlab oneByOne: false, // Configure proxy server, optional, default is false. When true, it will report the initial coverage data of each file one by one during compilation. It can also be a proxy server configuration. // #endregion }, ], ], };
Configuration ItemDescriptionRequiredDefault Value
dsnCoverage reporting address, the KEY for detecting CI pipeline variables is DSNYes (fill in according to the situation in CI variable configuration or manual configuration)None
reporterUser token, used to distinguish different users, the KEY for detecting CI pipeline variables is REPORTERYes (fill in according to the situation in CI variable configuration or manual configuration)None
projectIDRepository IDGenerally no manual configuration needed (automatic detection of CI Provider)None
shaGit Commit SHAGenerally no manual configuration needed (automatic detection of CI Provider)None
branchGit repository branchGenerally no manual configuration needed (automatic detection of CI Provider)None
reportIDUsed to distinguish different test casesOptionalNone
compareTargetComparison target, used as the baseline for the current SHA, for calculating the coverage of changed linesOptionalNone
keepMapKeep coverage map, optional, default is true, when false, it will generate .canyon_output fileOptionaltrue
instrumentCwdInstrumentation working directory, may need manual configuration in multi-repository modeOptionalprocess.cwd()
providerSource code provider (optional), default is gitlabOptionalgitlab
oneByOneConfigure proxy server, optional, default is false. When true, it will report the initial coverage data of each file one by one during compilation. It can also be a proxy server configurationOptionalfalse