@toptal/davinci-monorepo 8.1.4-alpha-CRT-5891-create-coverage-command-2488e674.2 → 8.1.4-alpha-CRT-5891-create-coverage-command-082cae9e.3

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/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-2488e674.2+2488e674",
3
+ "version": "8.1.4-alpha-CRT-5891-create-coverage-command-082cae9e.3+082cae9e",
4
4
  "description": "Monorepo utility tools",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -35,13 +35,14 @@
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-2488e674.34+2488e674",
38
+ "@toptal/davinci-cli-shared": "2.3.1-alpha-CRT-5891-create-coverage-command-082cae9e.35+082cae9e",
39
39
  "chalk": "^4.1.2",
40
40
  "codeowners": "5.1.1",
41
41
  "dependency-cruiser": "^12.5.0",
42
42
  "ervy": "^1.0.7",
43
43
  "execa": "^5.1.1",
44
44
  "find-up": "5.0.0",
45
+ "find-yarn-workspace-root": "^2.0.0",
45
46
  "glob": "^8.0.3",
46
47
  "ignore": "^5.2.0",
47
48
  "is-directory": "^0.3.1",
@@ -53,5 +54,5 @@
53
54
  "devDependencies": {
54
55
  "@jest/globals": "^29.4.2"
55
56
  },
56
- "gitHead": "2488e6747994019dbeab8517629432f68e9af814"
57
+ "gitHead": "082cae9ecf302c878d2dcbe004d88ff1ba737381"
57
58
  }
@@ -4,8 +4,8 @@ import { groupCoverageByCodeownersCommand } from './group-coverage-by-codeowners
4
4
  export const coverageCommand = program => {
5
5
  const coverage = program.createCommand('coverage').description('TODO ..')
6
6
 
7
- generateTeamCoverageCommand(coverageCommand)
8
- groupCoverageByCodeownersCommand(coverageCommand)
7
+ groupCoverageByCodeownersCommand(coverage)
8
+ generateTeamCoverageCommand(coverage)
9
9
 
10
10
  return coverage
11
11
  }
@@ -2,11 +2,17 @@ import path from 'path'
2
2
  import * as url from 'url'
3
3
  import execa from 'execa'
4
4
  import fs from 'fs'
5
+ import { print } from '@toptal/davinci-cli-shared'
6
+ import getWorkspaceRoot from 'find-yarn-workspace-root'
5
7
 
6
8
  import Codeowners from './codeowners/core/codeowners/codeowners.js'
7
9
 
8
10
  const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
9
11
  const rootProjectPath = path.join(__dirname, '../../')
12
+ const workspaceRoot = getWorkspaceRoot()
13
+
14
+ console.log('workspaceRoot', workspaceRoot)
15
+ console.log('rootProjectPath', rootProjectPath)
10
16
 
11
17
  const sanitizeTeamName = team => team.replace('/', '-').replace('@', '')
12
18
 
@@ -14,8 +20,10 @@ const sanitizeNycPercentage = percentage =>
14
20
  percentage === 'Unknown' ? 0 : percentage
15
21
 
16
22
  // eslint-disable-next-line max-statements
17
- const generateTeamCoverage = async () => {
18
- const codeowners = new Codeowners(rootProjectPath)
23
+ const generateTeamCoverage = async options => {
24
+ print.header('generateTeamCoverage')
25
+
26
+ const codeowners = new Codeowners(workspaceRoot)
19
27
 
20
28
  const ownerEntries = codeowners.ownerEntries
21
29
  const uniqueTeams = ownerEntries
@@ -66,15 +74,12 @@ const generateTeamCoverage = async () => {
66
74
  const results = []
67
75
  const created_at = new Date().toISOString()
68
76
 
69
- // TODO pass it as param
70
- const repo = 'client-portal'
71
-
72
77
  for await (const team of teams) {
73
78
  const sanitizedTeam = sanitizeTeamName(team)
74
79
  const result = {
75
80
  created_at,
76
81
  team,
77
- repo,
82
+ repo: options.repository,
78
83
  }
79
84
 
80
85
  const jestCoverageSummary = JSON.parse(
@@ -127,12 +132,14 @@ const generateTeamCoverage = async () => {
127
132
  }
128
133
 
129
134
  export const generateTeamCoverageCommand = program => {
135
+ print.header('generateTeamCoverageCommand')
136
+
130
137
  return program
131
- .createCommand('generate-team-coverage')
138
+ .command('generate-team-coverage')
132
139
  .description('TODO: generate-team-coverage')
133
140
  .requiredOption(
134
141
  '-r, --repository <repository_name>',
135
142
  'specify repository name'
136
143
  )
137
- .action((_, options) => generateTeamCoverage(options))
144
+ .action(options => generateTeamCoverage(options))
138
145
  }
@@ -1,15 +1,21 @@
1
1
  import path from 'path'
2
2
  import fs from 'fs'
3
3
  import * as url from 'url'
4
+ import { print } from '@toptal/davinci-cli-shared'
5
+ import getWorkspaceRoot from 'find-yarn-workspace-root'
4
6
 
5
7
  import Codeowners from './codeowners/core/codeowners/codeowners.js'
6
8
 
7
9
  const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
8
10
  const rootProjectPath = path.join(__dirname, '../../')
11
+ const workspaceRoot = getWorkspaceRoot()
12
+
13
+ console.log('workspaceRoot', workspaceRoot)
14
+ console.log('rootProjectPath', rootProjectPath)
9
15
 
10
16
  const readJestCoverageReport = () => {
11
17
  const jestCoverageReportPath = path.join(
12
- rootProjectPath,
18
+ workspaceRoot,
13
19
  'coverage/jest/coverage-final-jest.json'
14
20
  )
15
21
 
@@ -20,7 +26,7 @@ const readJestCoverageReport = () => {
20
26
 
21
27
  const readCypressCoverageReport = () => {
22
28
  const cypressCoverageReportPath = path.join(
23
- rootProjectPath,
29
+ workspaceRoot,
24
30
  'coverage/cypress/coverage-final-cypress.json'
25
31
  )
26
32
 
@@ -37,8 +43,12 @@ const splitReportIntoTeams = (reportObj, teams, codeowners, coveragePath) => {
37
43
  Object.entries(reportObj).forEach(([reportPathKey, report]) => {
38
44
  const file = report.path
39
45
  const relativePath = path.relative(rootProjectPath, file)
46
+ const relativeWorkspacePath = path.relative(workspaceRoot, file)
47
+
48
+ console.log('relativePath', relativePath)
49
+ console.log('relativeWorkspacePath', relativeWorkspacePath)
40
50
 
41
- const owners = codeowners.getOwner(relativePath)
51
+ const owners = codeowners.getOwner(relativeWorkspacePath)
42
52
 
43
53
  owners.forEach(owner => {
44
54
  teamsReport[owner] = {
@@ -53,7 +63,7 @@ const splitReportIntoTeams = (reportObj, teams, codeowners, coveragePath) => {
53
63
  const sanitizedTeamPath = sanitizeTeamName(team)
54
64
 
55
65
  const reportPath = path.join(
56
- rootProjectPath,
66
+ workspaceRoot,
57
67
  `${coveragePath}/coverage-final-${sanitizedTeamPath}.json`
58
68
  )
59
69
 
@@ -74,13 +84,13 @@ const getAllTeams = codeowners => {
74
84
  return uniqueTeams
75
85
  }
76
86
 
77
- const groupCoverageByCodeowners = async options => {
78
- console.log(options)
87
+ const groupCoverageByCodeowners = async () => {
88
+ print.header('groupCoverageByCodeowners')
79
89
 
80
90
  const jestReport = readJestCoverageReport()
81
91
  const cypressReport = readCypressCoverageReport()
82
92
 
83
- const codeowners = new Codeowners(rootProjectPath)
93
+ const codeowners = new Codeowners(workspaceRoot)
84
94
  const teams = getAllTeams(codeowners)
85
95
 
86
96
  splitReportIntoTeams(jestReport, teams, codeowners, 'coverage/jest')
@@ -88,12 +98,10 @@ const groupCoverageByCodeowners = async options => {
88
98
  }
89
99
 
90
100
  export const groupCoverageByCodeownersCommand = program => {
101
+ print.header('groupCoverageByCodeownersCommand')
102
+
91
103
  return program
92
- .createCommand('group-coverage-by-codeowners')
104
+ .command('group-coverage-by-codeowners')
93
105
  .description('TODO: group-coverage-by-codeowners')
94
- .requiredOption(
95
- '-r, --repository <repository_name>',
96
- 'specify repository name'
97
- )
98
- .action((_, options) => groupCoverageByCodeowners(options))
106
+ .action(groupCoverageByCodeowners)
99
107
  }
@@ -1,61 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`groupCoverageByCodeownersCommand has the correct command structure 1`] = `
4
- "{
5
- "_events": {},
6
- "_eventsCount": 1,
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
- "parent": null,
24
- "_allowUnknownOption": false,
25
- "_allowExcessArguments": true,
26
- "_args": [],
27
- "args": [],
28
- "rawArgs": [],
29
- "processedArgs": [],
30
- "_scriptPath": null,
31
- "_name": "group-coverage-by-codeowners",
32
- "_optionValues": {},
33
- "_optionValueSources": {},
34
- "_storeOptionsAsProperties": false,
35
- "_executableHandler": false,
36
- "_executableFile": null,
37
- "_executableDir": null,
38
- "_defaultCommandName": null,
39
- "_exitCallback": null,
40
- "_aliases": [],
41
- "_combineFlagAndOptionalValue": true,
42
- "_description": "TODO: group-coverage-by-codeowners",
43
- "_summary": "",
44
- "_enablePositionalOptions": false,
45
- "_passThroughOptions": false,
46
- "_lifeCycleHooks": {},
47
- "_showHelpAfterError": false,
48
- "_showSuggestionAfterError": true,
49
- "_outputConfiguration": {},
50
- "_hidden": false,
51
- "_hasHelpOption": true,
52
- "_helpFlags": "-h, --help",
53
- "_helpDescription": "display help for command",
54
- "_helpShortFlag": "-h",
55
- "_helpLongFlag": "--help",
56
- "_helpCommandName": "help",
57
- "_helpCommandnameAndArgs": "help [command]",
58
- "_helpCommandDescription": "display help for command",
59
- "_helpConfiguration": {}
60
- }"
61
- `;
@@ -1,23 +0,0 @@
1
- import { jest } from '@jest/globals'
2
- // eslint-disable-next-line import/no-extraneous-dependencies
3
- import { Command } from 'commander'
4
-
5
- import { groupCoverageByCodeownersCommand } from './group-coverage-by-codeowners.js'
6
-
7
- describe('groupCoverageByCodeownersCommand', () => {
8
- let program
9
-
10
- beforeEach(() => {
11
- program = new Command()
12
- })
13
-
14
- afterEach(() => {
15
- jest.clearAllMocks()
16
- })
17
-
18
- it('has the correct command structure', () => {
19
- const command = groupCoverageByCodeownersCommand(program)
20
-
21
- expect(JSON.stringify(command, null, 2)).toMatchSnapshot()
22
- })
23
- })