* reapply "switch from jest to vitest for faster, simpler tests (https://github.com/sourcegraph/sourcegraph/pull/57886)"
This was reverted in https://github.com/sourcegraph/sourcegraph/pull/58116 due to an issue with the browser tests.
* include fetch-mock
* fix flakiness
* rm mock that did not work in experimentalVmThreads
* fix
* timeout
* fixup
---------
Co-authored-by: William Bezuidenhout <william.bezuidenhout@sourcegraph.com>
When running vitests concurrently the target //client/browser:test fails
Revert "switch from jest to vitest for faster, simpler tests (#57886)"
This reverts commit ae5325e432.
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
Removed usage of gulp for running commands. Instead, we just use `package.json` scripts (that mostly invoke `ts-node -T ...`). The purpose of removing gulp is to remove a layer of duplication/indirection between the tasks we need to run and where they are defined.
The code generation tasks (GraphQL operations, CSS modules types, and schema/ JSON Schema types) no longer run in watch mode in local dev. If you make changes that require regeneration of this code, run `pnpm run generate` from the root. This is for simplicity and speed (they would run on many unrelated changes and slow down local dev).
* stub method to avoid unhandled exception in test from pretendRemote
* less flaky ActionItem test that checks condition before snapshotting
* rename *.{spec => test}.ts
This simplifies the test filename pattern.
* rename top-level tsconfig.all.json to tsconfig.json
* upgrade to pnpm 8.9.2
* avoid usage of jsdom.reconfigure
* more robust linkClickHandler.test.tsx
* make getBundleSizeStats.test.ts not need to use mocks
* extract createBarrier() to @sourcegraph/testing
* more robust fromObservableQuery.test.ts
* avoid jsdom.reconfigure
* do not attempt to request assets from assets.gitlab-static.net
fastmod -F assets.gitlab-static.net example.com client/browser/src/
* avoid "incorrect casing" for mocked React components
* use createBarrier
* fix SurveyToast mock GraphQL query
* fix classNames typo
Our tracking of frontend (TypeScript) code coverage has decayed and was no longer being used. The Codecov report at https://app.codecov.io/gh/sourcegraph/sourcegraph significantly under-counts coverage, and what coverage tasks we did have were flaky in CI and relied on old libraries that have not been updated recently to keep with modern practices (such as `@storybook/addon-storyshots` only supporting Jest with `injectGlobals`).
From https://sourcegraph.slack.com/archives/C04MYFW01NV/p1698059032863009?thread_ts=1698054092.709309&cid=C04MYFW01NV, the proposal is to remove coverage tracking for now and prioritize getting tests to run really fast and smooth locally first, including upgrading our testing infra, and then reenable code coverage tracking.
This PR adjusts all configs/generators/linters that we use to support multiple `.graphql` files to be stitched together for the final schema.
This should help a bit with the MASSIVE `schema.graphql` file that has grown to around 10k loc by now, by encapsulating different fields of concern into separate files. Using the `extend` keyword, there is nothing that cannot be expressed with separate files that could have been with a single file, so there are no drawbacks to this method, that I'm aware of.
In a follow-up PR, I will restructure the backend code for this a bit and make it so the enterprise schema is not used in OSS (which gives better introspection, because there is less noise from fields that aren't accessible because OSS) and doesn't require us to implement a `defaultXXResolver`.
* Use browser API
* Renames
* Polyfill globalThis in Jest
* Don't use dynamic import
* More type safe storage access
* Prettier webpack log
* Don't use NonNullable
* Remove unused background page handlers
* Replace sourcegraph.com string literals with constant
* Use BackgroundMessageHandlers interface in client too
Adds generic tests that test invariants of all mount getters.
Updates GitHub DOM fixtures to incorporate DOM changes (new tests were failing against old fixtures).
I had to add a custom jest-environment to both use latest JSDOM (for `el.insertAdjacentElement()`) and expose `jsdom` as a global.
This also allowed me to get rid of the `MutationObserver` polyfill (and the `IntersectionObserver` wasn't used anymore).
This increases the browser extension test coverage from 36.06% to 41.20% 🎉
* Stricter tsconfig for the browsr extension
* Refactor getPhabricatorState() to async function
This was the best way to fix the many noImplicitReturns violations in this function.
* Fix Alerts.tsx
* Update client/browser/src/shared/repo/backend.tsx
Co-Authored-By: lguychard <l.guychard@gmail.com>
* `| null` -> `| undefined`
* Add return type
Goal: help people write reliable UI code by making it easier to write and run tests.
Using Facebook's [jest](https://jestjs.io) for tests helps us achieve this goal because:
- jest has great first-class support for testing React components (see https://jestjs.io/docs/en/tutorial-react) and is by far the most popular way that people test React components, so the bugs are ironed out and the tooling is good
- jest can run all of our tests (`shared/`, `web/`, and `client/browser/` -- and unit tests **AND** e2e tests) from the same runner (`yarn test` in the root dir)
- jest has a great `--watch` UI and a good [vscode-jest extension](https://github.com/jest-community/vscode-jest)
- debugging tests in VS Code works with no additional effort
- jest requires a lot less configuration and code to set up testing and coverage than Mocha (no `--require ts-node --require source-map-support mocha.opts --require long-stack-traces --require esm ...`, no test-time bundling required using `unit-test-utils.ts`, etc.)
**Note:** Most of the diff is from https://github.com/skovhus/jest-codemods, which automatically updates our test code to use jest style (`describe`, `test`, `expect`, etc., not `it` and `assert`).
jest appears to be the most popular tool for solving the problem that we have (testing a large web/multi-platform application), and it was surprisingly painless to set up and a joy to use.
TODOs:
- [x] Make it pass on Buildkite
- [x] Ensure e2e, screenshots-after-failures, and coverage still work on Buildkite
- [x] Test on macOS
- [x] Add docs to repo
---
Usage:
> This is also documented in `doc/dev/testing.md` and `doc/dev/web_app.md`.
- 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](https://github.com/jest-community/vscode-jest) with `jest.autoEnable: true` (and, if you want, `jest.showCoverageOnLoad: true`)
- To debug tests in VS Code, use [vscode-jest](https://github.com/jest-community/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`
- 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.
---
Notes:
- There are no regressions. The following are all preserved as before: Puppeteer screenshots after test failures, jsdom tests, e2e tests, Codecov and lcov coverage, VS Code integration, etc.
- You will need to write tests using [jest matchers](https://jestjs.io/docs/en/using-matchers) (or [jest async matchers](https://jestjs.io/docs/en/asynchronous) for async code), not `assert`. They are very similar.
- You need to use `test()` instead of `it()` for defining test cases.
* remove or inline functions related to extensions providers
* remove unneeded backend/lsp.tsx and its type definitions
* remove unnecessary reexport of HoverMerged
* move ModeSpec to file with all other XyzSpec types
* de-duplicate highlight.js imports
* remove unused code from browser extension
This removes a lot of old pre-newInject code. None of this was in use anymore. The purpose of removing it is to make it easier to make extensions work well with the browser extension (by limiting the number of places that need to invoke the extensions client API).
Process:
1. Remove `export` keyword from definitions that were only used in the same file
2. Remove definitions that had no usages
3. Repeat
* remove enterprise workspace (build together with webapp)
* remove sourcegraph-extension-api workspace
* directly import graphqlschema instead of symlinking
* remove unneeded symlink (file now lives in this package)
* noEmit on extensions-client-common & refer to graphql schema in webapp only
* update paths @sourcegraph/extensions-client-common/{lib => src}
* remove unneeded workspace for and deps from extensions-client-common
* extensions-client-common compiles
* update paths in browser-extensions
* webapp compiles with ecc node_modules deleted
* compiling after adding back ecc node_modules
* root gulpfile working
* mv packages/webapp -> web
* replace "packages/webapp" with "web"
* mv packages/browser-extensions client/browser
* remove broken phabricator dev script
see https://github.com/sourcegraph/sourcegraph/issues/938
* replace "packages/browser-extensions" with "client/browser"
* mv packages/extensions-client-common shared
* update paths
* yarn.lock for browser ext
* update paths to graphqlschema
* tslint paths
* LinkOrSpan
* update gql
* client/browser typechecks
* client/browser tslint
* tsconfig.json combining
* rearrange gulpfiles
* clean up schema gulp tasks
* before linking a lot of deps
* webpack build working
* more consolidation
* add more common deps
* almost done w browser ext
* WIP just tried adding base.config.ts symlinks true
to try to fix the issues where multiple highlight.js caused hovers to fail due to no highlighting, and multiple rxjs type errors (codeintellify and sourcegraph/sourcegraph) showing up only in webpack. hypothesis is that this is due to webpack not resolving symlinks and so "seeing" multiple pkgs.
* hovers working, fixed resolve issue, just needed to add rxjs to root package.json
* regenerate lockfiles
* add browser ext to procfile
* add back builds
* manually sync contribution.schema.json
* import schema json files directly, no copying
* update import paths
* wip typescript build doc
* move enterprise/src/ into src/ for ease of typescript build
* wip build doc
* wip
* use a single root package.json
* update yarn.lock
* prettier
* set up .bin symlinks
* prettier
* all:typecheck
* fix
* fix all:typecheck
* fix schema output path
* add back .bin links
* fix link
* fix gulpfiles
* only include gulpfile in root tsconfig
* clean up gulpfiles
* generate
* fix node_modules paths in webpack
* sort
* simplify tsconfig
* ignore generated files
* fix bundlesize paths
* fix enterprise build
* fix tsconfigs
* fix back tsconfigs
* fix
* TMP
* fix path
* TIP
* WIP
* transpileonly in tests because we have already typechecked it
* fix browser ext test
* remove browser ext from procfile for now
* fix enterprise paths