Commit Graph

31 Commits

Author SHA1 Message Date
Quinn Slack
4002774429
reapply "switch from jest to vitest for faster, simpler tests (#57886)" (#58145)
* 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>
2023-11-07 12:00:18 +02:00
William Bezuidenhout
7f4bebe29d
Revert: bazel+vitest - when running vitests concurrently the target //client/browser:test fails (#58116)
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.
2023-11-06 14:02:35 +02:00
Quinn Slack
ae5325e432
switch from jest to vitest for faster, simpler tests (#57886)
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
2023-11-05 21:57:04 -10:00
Quinn Slack
90c6683218
remove gulp (task runner) (#57963)
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).
2023-10-29 12:09:50 -07:00
Quinn Slack
6bdcd5e59c
simplify tsconfig.json files (#57913) 2023-10-26 03:03:11 -07:00
Quinn Slack
85818110a7
misc improvements to tests to prep for vitest switch (#57904)
* 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
2023-10-26 01:47:40 +00:00
Quinn Slack
59c82bcfb1
disable frontend code coverage tracking (#57820)
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.
2023-10-23 21:29:40 +00:00
Valery Bugakov
ce38bbc724
web: fix pnpm-lock issue (#47478)
Fixes the issue caused by the presence of the `sourcegraph: ''` entry in the `pnpm-lock.yaml`. If we install any new dependency, the `pnpm install` command fails on CI. [Failure example](https://github.com/sourcegraph/sourcegraph/actions/runs/4121774771/jobs/7117792725).
2023-02-09 22:04:31 -08:00
Valery Bugakov
3512fb9aa2
web: sync TS project refenreces (#46407) 2023-01-16 18:55:10 -08:00
Valery Bugakov
b10c94b717
web: eliminate storybook & wildcard circle (#45976) 2023-01-04 18:39:15 -08:00
Taras Yemets
897cc20445
Refactor code-intel extensions bundling for VSCE and browser extension (#40017) 2022-08-09 12:18:57 +03:00
GitStart-SourceGraph
44082f5b73
[SG-33302] Upgrade all client packages to use the latest version of the JSX transform (#34287)
Co-authored-by: gitstart-sourcegraph <gitstart@users.noreply.github.com>
2022-04-22 12:25:38 +01:00
GitStart-SourceGraph
6cb8f5016a
Create a client-api package (#31151) 2022-03-17 01:17:26 -07:00
GitStart-SourceGraph
a39e8c44b6
Move modules to the @sourcegraph/common package into util (#29976)
* Move modules to the @sourcegraph/common package into util

Co-authored-by: gitstart-sourcegraph <gitstart@users.noreply.github.com>
2022-02-08 12:09:56 +07:00
GitStart-SourceGraph
e7e705c808
[SG-28893] refactor: extract graphql folder into a new http-client package. (#29346)
Co-authored-by: gitstart-sourcegraph <gitstart@users.noreply.github.com>
2022-01-13 18:40:35 +01:00
GitStart-SourceGraph
f9dc317cfe
refactor: extract codeintellify as new package (#29233)
* refactor: extract codeintellify as new package

* feat: add client/codeintellify into lsif-ts

Co-authored-by: gitstart-sourcegraph <gitstart@users.noreply.github.com>
2022-01-10 22:29:47 +07:00
GitStart-SourceGraph
f9ecd86d79
Extract util/errors.ts into a new common package (#29040)
Co-authored-by: gitstart-sourcegraph <gitstart@users.noreply.github.com>
2021-12-24 17:50:53 +07:00
Erik Seliger
c03cc7bd1e
Support multiple GraphQL schema files (#20077)
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`.
2021-04-19 14:35:49 +02:00
Felix Becker
85f198b04c
Move shared branded code to branded/ (#14515) 2020-10-08 15:14:34 +02:00
Felix Becker
45f9839011
Move all client code into client/ folder (#14480) 2020-10-07 22:23:53 +02:00
Felix Becker
cc5de96d4b
mv client/browser browser (#3826)
* mv client/browser browser

* Fix paths

* tslint --fix

* Add back .bin symlink

* Relative path for symlink
2019-05-06 19:36:03 +02:00
Felix Becker
d6a6bdccbf
Use modern browser API (#3606)
* 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
2019-05-03 23:20:47 +02:00
Felix Becker
88537f3ebe
Add WebExtension API polyfill (#3339)
Start of #3200
This will be an ongoing effort.
2019-04-10 16:59:35 +02:00
Felix Becker
66b44fc03f
Add tests for MountGetters (#3264)
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% 🎉
2019-04-08 13:20:57 +02:00
Quinn Slack
00d0eef0c9 remove remnants of safari support in the browser extension (#2294)
followup to https://github.com/sourcegraph/sourcegraph/pull/2122
2019-02-27 12:30:19 +01:00
Loic Guychard
077319232d
Stricter tsconfig for the browser extension (#2411)
* 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
2019-02-25 19:48:03 +01:00
Quinn Slack
d292f16d28
use jest for testing (#1456)
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.
2018-12-16 18:13:40 -08:00
Quinn Slack
98119646c3
clean up extension-related code (#1385)
* 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
2018-12-13 19:16:19 -08:00
Quinn Slack
81526b11ad
clean up extensions UI code (#1073)
See commit messages.

No change in behavior, just code cleanup and simplification.
2018-11-20 03:01:17 -08:00
Isaac Snow
46ff03e3c0
Use puppeteer for browser extension e2e testing (#1022) 2018-11-15 19:07:41 -08:00
Quinn Slack
c4f70b577e
use single root package.json, do not build intermediate shared code (#936)
* 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
2018-11-12 01:05:35 -08:00