Testing
Go tests (backend)
To run tests for the Go backend, run go test ./...
, or specify a package
directly, go test ./util/textutil
.
TypeScript tests (web app and browser extension)
- To run all unit tests, run
yarn test
from the root directory. - To run unit tests in development (only running the tests related to uncommitted code), run
yarn test --watch
.- And/or use vscode-jest with
jest.autoEnable: true
(and, if you want,jest.showCoverageOnLoad: true
)
- And/or use vscode-jest with
- To debug tests in VS Code, use vscode-jest and click the Debug code lens next to any
test('name ...', ...)
definition in your test file (be sure to set a breakpoint or break on uncaught exceptions by clicking in the left gutter). - e2e tests:
- To run e2e tests for the browser extension:
cd client/browser && yarn test-e2e
- To run e2e tests for the browser extension:
cd web && yarn test-e2e
- To run e2e tests for the browser extension:
- You can also run
yarn test
from any of the individual project dirs (shared/
,web/
,client/browser/
).
Usually while developing you will either have yarn test --watch
running in a terminal or you will use vscode-jest.
React component snapshot tests
React component snapshot tests are one way of testing React components. They make it easy to see when changes to a React component result in different output. Snapshots are files at __snapshots__/MyComponent.test.tsx.snap
relative to the component’s file, and they are committed (so that you can see the changes in git diff
or when reviewing a PR).
- See the React component snapshot tests documentation.
- See existing test files that use
react-test-renderer
for usage examples. - Use the jest watcher’s u keyboard shortcut (or
yarn test --updateSnapshot
) to update all snapshot files. Be sure to review the diff!
Continuous Integration
The test suite is exercised on every pull request. For the moment CI output access is limited to Sourcegraph employees, though we hope to enable public read-only access soon.
The test pipeline is generated by dev/ci/gen-pipeline.go
, and written to a
YAML file by dev/ci/init-pipeline.yml. This pipeline is immediately scheduled by
Buildkite to run on the Sourcegraph build farm. Some things that are tested
include:
- all of the Go source files that have tests
- dev/check/all.sh (gofmt, lint, go generator, no Security TODO’s, Bash syntax, others)
- JS formatting/linting (prettier, tslint, stylelint, graphql-lint)
- Dockerfile linter (hadolint)
- Check whether the Go module folders are “tidy” (go mod tidy)