babel-plugin-canyon
SourceA 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:
- Detect CI pipeline variables
- 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.
]
};
Configuration | Description | Required | Default |
---|---|---|---|
dsn | Coverage reporting address, CI pipeline variable key is DSN | Yes (configure in CI variables or manually) | None |
reporter | User token for distinguishing different users, CI pipeline variable key is REPORTER | Yes (configure in CI variables or manually) | None |
projectID | Repository ID | Usually no manual configuration needed (auto-detect CI Provider) | None |
sha | Git Commit SHA | Usually no manual configuration needed (auto-detect CI Provider) | None |
branch | Git repository branch | Usually no manual configuration needed (auto-detect CI Provider) | None |
reportID | For distinguishing different test cases | Optional | None |
compareTarget | Comparison target, used as baseline for current SHA, for calculating coverage of changed lines | 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-repository 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 during compilation. Can also be proxy server configuration | Optional | false |