我jest在 monorepo 中使用。我想在测试我的一些项目时生成 Cobertura 报告。
module.exports = {
preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel',
transform: {
'vee-validate/dist/rules': 'babel-jest',
'.*\\.(vue)$': 'vue-jest',
'^.+\\.(ts|tsx)$': 'ts-jest',
},
testMatch: [
'**/*.(spec|test).(js|jsx|ts|tsx)',
],
testEnvironmentOptions: {
// Allow test environment to fire onload event
// See https://github.com/jsdom/jsdom/issues/1816#issuecomment-355188615
resources: 'usable',
},
reporters: [
'default',
[
'jest-trx-results-processor',
{
outputFile: './coverage/test-results.trx',
defaultUserName: 'user name to use if automatic detection fails',
},
],
],
moduleFileExtensions: [
'js',
'ts',
'json',
'vue',
],
testURL: 'http://localhost/',
snapshotSerializers: [
'jest-serializer-vue',
],
runner: 'groups',
};
Run Code Online (Sandbox Code Playgroud)
const baseConfig = require('./jest.config.base')
module.exports = {
...baseConfig,
projects: [
'<rootDir>/apps/my-app',
'<rootDir>/apps/my-app-copy',
'<rootDir>/libs/my-lib',
],
coverageDirectory: '<rootDir>/coverage/',
};
Run Code Online (Sandbox Code Playgroud)
const baseConfig = require('../../jest.config.base');
const packageJson = require('./package.json');
module.exports = {
...baseConfig,
transformIgnorePatterns: [],
roots: [
'<rootDir>/src',
],
name: packageJson.name,
displayName: packageJson.name,
};
Run Code Online (Sandbox Code Playgroud)
为了节省空间,我没有粘贴其他 jest.config,但它们是相似的。
如果我运行jest --coverage --coverageReporters=cobertura,它将生成一份 Cobertura 报告,但我的所有项目都将被测试。
如果我运行jest --projects apps/my-app apps/my-app-copy --coverage --coverageReporters=cobertura,只会test-results.trx生成。
我如何才能只测试 3 个项目中的 2 个,并为这些项目生成一份 Cobertura 报告?
小智 4
我正在我们的 monorepo 中做类似的事情,我能够生成 cobertura 报告,jest-junit在根 jest.config 中安装和定义报告者,如下所示
coverageReporters: ['html', 'text', 'text-summary', 'cobertura'],
Run Code Online (Sandbox Code Playgroud)
然后我跑jest --coverage
| 归档时间: |
|
| 查看次数: |
5592 次 |
| 最近记录: |