Skip to content

Commit 6822493

Browse files
committed
docs: improve docs
1 parent 3088c6a commit 6822493

6 files changed

Lines changed: 107 additions & 42 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ pnpm install
3333
# and the modified code does not need to be built again.
3434
pnpm run dev
3535

36+
# link local scaffold to your plugin
37+
cd your-plugin-work-dir/
38+
pnpm link ../zotero-plugin-scaffold
39+
cd zotero-plugin-scaffold/
40+
41+
```
42+
43+
Now you can make changes to Scaffold and test them in your plugin.
44+
45+
When you're done modifying, make sure that you can pass the build and that the code style meets the requirements of this repository.
46+
47+
```bash
3648
# Build
3749
pnpm run build
3850

docs/.vitepress/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ export default defineConfig({
2323
socialLinks: [
2424
{ icon: "github", link: "https://github.com/northword/zotero-plugin-scaffold" },
2525
],
26+
27+
outline: "deep",
2628
},
2729
});

docs/index.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ hero:
1414
features:
1515
- title: Dev Serve
1616
details: Auto reload your plugin when source code changed
17+
link: /serve
1718
- title: Build Plugin
18-
details: TypeScript supported, many utils builders
19-
- title: Pack plugin
20-
details: Pack code to xpi file
19+
details: TypeScript supported, many utils builders, and pack code to xpi
20+
link: /build
21+
- title: Test plugin
22+
details: Out-of-the-box test kits
23+
link: /test
2124
- title: Release
2225
details: Auto bump version, and publish your plugin to GitHub
26+
link: /release
2327
---

docs/quick-start.md

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ pnpm dlx zotero-plugin create
1717

1818
### 01. Install
1919

20-
#### From NPM
21-
2220
```bash
2321
npm install -D zotero-plugin-scaffold
2422

@@ -27,22 +25,6 @@ yarn add -D zotero-plugin-scaffold
2725
pnpm add -D zotero-plugin-scaffold
2826
```
2927

30-
#### From source code
31-
32-
```bash
33-
# clone this repo
34-
git clone https://github.com/northword/zotero-plugin-scaffold.git zotero-plugin-scaffold/
35-
cd zotero-plugin-scaffold/
36-
37-
# build
38-
pnpm install
39-
pnpm build # or pnpm dev
40-
41-
# npm link
42-
cd your-plugin-work-dir/
43-
pnpm link ../zotero-plugin-scaffold
44-
```
45-
4628
### 02. Create a config file
4729

4830
The configuration file needs to be stored in the following location.
@@ -72,7 +54,7 @@ export default defineConfig({
7254
});
7355
```
7456

75-
Full config please refrence in [src/types](./src/types/index.ts).
57+
Full config please refrence in [src/types](https://github.com/northword/zotero-plugin-scaffold/blob/main/src/types/config.ts).
7658

7759
### 03. Create a env file
7860

docs/release.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
# Release
2+
3+
我们都知道,对于一个插件的发布,我们需要手动修改 `manifest.json` 中的 `version` 值,然后将其打包,上传到某个地方,随后,我们还需要更新 `update.json` 中的版本号和链接。
4+
5+
为了保持 Git 记录,我们在修改 version 值后,还需要提交代码并为这个提交添加 tag。
6+
7+
—— 这太麻烦了!
8+
9+
在 Scaffold 中,你只需要运行 `zotero-plugin release`,然后选择一个你需要的版本号,一切都将自动运行。

docs/test.md

Lines changed: 77 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
# Testing
22

3-
`zotero-plugin-scaffold` can run [mocha](https://mochajs.org/)/[chai](https://www.chaijs.com/)-based tests against a live Zotero instance via a proxy plugin.
4-
A temporary profile and data directory will be created when launching Zotero,
5-
so tests can be run locally on the system Zotero installation.
3+
`zotero-plugin-scaffold` can run [Mocha](https://mochajs.org/) / [Chai](https://www.chaijs.com/)-based tests against a live Zotero instance via a proxy plugin.
64

7-
## Configuration
5+
A temporary profile and data directory will be created when launching Zotero, so tests can be run locally on the system Zotero installation.
86

9-
> [!TIP]
10-
> See the `TestConfig` interface in [`src/types/config.ts`](./src/types/config.ts) for full documentation
7+
## Why
118

12-
After configuring your project to be built with `zotero-plugin-scaffold`,
13-
add a `test` object to your configuration:
9+
Since Zotero is a browser environment and has a lot of private APIs, if we use the mainstream Node-side testing scheme, we will inevitably need to mock a lot of methods, which will distort the test results.
1410

15-
```js
11+
In Scaffold, we use mocha as the testing framework, which is a simple but flexible enough testing framework for the browser side. We also use chai as an assertion library.
12+
13+
When we start a test, we generate a temporary plugin in `.scaffold/test/resource/` that we use to run the test. Iterate through the test files in the `test.entries` directory and compile them in `.scaffold/test/resource/content`.
14+
15+
When Zotero starts up, it loads your plugin and the test plugin that was just generated separately, so we have complete access to all the APIs and can use them for testing.
16+
17+
## Usage
18+
19+
### Configuring Test Options
20+
21+
After configuring your project to be built with `zotero-plugin-scaffold`, add a `test` object to your configuration:
22+
23+
```ts twoslash
1624
export default defineConfig({
1725
// ...
1826
test: {
1927
// Directories containing *.spec.js tests
20-
entries: ["test/"],
21-
// Abort the test when the first test fails
22-
abortOnFail: false,
28+
entries: ["test"],
2329
// Exit Zotero when the test is finished.
2430
exitOnFinish: true,
2531
// Function string that returns the initialization status of the plugin.
@@ -28,34 +34,85 @@ export default defineConfig({
2834
// if your plugin created a `MyPlugin` object beneath `Zotero` and it set an
2935
// `initialized` field to `true` at the end of its `startup` bootstrap method...
3036
waitForPlugin: `() => Zotero.MyPlugin.initialized`,
31-
// Run tests using xvfb without launching a Zotero window
32-
// (Linux only. defaults `true` in CI. Both xvfb and Zotero are installed automatically)
33-
headless: false,
3437
}
3538
});
3639
```
3740

41+
::: tip
42+
43+
See the `TestConfig` interface in [`src/types/config.ts`](https://github.com/northword/zotero-plugin-scaffold/blob/main/src/types/config.ts) for full documentation.
44+
45+
:::
46+
3847
Add a script to `package.json`:
3948

4049
```json
4150
{
4251
"scripts": {
43-
"...": "...",
44-
"test": "zotero-plugin test --abort-on-fail --exit-on-finish"
52+
"test": "zotero-plugin test"
4553
}
4654
}
4755
```
4856

49-
## CI
57+
### Install Mocha and Chai
58+
59+
We recommend that you install `mocha.js` locally as a development dependency, as this will avoid some potential dependency conflicts:
60+
61+
```bash
62+
npm install -D mocha @types/mocha @types/chai
63+
```
64+
65+
When Scaffold detects your locally installed mocha, it will automatically use your installed mocha, otherwise Scaffold will get the latest version of mocha from NPM.
66+
67+
Since the ESM import issue for Chai has not been resolved, chai will always use the remote version.
68+
69+
The mocha and chai downloaded from the remote will be cached in the `.scaffold/cache` directory, and you can delete the cache if you need to in order to force Scaffold to update their versions.
70+
71+
### Write Your Test Cases
72+
73+
You can then write your test file, see [Mocha](https://mochajs.org/) and [Chai](https://www.chaijs.com/) for syntax.
74+
75+
### Run Test
76+
77+
一旦你完成测试代码的编写,你可以通过 `npm run test` 来启动测试。
78+
79+
`zotero-plugin test` 也提供了一些命令行参数,以便你可以覆盖配置文件中的设置,你可以通过 `zotero-plugin test --help` 来查看:
80+
81+
```bash
82+
$ pnpm zotero-plugin test --help
83+
Usage: cli test [options]
84+
85+
Run tests
86+
87+
Options:
88+
--abort-on-fail Abort the test suite on first failure
89+
--exit-on-finish Exit the test suite after all tests have run
90+
-h, --help display help for command
91+
```
92+
93+
## Watch Mode
94+
95+
In watch mode, Scaffold will:
96+
97+
- When the source code changes, it will automatically recompile the source code, reload the plugins and re-run the tests;
98+
- When the test code changes, it will automatically re-run the tests;
5099

51-
Tests can be run headlessly, e.g. on Github Actions:
100+
This feature is not yet complete.
101+
102+
## Run Test on CI
103+
104+
Most of the time, we want tests to run automatically on CI services such as GitHub Actions, for which we provide `headless` mode.
105+
106+
In general, when we detect that you are running tests on a CI service, we will automatically enable headless mode. If you have a need to use headless locally, you just need to pass `headless` in the cli parameter or set `test.headless: true` in the configuration.
52107

53108
::: warning
54109

55-
Currently ubuntu must be pinned lower than `24.04`, see [`#74`](https://github.com/northword/zotero-plugin-scaffold/issues/74)
110+
Scaffold's built-in headless mode is only supported on Ubuntu 22.04, 24.04. If you are using a different Linux distribution, manually configure the headless environment, set Scaffold's `test.headless` to `false`, and start the test using something like `xvfb-run npm run test`, etc.
56111

57112
:::
58113

114+
For tests running on GitHub Actions, this is a typical workflow template:
115+
59116
```yaml
60117
name: test
61118

0 commit comments

Comments
 (0)