|
| 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