vscode/test/unit
Connor Peet 6a847ba6d1
eng: add support for snapshot tests (#190444)
* eng: add support for snapshot tests

This adds Jest-like support for snapshot testing.
Developers can do something like:

```js
await assertSnapshot(myComplexObject)
```

The first time this is run, the snapshot expectation file is written
to a `__snapshots__` directory beside the test file. Subsequent runs
will compare the object to the snapshot, and fail if it doesn't match.

You can see an example of this in the test for snapshots themselves!

After a successful run, any unused snapshots are cleaned up. On a failed
run, a gitignored `.actual` snapshot file is created beside the
snapshot for easy processing and inspection.

Shortly I will do some integration with the selfhost test extension to
allow developers to easily update snapshots from the vscode UI.

For #189680

cc @ulugbekna @hediet

* fix async stacktraces getting clobbered

* random fixes

* comment out leak detector, for now

* add option to snapshot file extension
2023-08-15 12:03:51 -07:00
..
browser eng: add support for snapshot tests (#190444) 2023-08-15 12:03:51 -07:00
electron eng: add support for snapshot tests (#190444) 2023-08-15 12:03:51 -07:00
node eng: add support for snapshot tests (#190444) 2023-08-15 12:03:51 -07:00
assert.js Check notebook URIs in BulkCellEdits (#169669) 2023-01-07 17:35:25 -08:00
coverage.js fix: parse errors in coverage command (#156837) 2022-08-05 18:27:40 +02:00
fullJsonStreamReporter.js eng: add support for snapshot tests (#190444) 2023-08-15 12:03:51 -07:00
README.md chore: update to Electron 22 (#177600) 2023-04-03 09:09:31 +02:00
reporter.js auto-fixed prefer-const violation 2022-06-08 17:49:21 +02:00

Unit Tests

Run (inside Electron)

./scripts/test.[sh|bat]

All unit tests are run inside a Electron renderer environment which access to DOM and Nodejs api. This is the closest to the environment in which VS Code itself ships. Notes:

  • use the --debug to see an electron window with dev tools which allows for debugging
  • to run only a subset of tests use the --run or --glob options
  • use yarn watch to automatically compile changes

For instance, ./scripts/test.sh --debug --glob **/extHost*.test.js runs all tests from extHost-files and enables you to debug them.

Run (inside browser)

yarn test-browser --browser webkit --browser chromium

Unit tests from layers common and browser are run inside chromium, webkit, and (soon'ish) firefox (using playwright). This complements our electron-based unit test runner and adds more coverage of supported platforms. Notes:

  • these tests are part of the continuous build, that means you might have test failures that only happen with webkit on windows or chromium on linux
  • you can run these tests locally via yarn test-browser --browser chromium --browser webkit
  • to debug, open <vscode>/test/unit/browser/renderer.html inside a browser and use the ?m=<amd_module>-query to specify what AMD module to load, e.g file:///Users/jrieken/Code/vscode/test/unit/browser/renderer.html?m=vs/base/test/common/strings.test runs all tests from strings.test.ts
  • to run only a subset of tests use the --run or --glob options

Note: you can enable verbose logging of playwright library by setting a DEBUG environment variable before running the tests (https://playwright.dev/docs/debug#verbose-api-logs)

Run (with node)

yarn test-node --run src/vs/editor/test/browser/controller/cursor.test.ts

Coverage

The following command will create a coverage folder in the .build folder at the root of the workspace:

OS X and Linux

./scripts/test.sh --coverage

Windows

scripts\test --coverage