Add a testing section in README

This commit is contained in:
hjonasson 2023-11-17 11:18:36 +13:00
parent eeeb774668
commit 5e756acd75
No known key found for this signature in database
GPG Key ID: 68D22124ADDEEB04
1 changed files with 60 additions and 42 deletions

View File

@ -8,6 +8,7 @@ The repo depends on the latest plugin API (obsidian.d.ts) in Typescript Definiti
**Note:** The Obsidian API is still in early alpha and is subject to change at any time!
This sample plugin demonstrates some of the basic functionality the plugin API can do.
- Adds a ribbon icon, which shows a Notice when clicked.
- Adds a command "Open Sample Modal" which opens a Modal.
- Adds a plugin setting tab to the settings page.
@ -53,11 +54,28 @@ Quick starting guide for new plugin devs:
- `npm i` or `yarn` to install dependencies.
- `npm run dev` to start compilation in watch mode.
## Testing
There is a setup for writing unit tests using [`Jest`](https://jestjs.io/). To run the test suite you can run
```BASH
npm run test
```
or in watch mode
```BASH
npm run test:watch
```
Due to the Obsidian source code not being open-source Jest's more common mocking patterns don't work, such as `jest.mock('obsidian')`. Instead we use [Jest's manual mocks](https://jestjs.io/docs/manual-mocks) by writing a partial mock module in [`__mocks__/obsidian.js`](./__mocks__/obsidian.js). Note that it does not contain a full mock of `obsidian` and you might need to extend it to test your plugin. If you do, please consider adding your extension to this repo.
## Manually installing the plugin
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`.
## Improve code quality with eslint (optional)
- [ESLint](https://eslint.org/) is a tool that analyzes your code to quickly find problems. You can run ESLint against your plugin to find common bugs and ways to improve your code.
- To use eslint with this project, make sure to install eslint from terminal:
- `npm install -g eslint`