Skip to content

Commit 96d9efe

Browse files
feat: Add coverage generation step to CircleCI and OtherCI onboarding (#3596)
1 parent 2ee8ba5 commit 96d9efe

File tree

10 files changed

+348
-209
lines changed

10 files changed

+348
-209
lines changed

src/pages/RepoPage/CoverageOnboarding/CircleCI/CircleCI.test.tsx

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,37 @@ describe('CircleCI', () => {
108108
return { mockMetricMutationVariables, user }
109109
}
110110

111-
describe('step one', () => {
111+
describe('output coverage step', () => {
112112
it('renders header', async () => {
113113
setup({})
114114
render(<CircleCI />, { wrapper })
115115

116-
const header = await screen.findByRole('heading', { name: /Step 1/ })
116+
const header = await screen.findByText(
117+
/Step \d: Output a Coverage report file in your CI/
118+
)
119+
expect(header).toBeInTheDocument()
120+
})
121+
122+
it('renders body', async () => {
123+
setup({})
124+
render(<CircleCI />, { wrapper })
125+
126+
const body = await screen.findByText(/Select your language below/)
127+
expect(body).toBeInTheDocument()
128+
129+
const jest = await screen.findByText(/Jest/)
130+
expect(jest).toBeInTheDocument()
131+
})
132+
})
133+
134+
describe('token step', () => {
135+
it('renders header', async () => {
136+
setup({})
137+
render(<CircleCI />, { wrapper })
138+
139+
const header = await screen.findByRole('heading', {
140+
name: /Step \d: add repository token to environment variables/,
141+
})
117142
expect(header).toBeInTheDocument()
118143
})
119144

@@ -204,13 +229,15 @@ describe('CircleCI', () => {
204229
})
205230
})
206231

207-
describe('step two', () => {
232+
describe('orb yaml step', () => {
208233
beforeEach(() => setup({}))
209234

210235
it('renders header', async () => {
211236
render(<CircleCI />, { wrapper })
212237

213-
const header = await screen.findByRole('heading', { name: /Step 2/ })
238+
const header = await screen.findByRole('heading', {
239+
name: /Step \d: add Codecov orb to CircleCI/,
240+
})
214241
expect(header).toBeInTheDocument()
215242

216243
const CircleCIJSWorkflowLink = await screen.findByRole('link', {
@@ -252,8 +279,18 @@ describe('CircleCI', () => {
252279
})
253280
})
254281

255-
describe('step three', () => {
282+
describe('merge step', () => {
256283
beforeEach(() => setup({}))
284+
285+
it('renders header', async () => {
286+
render(<CircleCI />, { wrapper })
287+
288+
const header = await screen.findByText(
289+
/Step \d: merge to main or your preferred feature branch/
290+
)
291+
expect(header).toBeInTheDocument()
292+
})
293+
257294
it('renders body', async () => {
258295
render(<CircleCI />, { wrapper })
259296

@@ -299,20 +336,21 @@ describe('CircleCI', () => {
299336

300337
describe('user copies text', () => {
301338
it('stores codecov metric', async () => {
339+
// will be removing this stuff soon, backend for this doesn't exist anymore
302340
const { mockMetricMutationVariables } = setup({})
303341
const user = userEvent.setup()
304342
render(<CircleCI />, { wrapper })
305343

306344
const copyCommands = await screen.findAllByTestId(
307345
'clipboard-code-snippet'
308346
)
309-
expect(copyCommands.length).toEqual(3)
347+
expect(copyCommands.length).toEqual(5)
310348

311349
await user.click(copyCommands[1] as HTMLElement)
312350

313351
await user.click(copyCommands[2] as HTMLElement)
314352
await waitFor(() =>
315-
expect(mockMetricMutationVariables).toHaveBeenCalledTimes(2)
353+
expect(mockMetricMutationVariables).toHaveBeenCalledTimes(1)
316354
)
317355
})
318356
})

src/pages/RepoPage/CoverageOnboarding/CircleCI/CircleCI.tsx

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useState } from 'react'
12
import { useParams } from 'react-router-dom'
23

34
import envVarScreenshot from 'assets/onboarding/env_variable_screenshot.png'
@@ -17,6 +18,11 @@ import { ExpandableSection } from 'ui/ExpandableSection'
1718

1819
import ExampleBlurb from '../ExampleBlurb'
1920
import LearnMoreBlurb from '../LearnMoreBlurb'
21+
import OutputCoverageStep from '../OutputCoverageStep/OutputCoverageStep'
22+
import {
23+
Framework,
24+
UseFrameworkInstructions,
25+
} from '../UseFrameworkInstructions'
2026

2127
const orbsString = `orbs:
2228
codecov: codecov/codecov@5
@@ -49,15 +55,28 @@ function CircleCI() {
4955
const uploadToken = orgUploadToken ?? data?.repository?.uploadToken ?? ''
5056
const tokenCopy = orgUploadToken ? 'global' : 'repository'
5157

58+
const [framework, setFramework] = useState<Framework>('Jest')
59+
const frameworkInstructions = UseFrameworkInstructions({
60+
orgUploadToken,
61+
owner,
62+
repo,
63+
})
64+
5265
return (
5366
<div className="flex flex-col gap-5">
54-
<Step1
67+
<OutputCoverageStep
68+
framework={framework}
69+
frameworkInstructions={frameworkInstructions}
70+
owner={owner}
71+
setFramework={setFramework}
72+
/>
73+
<TokenStep
5574
tokenCopy={tokenCopy}
5675
uploadToken={uploadToken}
5776
providerName={providerName!}
5877
/>
59-
<Step2 defaultBranch={data?.repository?.defaultBranch ?? ''} />
60-
<Step3 />
78+
<OrbYAMLStep defaultBranch={data?.repository?.defaultBranch ?? ''} />
79+
<MergeStep />
6180
<FeedbackCTA />
6281
<LearnMoreBlurb />
6382
</div>
@@ -66,20 +85,20 @@ function CircleCI() {
6685

6786
export default CircleCI
6887

69-
interface Step1Props {
88+
interface TokenStepProps {
7089
tokenCopy: string
7190
uploadToken: string
7291
providerName: string
7392
}
7493

75-
function Step1({ tokenCopy, uploadToken, providerName }: Step1Props) {
94+
function TokenStep({ tokenCopy, uploadToken, providerName }: TokenStepProps) {
7695
const { mutate: storeEventMetric } = useStoreCodecovEventMetric()
7796
const { owner } = useParams<URLParams>()
7897
return (
7998
<Card>
8099
<Card.Header>
81100
<Card.Title size="base">
82-
Step 1: add {tokenCopy} token to environment variables
101+
Step 2: add {tokenCopy} token to environment variables
83102
</Card.Title>
84103
</Card.Header>
85104
<Card.Content className="flex flex-col gap-4">
@@ -133,18 +152,18 @@ function Step1({ tokenCopy, uploadToken, providerName }: Step1Props) {
133152
)
134153
}
135154

136-
interface Step2Props {
155+
interface OrbYAMLStepProps {
137156
defaultBranch: string
138157
}
139158

140-
function Step2({ defaultBranch }: Step2Props) {
159+
function OrbYAMLStep({ defaultBranch }: OrbYAMLStepProps) {
141160
const { mutate: storeEventMetric } = useStoreCodecovEventMetric()
142161
const { owner } = useParams<URLParams>()
143162
return (
144163
<Card>
145164
<Card.Header>
146165
<Card.Title size="base">
147-
Step 2: add Codecov orb to CircleCI{' '}
166+
Step 3: add Codecov orb to CircleCI{' '}
148167
<A
149168
hook="circleCIyamlLink"
150169
isExternal
@@ -180,12 +199,12 @@ function Step2({ defaultBranch }: Step2Props) {
180199
)
181200
}
182201

183-
function Step3() {
202+
function MergeStep() {
184203
return (
185204
<Card>
186205
<Card.Header>
187206
<Card.Title size="base">
188-
Step 3: merge to main or your preferred feature branch
207+
Step 4: merge to main or your preferred feature branch
189208
</Card.Title>
190209
</Card.Header>
191210
<Card.Content className="flex flex-col gap-4">

src/pages/RepoPage/CoverageOnboarding/GitHubActions/GitHubActions.tsx

Lines changed: 11 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ import A from 'ui/A'
1010
import { Card } from 'ui/Card'
1111

1212
import MergeStep from './MergeStep'
13-
import OutputCoverageStep from './OutputCoverageStep'
1413
import TokenStep from './TokenStep'
15-
import { Framework } from './types'
1614
import WorkflowYMLStep from './WorkflowYMLStep'
1715

1816
import LearnMoreBlurb from '../LearnMoreBlurb'
17+
import OutputCoverageStep from '../OutputCoverageStep/OutputCoverageStep'
18+
import {
19+
Framework,
20+
UseFrameworkInstructions,
21+
} from '../UseFrameworkInstructions'
22+
1923
interface URLParams {
2024
provider: Provider
2125
owner: string
@@ -60,161 +64,12 @@ function GitHubActions() {
6064
}
6165

6266
const [framework, setFramework] = useState<Framework>('Jest')
67+
const frameworkInstructions = UseFrameworkInstructions({
68+
orgUploadToken,
69+
owner,
70+
repo,
71+
})
6372

64-
const frameworkInstructions = {
65-
Jest: {
66-
install: 'npm install --save-dev jest',
67-
run: 'npx jest --coverage',
68-
workflow: `name: Run tests and upload coverage
69-
70-
on:
71-
push
72-
73-
jobs:
74-
test:
75-
name: Run tests and collect coverage
76-
runs-on: ubuntu-latest
77-
steps:
78-
- name: Checkout
79-
uses: actions/checkout@v4
80-
with:
81-
fetch-depth: 0
82-
83-
- name: Set up Node
84-
uses: actions/setup-node@v4
85-
86-
- name: Install dependencies
87-
run: npm install
88-
89-
- name: Run tests
90-
run: npx jest --coverage
91-
92-
- name: Upload results to Codecov
93-
uses: codecov/codecov-action@v5
94-
with:
95-
token: \${{ secrets.CODECOV_TOKEN }}${
96-
orgUploadToken
97-
? `
98-
slug: ${owner}/${repo}`
99-
: ''
100-
}
101-
`,
102-
},
103-
Vitest: {
104-
install: 'npm install --save-dev vitest @vitest/coverage-v8',
105-
run: 'npx vitest run --coverage',
106-
workflow: `name: Run tests and upload coverage
107-
108-
on:
109-
push
110-
111-
jobs:
112-
test:
113-
name: Run tests and collect coverage
114-
runs-on: ubuntu-latest
115-
steps:
116-
- name: Checkout
117-
uses: actions/checkout@v4
118-
with:
119-
fetch-depth: 0
120-
121-
- name: Set up Node
122-
uses: actions/setup-node@v4
123-
124-
- name: Install dependencies
125-
run: npm install
126-
127-
- name: Run tests
128-
run: npx vitest run --coverage
129-
130-
- name: Upload results to Codecov
131-
uses: codecov/codecov-action@v5
132-
with:
133-
token: \${{ secrets.CODECOV_TOKEN }}${
134-
orgUploadToken
135-
? `
136-
slug: ${owner}/${repo}`
137-
: ''
138-
}
139-
`,
140-
},
141-
Pytest: {
142-
install: 'pip install pytest pytest-cov',
143-
run: 'pytest --cov --cov-report=xml',
144-
workflow: `name: Run tests and upload coverage
145-
146-
on:
147-
push
148-
149-
jobs:
150-
test:
151-
name: Run tests and collect coverage
152-
runs-on: ubuntu-latest
153-
steps:
154-
- name: Checkout
155-
uses: actions/checkout@v4
156-
with:
157-
fetch-depth: 0
158-
159-
- name: Set up Python
160-
uses: actions/setup-python@v4
161-
162-
- name: Install dependencies
163-
run: pip install pytest pytest-cov
164-
165-
- name: Run tests
166-
run: pytest --cov --cov-report=xml
167-
168-
- name: Upload results to Codecov
169-
uses: codecov/codecov-action@v5
170-
with:
171-
token: \${{ secrets.CODECOV_TOKEN }}${
172-
orgUploadToken
173-
? `
174-
slug: ${owner}/${repo}`
175-
: ''
176-
}
177-
`,
178-
},
179-
Go: {
180-
install: undefined,
181-
run: 'go test -coverprofile=coverage.txt',
182-
workflow: `name: Run tests and upload coverage
183-
184-
on:
185-
push
186-
187-
jobs:
188-
test:
189-
name: Run tests and collect coverage
190-
runs-on: ubuntu-latest
191-
steps:
192-
- name: Checkout
193-
uses: actions/checkout@v4
194-
with:
195-
fetch-depth: 0
196-
197-
- name: Set up Go
198-
uses: actions/setup-go@v5
199-
200-
- name: Install dependencies
201-
run: go mod download
202-
203-
- name: Run tests
204-
run: go test -coverprofile=coverage.txt
205-
206-
- name: Upload results to Codecov
207-
uses: codecov/codecov-action@v5
208-
with:
209-
token: \${{ secrets.CODECOV_TOKEN }}${
210-
orgUploadToken
211-
? `
212-
slug: ${owner}/${repo}`
213-
: ''
214-
}
215-
`,
216-
},
217-
}
21873
return (
21974
<div className="flex flex-col gap-5">
22075
<OutputCoverageStep

0 commit comments

Comments
 (0)