mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 18:11:48 +00:00
Replaces our usage of jest with vitest. Also removes the babel transpiler. This simplifies our test configuration by a lot, makes tests run 10% faster, and makes further modernizations to our build/test stuff possible (such as using vite for frontend builds).
This removes some of the junit exporting for Buildkite, and the vitest bazel defs don't really cleanly implement bazel testing guidelines (like sharding). But vitest is only used for unit tests (all integration/e2e/regression tests have always run in mocha), so none of them are very slow anyway.
## Codemods for vitest imports
fastmod -e js,ts,tsx @jest/globals vitest client/ dev/release/
fastmod -e js,ts,tsx 'jest\.(\w+)\(' 'vi.$1(' client/ dev/release/
fastmod -e js,ts,tsx 'jest,' 'vi,' client/ dev/release/
fastmod -e js,ts,tsx 'jest }' 'vi }' client/ dev/release/
git diff --diff-filter=M --name-only | xargs pnpm exec prettier --write
160 lines
6.8 KiB
TypeScript
160 lines
6.8 KiB
TypeScript
import { render } from '@testing-library/react'
|
|
import { noop } from 'lodash'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import { HTTPStatusError } from '@sourcegraph/http-client'
|
|
|
|
import { ViewOnSourcegraphButton } from './ViewOnSourcegraphButton'
|
|
|
|
describe('<ViewOnSourcegraphButton />', () => {
|
|
describe('repository exists on the instance', () => {
|
|
it('renders a link to the repository on the Sourcegraph instance', () => {
|
|
expect(
|
|
render(
|
|
<ViewOnSourcegraphButton
|
|
codeHostType="test-codehost"
|
|
sourcegraphURL="https://test.com"
|
|
userSettingsURL="https://sourcegraph.com/users/john.doe/settings/repositories/manage"
|
|
context={{ rawRepoName: 'test', privateRepository: false }}
|
|
className="test"
|
|
repoExistsOrError={true}
|
|
minimalUI={false}
|
|
/>
|
|
).asFragment()
|
|
).toMatchSnapshot()
|
|
})
|
|
|
|
it('renders nothing in minimal UI mode', () => {
|
|
expect(
|
|
render(
|
|
<ViewOnSourcegraphButton
|
|
codeHostType="test-codehost"
|
|
sourcegraphURL="https://test.com"
|
|
userSettingsURL="https://sourcegraph.com/users/john.doe/settings/repositories/manage"
|
|
context={{ rawRepoName: 'test', privateRepository: false }}
|
|
className="test"
|
|
repoExistsOrError={true}
|
|
minimalUI={true}
|
|
/>
|
|
).asFragment()
|
|
).toMatchSnapshot()
|
|
})
|
|
|
|
it('renders a link with the revision when provided', () => {
|
|
expect(
|
|
render(
|
|
<ViewOnSourcegraphButton
|
|
codeHostType="test-codehost"
|
|
sourcegraphURL="https://test.com"
|
|
userSettingsURL="https://sourcegraph.com/users/john.doe/settings/repositories/manage"
|
|
context={{
|
|
rawRepoName: 'test',
|
|
revision: 'test',
|
|
privateRepository: false,
|
|
}}
|
|
className="test"
|
|
repoExistsOrError={true}
|
|
minimalUI={false}
|
|
/>
|
|
).asFragment()
|
|
).toMatchSnapshot()
|
|
})
|
|
})
|
|
|
|
describe('repository does not exist on the instance', () => {
|
|
it('renders "Configure Sourcegraph" button when pointing at sourcegraph.com', () => {
|
|
expect(
|
|
render(
|
|
<ViewOnSourcegraphButton
|
|
codeHostType="test-codehost"
|
|
sourcegraphURL="https://sourcegraph.com"
|
|
userSettingsURL="https://sourcegraph.com/users/john.doe/settings/repositories/manage"
|
|
context={{
|
|
rawRepoName: 'test',
|
|
revision: 'test',
|
|
privateRepository: false,
|
|
}}
|
|
className="test"
|
|
repoExistsOrError={false}
|
|
onConfigureSourcegraphClick={noop}
|
|
minimalUI={false}
|
|
/>
|
|
).asFragment()
|
|
).toMatchSnapshot()
|
|
})
|
|
|
|
it('renders a "Repository not found" button when not pointing at sourcegraph.com', () => {
|
|
expect(
|
|
render(
|
|
<ViewOnSourcegraphButton
|
|
codeHostType="test-codehost"
|
|
sourcegraphURL="https://sourcegraph.test"
|
|
userSettingsURL="https://sourcegraph.com/users/john.doe/settings/repositories/manage"
|
|
context={{
|
|
rawRepoName: 'test',
|
|
revision: 'test',
|
|
privateRepository: false,
|
|
}}
|
|
className="test"
|
|
repoExistsOrError={false}
|
|
onConfigureSourcegraphClick={noop}
|
|
minimalUI={false}
|
|
/>
|
|
).asFragment()
|
|
).toMatchSnapshot()
|
|
})
|
|
})
|
|
|
|
describe('existence could not be determined ', () => {
|
|
describe('because of an authentication failure', () => {
|
|
for (const minimalUI of [true, false]) {
|
|
describe(`minimalUI = ${String(minimalUI)}`, () => {
|
|
it('renders a sign in button if showSignInButton = true', () => {
|
|
expect(
|
|
render(
|
|
<ViewOnSourcegraphButton
|
|
codeHostType="test-codehost"
|
|
sourcegraphURL="https://test.com"
|
|
userSettingsURL="https://sourcegraph.com/users/john.doe/settings/repositories/manage"
|
|
context={{
|
|
rawRepoName: 'test',
|
|
revision: 'test',
|
|
privateRepository: false,
|
|
}}
|
|
showSignInButton={true}
|
|
className="test"
|
|
repoExistsOrError={new HTTPStatusError(new Response('', { status: 401 }))}
|
|
minimalUI={minimalUI}
|
|
/>
|
|
).asFragment()
|
|
).toMatchSnapshot()
|
|
})
|
|
})
|
|
}
|
|
})
|
|
|
|
describe('because of an unknown error', () => {
|
|
it('renders a button with an error label', () => {
|
|
expect(
|
|
render(
|
|
<ViewOnSourcegraphButton
|
|
codeHostType="test-codehost"
|
|
sourcegraphURL="https://test.com"
|
|
userSettingsURL="https://sourcegraph.com/users/john.doe/settings/repositories/manage"
|
|
context={{
|
|
rawRepoName: 'test',
|
|
revision: 'test',
|
|
privateRepository: false,
|
|
}}
|
|
showSignInButton={true}
|
|
className="test"
|
|
repoExistsOrError={new Error('Something unknown happened!')}
|
|
minimalUI={false}
|
|
/>
|
|
).asFragment()
|
|
).toMatchSnapshot()
|
|
})
|
|
})
|
|
})
|
|
})
|