babel-plugin-canyon
A Babel plugin used to detect CI environment variables. It 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'] : []
}
It will do two things:
- Detect CI pipeline variables.
- Check the instrumentation products generated by istanbul in the previous step and save them locally (when
keepMap
isfalse
).
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', // The 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 auto-detection, generally doesn't need manual configuration. For details, please refer to the Support Provider documentation.
projectID: '230614', // Repository ID
sha: 'xxxxxxxxx', // Git Commit SHA
branch: 'master', // Git repository branch
// #endregion
// #region == Step 3: Additional configuration for coverage (optional)
reportID: 'case_id', // Used to distinguish different test cases
compareTarget: 'develop', // The comparison target, used as the baseline of the current SHA, for calculating the coverage of changed lines.
// #endregion
// #region == Step 4: Separation of hit and map data (optional)
keepMap: true, // Keep the coverage map. Optional, the default value is `true`. When it's `false`, a `.canyon_output` file will be generated!!!
// #endregion
// #region == Step 5: Other configurations (optional)
instrumentCwd: '/path/to', // The working directory for instrumentation. It may need to be manually configured in multi-repository mode.
provider: 'gitlab', // The source code provider (optional), the default is `gitlab`.
oneByOne: false, // Configure the proxy server. Optional, the default is `false`. When it's `true`, the initial coverage data of each file will be reported one by one during compilation. It can also be the proxy server configuration.
// #endregion
}
]
]
}
Configuration Item | Description | Whether Required | Default Value |
---|---|---|---|
dsn | The coverage reporting address. The key for detecting CI pipeline variables is DSN. | Yes (depending on whether to fill in during CI variable configuration or manual explicit configuration) | None |
reporter | User token, used to distinguish different users. The key for detecting CI pipeline variables is REPORTER. | Yes (depending on whether to fill in during CI variable configuration or manual explicit configuration) | None |
projectID | Repository ID | Generally doesn’t need manual configuration (auto-detected by CI Provider) | None |
sha | Git Commit SHA | Generally doesn’t need manual configuration (auto-detected by CI Provider) | None |
branch | Git repository branch | Generally doesn’t need manual configuration (auto-detected by CI Provider) | None |
reportID | Used to distinguish different test cases | Optional | None |
compareTarget | The comparison target, used as the baseline of the current SHA, for calculating the coverage of changed lines. | Optional | None |
keepMap | Keep the coverage map. Optional, the default value is true . When it’s false , a .canyon_output file will be generated. | Optional | true |
instrumentCwd | The working directory for instrumentation. It may need to be manually configured in multi-repository mode. | Optional | process.cwd() |
provider | The source code provider (optional), the default is gitlab . | Optional | gitlab |
oneByOne | Configure the proxy server. Optional, the default is false . When it’s true , the initial coverage data of each file will be reported one by one during compilation. It can also be the proxy server configuration. | Optional | false |