Skip to content

Commit 467933d

Browse files
feat(codecov): Add output coverage file step 1
1 parent f38fdb9 commit 467933d

File tree

4 files changed

+102
-2
lines changed

4 files changed

+102
-2
lines changed

static/app/views/codecov/tests/onboarding.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {space} from 'sentry/styles/space';
88

99
type SetupOption = 'githubAction' | 'cli';
1010

11+
// Phase out for directory version
1112
export default function TestsOnboardingPage() {
1213
const [searchParams, setSearchParams] = useSearchParams();
1314
const opt = searchParams.get('opt');

static/app/views/codecov/tests/onboarding/onboarding.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import styled from '@emotion/styled';
44
import RadioGroup from 'sentry/components/forms/controls/radioGroup';
55
import {t} from 'sentry/locale';
66
import {space} from 'sentry/styles/space';
7+
import {OutputCoverageFile} from 'sentry/views/codecov/tests/onboarding/outputCoverageFile';
78

89
type SetupOption = 'githubAction' | 'cli';
910

@@ -32,6 +33,9 @@ export default function TestsOnboardingPage() {
3233
['cli', t("Use Sentry Prevent's CLI to upload testing reports")],
3334
]}
3435
/>
36+
<StepsContainer>
37+
<OutputCoverageFile stepString="1" />
38+
</StepsContainer>
3539
</OnboardingContainer>
3640
</LayoutGap>
3741
);
@@ -50,7 +54,6 @@ const OnboardingContainer = styled('div')`
5054

5155
const IntroContainer = styled('div')`
5256
border-bottom: 1px solid ${p => p.theme.border};
53-
padding-bottom: ${space(3)};
5457
`;
5558

5659
const GetStartedHeader = styled('h2')`
@@ -69,3 +72,7 @@ const SelectOptionHeader = styled('h5')`
6972
color: ${p => p.theme.tokens.content.primary};
7073
margin-top: ${space(3)};
7174
`;
75+
76+
const StepsContainer = styled('div')`
77+
padding: ${space(3)} ${space(4)};
78+
`;

static/app/views/codecov/tests/onboarding/onboardingStep.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ const Container = styled('div')`
1111
padding: ${space(2)} ${space(3)};
1212
`;
1313

14-
const Header = styled('h5')`
14+
const Header = styled('h3')`
1515
font-size: ${p => p.theme.fontSizeExtraLarge};
1616
color: ${p => p.theme.gray300};
17+
margin-bottom: 0;
1718
`;
1819

1920
const Content = styled('div')`
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import {Fragment, useState} from 'react';
2+
import {Link} from 'react-router-dom';
3+
import styled from '@emotion/styled';
4+
5+
import {CodeSnippet} from 'sentry/components/codeSnippet';
6+
import {Select} from 'sentry/components/core/select';
7+
import {t, tct} from 'sentry/locale';
8+
import {space} from 'sentry/styles/space';
9+
import {OnboardingStep} from 'sentry/views/codecov/tests/onboarding/onboardingStep';
10+
11+
interface OutputCoverageFileProps {
12+
stepString: string;
13+
}
14+
15+
type Frameworks = 'jest' | 'vitest' | 'pytest' | 'phpunit';
16+
17+
const INSTALL_REQUIREMENTS_SNIPPETS: Record<Frameworks, string> = {
18+
jest: `pytest --cov --junitxml=junit.xml -o junit_family=legacy`,
19+
vitest: `vitest --reporter=junit --outputFile=test-report.junit.xml`,
20+
pytest: `npm i --save-dev jest-junit`,
21+
phpunit: `./vendor/bin/phpunit --log-junit junit.xml`,
22+
};
23+
24+
const GENERATE_FILE_SNIPPETS: Record<Frameworks, string> = {
25+
jest: '',
26+
vitest: '',
27+
pytest: `JEST_JUNIT_CLASSNAME="{filepath}" jest --reporters=jest-junit`,
28+
phpunit: '',
29+
};
30+
31+
export function OutputCoverageFile({stepString}: OutputCoverageFileProps) {
32+
const headerText = tct('Step [stepString]: Output a JUnit XML file in your CI', {
33+
stepString,
34+
});
35+
const [selectedFramework, setSelectedFramework] = useState<Frameworks>('jest');
36+
37+
return (
38+
<OnboardingStep.Container>
39+
<OnboardingStep.Header>{headerText}</OnboardingStep.Header>
40+
<OnboardingStep.Content>
41+
<p>
42+
{tct(
43+
"Select your language below to generate your testing reports. If your language isn't listed, visit [supported] for your testing framework. Currently, Sentry supports JUnit XML format only.",
44+
{
45+
supported: (
46+
// TODO: the new version of this link is still TBD
47+
<Link to="https://docs.codecov.com/docs/test-analytics#:~:text=Only%20JUnit%20XML%20test%20result%20files%20are%20supported%20at%20the%20moment">
48+
supported languages
49+
</Link>
50+
),
51+
}
52+
)}
53+
</p>
54+
<StyledSelectControl
55+
size="md"
56+
options={[
57+
{label: 'Jest', value: 'jest'},
58+
{label: 'Vitest', value: 'vitest'},
59+
{label: 'Pytest', value: 'pytest'},
60+
{label: 'PHPunit', value: 'phpunit'},
61+
]}
62+
value={selectedFramework}
63+
onChange={(option: {value: Frameworks}) => setSelectedFramework(option.value)}
64+
/>
65+
<StyledP>{t('Install requirements in your terminal:')}</StyledP>
66+
<CodeSnippet dark language="bash">
67+
{INSTALL_REQUIREMENTS_SNIPPETS[selectedFramework]}
68+
</CodeSnippet>
69+
{GENERATE_FILE_SNIPPETS[selectedFramework] ? (
70+
<Fragment>
71+
<StyledP>
72+
{t('Generate a JUnit XML file that contains the results of your test run.')}
73+
</StyledP>
74+
<CodeSnippet dark language="bash">
75+
{GENERATE_FILE_SNIPPETS[selectedFramework]}
76+
</CodeSnippet>
77+
</Fragment>
78+
) : null}
79+
</OnboardingStep.Content>
80+
</OnboardingStep.Container>
81+
);
82+
}
83+
84+
const StyledSelectControl = styled(Select)`
85+
width: 110px;
86+
margin-bottom: ${space(1.5)};
87+
`;
88+
89+
const StyledP = styled('p')`
90+
margin: ${space(1.5)} 0;
91+
`;

0 commit comments

Comments
 (0)