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 will do two things:

  1. Detect CI pipeline variables
  2. Check the previous istanbul instrumentation output and save it locally (when keepMap is false)

Configuration

babel.config.js

module.exports = { plugins: [ // #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 // #region == Step 2: CI Provider auto-detection, usually no manual configuration needed, see Support Provider documentation projectID: "230614", // Repository ID sha: "abc123", // Git Commit SHA branch: "master", // Git repository branch // #region == Step 3: Additional coverage configuration (optional) reportID: "case_id", // For distinguishing different test cases compareTarget: "develop", // Comparison target, used as baseline for current SHA, for calculating coverage of changed lines // #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!!! // #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, will report initial coverage data for each file during compilation. Can also be proxy server configuration. ] };
ConfigurationDescriptionRequiredDefault
dsnCoverage reporting address, CI pipeline variable key is DSNYes (configure in CI variables or manually)None
reporterUser token for distinguishing different users, CI pipeline variable key is REPORTERYes (configure in CI variables or manually)None
projectIDRepository IDUsually no manual configuration needed (auto-detect CI Provider)None
shaGit Commit SHAUsually no manual configuration needed (auto-detect CI Provider)None
branchGit repository branchUsually no manual configuration needed (auto-detect CI Provider)None
reportIDFor distinguishing different test casesOptionalNone
compareTargetComparison target, used as baseline for current SHA, for calculating coverage of changed linesOptionalNone
keepMapKeep coverage map, optional, default is true, when false, 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, will report initial coverage data for each file during compilation. Can also be proxy server configurationOptionalfalse