@toptal/davinci-monorepo 8.1.4-alpha-CRT-5891-create-coverage-command-5071adf7.9 → 8.1.4-alpha-CRT-5891-create-coverage-command-1b2c7953.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/coverage.md +2 -2
- package/package.json +3 -3
- package/src/commands/coverage-command/__snapshots__/create-generate-team-coverage-command.test.js.snap +74 -0
- package/src/commands/coverage-command/__snapshots__/create-group-coverage-by-codeowners-command.test.js.snap +47 -0
- package/src/commands/coverage-command/create-generate-team-coverage-command.js +21 -7
- package/src/commands/coverage-command/create-generate-team-coverage-command.test.js +25 -0
- package/src/commands/coverage-command/create-group-coverage-by-codeowners-command.js +10 -2
- package/src/commands/coverage-command/create-group-coverage-by-codeowners-command.test.js +25 -0
- package/src/commands/coverage-command/index.js +4 -8
package/docs/coverage.md
CHANGED
|
@@ -8,10 +8,10 @@ Streamline code coverage analysis and reporting by organizing coverage reports b
|
|
|
8
8
|
codeowners group-coverage-by-codeowners
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
#### `
|
|
11
|
+
#### `generate-team-coverage`
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
|
-
coverage
|
|
14
|
+
coverage generate-team-coverage [options]
|
|
15
15
|
|
|
16
16
|
Options:
|
|
17
17
|
-r, --repository <repository_name> specify repository name
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toptal/davinci-monorepo",
|
|
3
|
-
"version": "8.1.4-alpha-CRT-5891-create-coverage-command-
|
|
3
|
+
"version": "8.1.4-alpha-CRT-5891-create-coverage-command-1b2c7953.12+1b2c7953",
|
|
4
4
|
"description": "Monorepo utility tools",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@nodelib/fs.walk": "^1.2.6",
|
|
37
37
|
"@oclif/core": "^1.16.1",
|
|
38
|
-
"@toptal/davinci-cli-shared": "2.3.1-alpha-CRT-5891-create-coverage-command-
|
|
38
|
+
"@toptal/davinci-cli-shared": "2.3.1-alpha-CRT-5891-create-coverage-command-1b2c7953.44+1b2c7953",
|
|
39
39
|
"chalk": "^4.1.2",
|
|
40
40
|
"codeowners": "5.1.1",
|
|
41
41
|
"dependency-cruiser": "^12.5.0",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@jest/globals": "^29.4.2"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "1b2c79534c7559b73b39c067ab0480eadccf0ebc"
|
|
58
58
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`createGenerateTeamCoverageCommand has the correct command structure 1`] = `
|
|
4
|
+
"{
|
|
5
|
+
"_events": {},
|
|
6
|
+
"_eventsCount": 2,
|
|
7
|
+
"commands": [],
|
|
8
|
+
"options": [
|
|
9
|
+
{
|
|
10
|
+
"flags": "-r, --repository <repository_name>",
|
|
11
|
+
"description": "specify repository name",
|
|
12
|
+
"required": true,
|
|
13
|
+
"optional": false,
|
|
14
|
+
"variadic": false,
|
|
15
|
+
"mandatory": true,
|
|
16
|
+
"short": "-r",
|
|
17
|
+
"long": "--repository",
|
|
18
|
+
"negate": false,
|
|
19
|
+
"hidden": false,
|
|
20
|
+
"conflictsWith": []
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"flags": "-o, --output-file-name <output_file_name>",
|
|
24
|
+
"description": "specify output file name",
|
|
25
|
+
"required": true,
|
|
26
|
+
"optional": false,
|
|
27
|
+
"variadic": false,
|
|
28
|
+
"mandatory": true,
|
|
29
|
+
"short": "-o",
|
|
30
|
+
"long": "--output-file-name",
|
|
31
|
+
"negate": false,
|
|
32
|
+
"hidden": false,
|
|
33
|
+
"conflictsWith": []
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"parent": null,
|
|
37
|
+
"_allowUnknownOption": false,
|
|
38
|
+
"_allowExcessArguments": true,
|
|
39
|
+
"_args": [],
|
|
40
|
+
"args": [],
|
|
41
|
+
"rawArgs": [],
|
|
42
|
+
"processedArgs": [],
|
|
43
|
+
"_scriptPath": null,
|
|
44
|
+
"_name": "generate-team-coverage",
|
|
45
|
+
"_optionValues": {},
|
|
46
|
+
"_optionValueSources": {},
|
|
47
|
+
"_storeOptionsAsProperties": false,
|
|
48
|
+
"_executableHandler": false,
|
|
49
|
+
"_executableFile": null,
|
|
50
|
+
"_executableDir": null,
|
|
51
|
+
"_defaultCommandName": null,
|
|
52
|
+
"_exitCallback": null,
|
|
53
|
+
"_aliases": [],
|
|
54
|
+
"_combineFlagAndOptionalValue": true,
|
|
55
|
+
"_description": "Generates team-specific coverage reports by copying and processing coverage data from Jest and Cypress reports.\\nThe resulting coverage reports provide insights into the code coverage metrics for each team.",
|
|
56
|
+
"_summary": "",
|
|
57
|
+
"_enablePositionalOptions": false,
|
|
58
|
+
"_passThroughOptions": false,
|
|
59
|
+
"_lifeCycleHooks": {},
|
|
60
|
+
"_showHelpAfterError": false,
|
|
61
|
+
"_showSuggestionAfterError": true,
|
|
62
|
+
"_outputConfiguration": {},
|
|
63
|
+
"_hidden": false,
|
|
64
|
+
"_hasHelpOption": true,
|
|
65
|
+
"_helpFlags": "-h, --help",
|
|
66
|
+
"_helpDescription": "display help for command",
|
|
67
|
+
"_helpShortFlag": "-h",
|
|
68
|
+
"_helpLongFlag": "--help",
|
|
69
|
+
"_helpCommandName": "help",
|
|
70
|
+
"_helpCommandnameAndArgs": "help [command]",
|
|
71
|
+
"_helpCommandDescription": "display help for command",
|
|
72
|
+
"_helpConfiguration": {}
|
|
73
|
+
}"
|
|
74
|
+
`;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`createGroupCoverageByCodeownersCommand has the correct command structure 1`] = `
|
|
4
|
+
"{
|
|
5
|
+
"_events": {},
|
|
6
|
+
"_eventsCount": 0,
|
|
7
|
+
"commands": [],
|
|
8
|
+
"options": [],
|
|
9
|
+
"parent": null,
|
|
10
|
+
"_allowUnknownOption": false,
|
|
11
|
+
"_allowExcessArguments": true,
|
|
12
|
+
"_args": [],
|
|
13
|
+
"args": [],
|
|
14
|
+
"rawArgs": [],
|
|
15
|
+
"processedArgs": [],
|
|
16
|
+
"_scriptPath": null,
|
|
17
|
+
"_name": "group-coverage-by-codeowners",
|
|
18
|
+
"_optionValues": {},
|
|
19
|
+
"_optionValueSources": {},
|
|
20
|
+
"_storeOptionsAsProperties": false,
|
|
21
|
+
"_executableHandler": false,
|
|
22
|
+
"_executableFile": null,
|
|
23
|
+
"_executableDir": null,
|
|
24
|
+
"_defaultCommandName": null,
|
|
25
|
+
"_exitCallback": null,
|
|
26
|
+
"_aliases": [],
|
|
27
|
+
"_combineFlagAndOptionalValue": true,
|
|
28
|
+
"_description": "Reads code coverage reports for Jest and Cypress, groups the coverage data based on code owners, and writes separate coverage reports for each team.\\nThe command utilizes the Codeowners class, which is responsible for identifying the code owners associated with each file.",
|
|
29
|
+
"_summary": "",
|
|
30
|
+
"_enablePositionalOptions": false,
|
|
31
|
+
"_passThroughOptions": false,
|
|
32
|
+
"_lifeCycleHooks": {},
|
|
33
|
+
"_showHelpAfterError": false,
|
|
34
|
+
"_showSuggestionAfterError": true,
|
|
35
|
+
"_outputConfiguration": {},
|
|
36
|
+
"_hidden": false,
|
|
37
|
+
"_hasHelpOption": true,
|
|
38
|
+
"_helpFlags": "-h, --help",
|
|
39
|
+
"_helpDescription": "display help for command",
|
|
40
|
+
"_helpShortFlag": "-h",
|
|
41
|
+
"_helpLongFlag": "--help",
|
|
42
|
+
"_helpCommandName": "help",
|
|
43
|
+
"_helpCommandnameAndArgs": "help [command]",
|
|
44
|
+
"_helpCommandDescription": "display help for command",
|
|
45
|
+
"_helpConfiguration": {}
|
|
46
|
+
}"
|
|
47
|
+
`;
|
|
@@ -2,9 +2,10 @@ import path from 'path'
|
|
|
2
2
|
import execa from 'execa'
|
|
3
3
|
import { print } from '@toptal/davinci-cli-shared'
|
|
4
4
|
import { readFile, writeFile, mkdir, cp, rm } from 'fs/promises'
|
|
5
|
+
import { existsSync } from 'fs'
|
|
5
6
|
|
|
6
7
|
import { sanitizeTeamName } from './services/sanitize-team-name/sanitize-team-name.js'
|
|
7
|
-
import {
|
|
8
|
+
import { TEAMS_COVERAGE_PATH } from './config.js'
|
|
8
9
|
import { getUniqueTeams } from './services/get-unique-teams/get-unique-teams.js'
|
|
9
10
|
import { asyncCodeownersImport } from '../codeowners/index.js'
|
|
10
11
|
|
|
@@ -16,15 +17,28 @@ const generateNycReport = async ({
|
|
|
16
17
|
sanitizedTeamPath,
|
|
17
18
|
sanitizedTeam,
|
|
18
19
|
}) => {
|
|
19
|
-
|
|
20
|
+
const sanitizedTeamPathWithType = path.join(sanitizedTeamPath, type)
|
|
21
|
+
|
|
22
|
+
await mkdir(sanitizedTeamPathWithType)
|
|
23
|
+
|
|
24
|
+
const fullCoverageTeamPath = path.join(
|
|
25
|
+
'coverage',
|
|
26
|
+
type,
|
|
27
|
+
`coverage-final-${sanitizedTeam}.json`
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
if (!existsSync(fullCoverageTeamPath)) {
|
|
31
|
+
print.red(`Make sure that '${fullCoverageTeamPath}' exists`)
|
|
32
|
+
process.exit(1)
|
|
33
|
+
}
|
|
20
34
|
|
|
21
35
|
await cp(
|
|
22
|
-
|
|
23
|
-
|
|
36
|
+
path.join(fullCoverageTeamPath),
|
|
37
|
+
path.join(sanitizedTeamPathWithType, 'coverage-final.json')
|
|
24
38
|
)
|
|
25
39
|
|
|
26
40
|
await execa.command(
|
|
27
|
-
`yarn nyc report --temp-dir ${
|
|
41
|
+
`yarn nyc report --temp-dir ${sanitizedTeamPathWithType} --reporter json-summary --reporter html --report-dir ${sanitizedTeamPathWithType}`
|
|
28
42
|
)
|
|
29
43
|
}
|
|
30
44
|
|
|
@@ -32,7 +46,7 @@ const getCoverageSummary = async (type, teamPath) => {
|
|
|
32
46
|
const result = {}
|
|
33
47
|
|
|
34
48
|
const coverageSummary = JSON.parse(
|
|
35
|
-
await readFile(
|
|
49
|
+
await readFile(path.join(teamPath, type, 'coverage-summary.json'), 'utf8')
|
|
36
50
|
)
|
|
37
51
|
|
|
38
52
|
result[`${type}_lines_coverage`] = sanitizeNycPercentage(
|
|
@@ -111,7 +125,7 @@ const generateTeamCoverage = async options => {
|
|
|
111
125
|
|
|
112
126
|
export const createGenerateTeamCoverageCommand = program =>
|
|
113
127
|
program
|
|
114
|
-
.
|
|
128
|
+
.createCommand('generate-team-coverage')
|
|
115
129
|
.description(
|
|
116
130
|
`Generates team-specific coverage reports by copying and processing coverage data from Jest and Cypress reports.
|
|
117
131
|
The resulting coverage reports provide insights into the code coverage metrics for each team.`
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jest } from '@jest/globals'
|
|
2
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
3
|
+
import { Command } from 'commander'
|
|
4
|
+
|
|
5
|
+
const { createGenerateTeamCoverageCommand } = await import(
|
|
6
|
+
'./create-generate-team-coverage-command.js'
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
describe('createGenerateTeamCoverageCommand', () => {
|
|
10
|
+
let program
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
program = new Command()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
jest.clearAllMocks()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('has the correct command structure', () => {
|
|
21
|
+
const command = createGenerateTeamCoverageCommand(program)
|
|
22
|
+
|
|
23
|
+
expect(JSON.stringify(command, null, 2)).toMatchSnapshot()
|
|
24
|
+
})
|
|
25
|
+
})
|
|
@@ -2,6 +2,7 @@ import path from 'path'
|
|
|
2
2
|
import { print } from '@toptal/davinci-cli-shared'
|
|
3
3
|
import getWorkspaceRoot from 'find-yarn-workspace-root'
|
|
4
4
|
import { readFile, writeFile } from 'fs/promises'
|
|
5
|
+
import { existsSync } from 'fs'
|
|
5
6
|
|
|
6
7
|
import { CYPRESS_COVERAGE_PATH, JEST_COVERAGE_PATH } from './config.js'
|
|
7
8
|
import { sanitizeTeamName } from './services/sanitize-team-name/sanitize-team-name.js'
|
|
@@ -11,7 +12,14 @@ import { asyncCodeownersImport } from '../codeowners/index.js'
|
|
|
11
12
|
const workspaceRoot = getWorkspaceRoot()
|
|
12
13
|
|
|
13
14
|
const readCoverageReport = async reportPathName => {
|
|
14
|
-
const
|
|
15
|
+
const fullPath = path.join(workspaceRoot, reportPathName)
|
|
16
|
+
|
|
17
|
+
if (!existsSync(fullPath)) {
|
|
18
|
+
print.red(`Make sure that '${fullPath}' exists`)
|
|
19
|
+
process.exit(1)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const data = await readFile(fullPath, 'utf8')
|
|
15
23
|
|
|
16
24
|
return JSON.parse(data)
|
|
17
25
|
}
|
|
@@ -87,7 +95,7 @@ const groupCoverageByCodeowners = async () => {
|
|
|
87
95
|
|
|
88
96
|
export const createGroupCoverageByCodeownersCommand = program =>
|
|
89
97
|
program
|
|
90
|
-
.
|
|
98
|
+
.createCommand('group-coverage-by-codeowners')
|
|
91
99
|
.description(
|
|
92
100
|
`Reads code coverage reports for Jest and Cypress, groups the coverage data based on code owners, and writes separate coverage reports for each team.
|
|
93
101
|
The command utilizes the Codeowners class, which is responsible for identifying the code owners associated with each file.`
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jest } from '@jest/globals'
|
|
2
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
3
|
+
import { Command } from 'commander'
|
|
4
|
+
|
|
5
|
+
const { createGroupCoverageByCodeownersCommand } = await import(
|
|
6
|
+
'./create-group-coverage-by-codeowners-command.js'
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
describe('createGroupCoverageByCodeownersCommand', () => {
|
|
10
|
+
let program
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
program = new Command()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
jest.clearAllMocks()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('has the correct command structure', () => {
|
|
21
|
+
const command = createGroupCoverageByCodeownersCommand(program)
|
|
22
|
+
|
|
23
|
+
expect(JSON.stringify(command, null, 2)).toMatchSnapshot()
|
|
24
|
+
})
|
|
25
|
+
})
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { createGroupCoverageByCodeownersCommand } from './create-group-coverage-by-codeowners-command.js'
|
|
2
2
|
import { createGenerateTeamCoverageCommand } from './create-generate-team-coverage-command.js'
|
|
3
3
|
|
|
4
|
-
export const createCoverageCommand = program =>
|
|
5
|
-
|
|
4
|
+
export const createCoverageCommand = program =>
|
|
5
|
+
program
|
|
6
6
|
.createCommand('coverage')
|
|
7
7
|
.description(
|
|
8
8
|
'Provides code coverage analysis, including organizing coverage reports by code owners and generating team-specific reports'
|
|
9
9
|
)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
createGenerateTeamCoverageCommand(coverageCommand)
|
|
13
|
-
|
|
14
|
-
return coverageCommand
|
|
15
|
-
}
|
|
10
|
+
.addCommand(createGroupCoverageByCodeownersCommand(program))
|
|
11
|
+
.addCommand(createGenerateTeamCoverageCommand(program))
|