Testing
Summary
Writing and running tests in Dendron
Writing Tests
Depending on the package you are working on, tests are handled differently
- If you are writing tests for Plugin Core, see here.
- If you are writing tests for NextJS Template, see here
- If you are writing tests for any other package, see here
For all tests, we use the GIVEN-WHEN-THEN
style described in Style when writing test.
Executing Tests
-
For Plugin Core, see run all plugin tests
-
For Dendron CLI, see Run Task
-
For any other package, see run other tests
-
NOTE: Dendron has automated tests that run on every pull request - if you are unable to run tests locally, you can also wait for the pull request to finish running the test
-
NOTE: If you running MacOS or Linux, pay special attention to the Windows output and vice versa if you are developing on Windows
Snapshot Testing
Snapshot testing lets us assert that certain outputs of a piece of code is staying the same after changes. This is a very powerful tool because it lets us easily test for outputs that we know that will (should) be constant.
That being said, snapshot tests should not be considered part of unit testing, or testing for a certain functional aspect of code. It also shouldn't replace end-to-end testing, since snapshot tests are only verifying the output, and not the behavior. The output can look the same at the end but could have gotten there in a way that you did not intend to.
While snapshot tests provides us with some great power, it has drawbacks when we aren't mindful about using them.
This note will go over when to write snapshot tests, some common pitfalls, and how to avoid them.
Manual Testing
See manual Testing
Test Utilities
Dendron provides many utilities to more easily setup tests. See provided utilities in Test Utils
Presets
When setting up a mock workspace, Dendron provides multiple pre-configured notes and vaults that can be tested against.
Low level presets (single note) can be found in Note Presets
Higher level presets (multiple notes can be found in Note Collection Presets
More about preset testing in Engine
Custom Notes
If you need to create ad hoc notes, you can use createNote function.
Checklist
Basics
- Write Tests
- Confirm existing tests pass
- Confirm manual testing
- Common cases tested
- 1-2 Edge cases tested
- If your tests changes an existing snapshot
Extended
-
If you are adding a new language feature (graphically visible in VS Code/preview/publishing), an example is included in the test workspace
-
CSS
- display is correct for following dimensions
- sm: screen ≥ 576px, eg. iphonex, (375x812)
- lg: screen ≥ 992px
- xxl: screen ≥ 1600px eg. mac (1600x900)
- display is correct for following browsers (across the various dimensions)
- safari
- firefox
- chrome
- display is correct for following dimensions
Troubleshooting
One of the tests failed in github actions
See if its timeout related. We have a few tests that are unfortunately flaky. Examples include:
- timeout due to pulling down antd
- timeout with
DefinitionProvider
If a single test failed, its usually fine to ignore it. If you want to be certain, you can follow the instructions here.
Cannot register "..."
This happens when you reload the extension host when working on the plugin. To fix, restart the debug and build task for the plugin.
See example in here
Cook
Backlinks