Skip to content

feat(codecov): Add output coverage file step 1 #92044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions static/app/views/codecov/tests/onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import styled from '@emotion/styled';
import RadioGroup from 'sentry/components/forms/controls/radioGroup';
import {t} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import {OutputCoverageFile} from 'sentry/views/codecov/tests/onboardingSteps/outputCoverageFile';
import TestPreOnboardingPage from 'sentry/views/codecov/tests/preOnboarding';

type SetupOption = 'githubAction' | 'cli';

Expand All @@ -22,6 +24,7 @@ export default function TestsOnboardingPage() {
return (
<LayoutGap>
<p>Test Analytics Onboarding</p>
<TestPreOnboardingPage />
<OnboardingContainer>
<IntroContainer>
<GetStartedHeader>{t('Get Started with Test Analytics')}</GetStartedHeader>
Expand All @@ -41,6 +44,9 @@ export default function TestsOnboardingPage() {
['cli', t("Use Sentry Prevent's CLI to upload testing reports")],
]}
/>
<StepsContainer>
<OutputCoverageFile stepString="1" />
</StepsContainer>
</OnboardingContainer>
</LayoutGap>
);
Expand Down Expand Up @@ -78,3 +84,7 @@ const SelectOptionHeader = styled('h5')`
color: ${p => p.theme.tokens.content.primary};
margin-top: ${space(3)};
`;

const StepsContainer = styled('div')`
padding: ${space(3)} ${space(4)};
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import styled from '@emotion/styled';

import {space} from 'sentry/styles/space';

const Container = styled('div')`
display: flex;
flex-direction: column;
gap: ${space(1)};
border: 1px solid ${p => p.theme.border};
border-radius: ${p => p.theme.borderRadius};
padding: ${space(2)} ${space(3)};
`;

const Header = styled('h3')`
font-size: ${p => p.theme.fontSizeExtraLarge};
color: ${p => p.theme.gray300};
margin-bottom: 0;
`;

const Content = styled('div')`
/* flex-grow: 1; */
`;

export const OnboardingStep = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why you decided to lump these 3 styled components into this file. It feels like we're trying to think this as a component rather than at markup so trying to get a feel of why it's on it's own file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to reuse this composition components for all of the steps so they wouldn't be associated with one specific file/component

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh fair fair I see. Do you ever foresee these steps having different styling bw their headers, contents or containers? I'd normally say this is preemptive abstraction but I think there's a valid case to say you want all of them to be the same, so this comes as a handy way for that if that's how we foresee this behaving in the future. I trust your judgement here 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I will leave it for now then. I do think there's a possibility for steps to have different styling but looking at our current designs, they are all relatively identical. If we run into an outlier, we can explicitly define new styles to be used instead of the styled composition components for that/those instance(s).

Container,
Header,
Content,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import {Fragment, useState} from 'react';
import {Link} from 'react-router-dom';
import styled from '@emotion/styled';

import {CodeSnippet} from 'sentry/components/codeSnippet';
import {Select} from 'sentry/components/core/select';
import {t, tct} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import {OnboardingStep} from 'sentry/views/codecov/tests/onboardingSteps/onboardingStep';

interface OutputCoverageFileProps {
stepString: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: adding the type of variable to the name itself is kind of redundant when you have it typed by a type. I'd call this step or something and cast the number to str if you're expecting that to be a number

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The steps could include a sub-step letter like "2a" so it will need to stay a string.

}

type Frameworks = 'jest' | 'vitest' | 'pytest' | 'phpunit';

const INSTALL_REQUIREMENTS_SNIPPETS: Record<Frameworks, string> = {
jest: `pytest --cov --junitxml=junit.xml -o junit_family=legacy`,
vitest: `vitest --reporter=junit --outputFile=test-report.junit.xml`,
pytest: `npm i --save-dev jest-junit`,
phpunit: `./vendor/bin/phpunit --log-junit junit.xml`,
};

const GENERATE_FILE_SNIPPETS: Record<Frameworks, string> = {
jest: '',
vitest: '',
pytest: `JEST_JUNIT_CLASSNAME="{filepath}" jest --reporters=jest-junit`,
phpunit: '',
};

export function OutputCoverageFile({stepString}: OutputCoverageFileProps) {
const headerText = tct('Step [stepString]: Output a JUnit XML file in your CI', {
stepString,
});
const [selectedFramework, setSelectedFramework] = useState<Frameworks>('jest');

return (
<OnboardingStep.Container>
<OnboardingStep.Header>{headerText}</OnboardingStep.Header>
<OnboardingStep.Content>
<p>
{tct(
"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.",
{
supported: (
// TODO: the new version of this link is still TBD
<Link to="https://docs.codecov.com/docs/test-analytics#:~:text=Only%20JUnit%20XML%20test%20result%20files%20are%20supported%20at%20the%20moment">
{t('supported languages')}
</Link>
),
}
)}
</p>
<StyledSelectControl
size="md"
options={[
{label: 'Jest', value: 'jest'},
{label: 'Vitest', value: 'vitest'},
{label: 'Pytest', value: 'pytest'},
{label: 'PHPunit', value: 'phpunit'},
]}
value={selectedFramework}
onChange={(option: {value: Frameworks}) => setSelectedFramework(option.value)}
/>
<StyledInstruction>
{t('Install requirements in your terminal:')}
</StyledInstruction>
<CodeSnippet dark language="bash">
{INSTALL_REQUIREMENTS_SNIPPETS[selectedFramework]}
</CodeSnippet>
{selectedFramework === 'pytest' ? (
<Fragment>
<StyledInstruction>
{t('Generate a JUnit XML file that contains the results of your test run.')}
</StyledInstruction>
<CodeSnippet dark language="bash">
{GENERATE_FILE_SNIPPETS.pytest}
</CodeSnippet>
</Fragment>
) : null}
</OnboardingStep.Content>
</OnboardingStep.Container>
);
}

const StyledSelectControl = styled(Select)`
width: 110px;
margin-bottom: ${space(1.5)};
`;

const StyledInstruction = styled('p')`
margin: ${space(1.5)} 0;
`;
2 changes: 2 additions & 0 deletions static/app/views/codecov/tests/tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import PageFiltersContainer from 'sentry/components/organizations/pageFilters/co
import {space} from 'sentry/styles/space';
import {decodeSorts} from 'sentry/utils/queryString';
import {useLocation} from 'sentry/utils/useLocation';
import TestsOnboardingPage from 'sentry/views/codecov/tests/onboarding';
import {DEFAULT_SORT} from 'sentry/views/codecov/tests/settings';
import {Summaries} from 'sentry/views/codecov/tests/summaries/summaries';
import type {ValidSort} from 'sentry/views/codecov/tests/testAnalyticsTable/testAnalyticsTable';
Expand Down Expand Up @@ -75,6 +76,7 @@ export default function TestsPage() {
{/* TODO: Conditionally show these if the branch we're in is the main branch */}
<Summaries />
<TestAnalyticsTable response={fakeApiResponse} sort={sorts[0]} />
<TestsOnboardingPage />
</LayoutGap>
);
}
Expand Down
Loading