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

Install:

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 istanbul instrumentation output from the previous step and save to local (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, CI pipeline variable KEY is DSN reporter: "your_token", // User token for distinguishing different users, CI pipeline variable KEY is REPORTER // #endregion // #region == Step 2: CI Provider auto-detection, generally no manual configuration needed, see Support Provider documentation for details projectID: "230614", // Repository ID sha: "xxxxxxxxx", // Git Commit SHA branch: "master", // Git repository branch // #endregion // #region == Step 3: Additional coverage feature configuration (optional) reportID: "case_id", // Used to distinguish different test cases compareTarget: "develop", // Comparison target, used as baseline for current SHA, for calculating changed line coverage // #endregion // #region == Step 4: Separate hit and map data (optional) keepMap: true, // Keep coverage map, optional, default is true, when false, will generate .canyon_output file!!! // #endregion // #region == Step 5: Other configuration (optional) instrumentCwd: "/path/to", // Instrumentation working directory, may need manual configuration in multi-repo mode provider: "gitlab", // Source code provider (optional), default is gitlab oneByOne: false, // Configure proxy server, optional, default is false. When true, will report initial coverage data for each file one by one during compilation. Can also be proxy server configuration. // #endregion }, ], ], };
Configuration ItemDescriptionRequiredDefault
dsnCoverage reporting address, CI pipeline variable KEY is DSNYes (fill in CI variable configuration or manual explicit configuration as needed)None
reporterUser token for distinguishing different users, CI pipeline variable KEY is REPORTERYes (fill in CI variable configuration or manual explicit configuration as needed)None
projectIDRepository IDGenerally no manual configuration needed (auto-detect CI Provider)None
shaGit Commit SHAGenerally no manual configuration needed (auto-detect CI Provider)None
branchGit repository branchGenerally no manual configuration needed (auto-detect CI Provider)None
reportIDUsed to distinguish different test casesOptionalNone
compareTargetComparison target, used as baseline for current SHA, for calculating changed line coverageOptionalNone
keepMapKeep coverage map, optional, default is true, when false, will generate .canyon_output fileOptionaltrue
instrumentCwdInstrumentation working directory, may need manual configuration in multi-repo modeOptionalprocess.cwd()
providerSource code provider (optional), default is gitlabOptionalgitlab
oneByOneConfigure proxy server, optional, default is false. When true, will report initial coverage data for each file one by one during compilation. Can also be proxy server configurationOptionalfalse