babel-plugin-canyon
SourceA Babel plugin for detecting CI environment variables. Works with istanbuljs to complete code instrumentation.
Usage
Install:
npm install --save-dev babel-plugin-canyonAdd 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:
- Detect CI pipeline variables
- 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 Item | Description | Required | Default |
|---|---|---|---|
| dsn | Coverage reporting address, CI pipeline variable KEY is DSN | Yes (fill in CI variable configuration or manual explicit configuration as needed) | None |
| reporter | User token for distinguishing different users, CI pipeline variable KEY is REPORTER | Yes (fill in CI variable configuration or manual explicit configuration as needed) | None |
| projectID | Repository ID | Generally no manual configuration needed (auto-detect CI Provider) | None |
| sha | Git Commit SHA | Generally no manual configuration needed (auto-detect CI Provider) | None |
| branch | Git repository branch | Generally no manual configuration needed (auto-detect CI Provider) | None |
| reportID | Used to distinguish different test cases | Optional | None |
| compareTarget | Comparison target, used as baseline for current SHA, for calculating changed line coverage | Optional | None |
| keepMap | Keep coverage map, optional, default is true, when false, will generate .canyon_output file | Optional | true |
| instrumentCwd | Instrumentation working directory, may need manual configuration in multi-repo mode | Optional | process.cwd() |
| provider | Source code provider (optional), default is gitlab | Optional | gitlab |
| oneByOne | 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 | Optional | false |