wdio-obsidian-service 1.3.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,37 +1,35 @@
1
- [![NPM](https://img.shields.io/npm/v/wdio-obsidian-service)](https://www.npmjs.com/package/wdio-obsidian-service)
2
- # WDIO Obsidian Service
3
-
4
- `wdio-obsidian-service` lets you test [Obsidian](https://obsidian.md) plugins end-to-end using
5
- [WebdriverIO](https://webdriver.io). The service can:
6
- - Download and install Obsidian
7
- - Test your plugin on different Obsidian app versions and installer/electron versions
8
- - Download Chromedriver matching the Obsidian electron version
9
- - Sandbox Obsidian so tests don't interfere with your system Obsidian installation or each other
10
- - Run tests in parallel
11
- - Open and switch between test vaults during your tests
12
- - Provide helper functions for common testing tasks
13
- - Run tests in GitHub CI
1
+ # WDIO Obsidian Service [![NPM](https://img.shields.io/npm/v/wdio-obsidian-service)](https://www.npmjs.com/package/wdio-obsidian-service)
2
+
3
+ Test your [Obsidian](https://obsidian.md) plugins end-to-end using [WebdriverIO](https://webdriver.io)!
4
+
5
+ WDIO Obsidian Service can:
6
+ - 📥 Download and test multiple versions of Obsidian
7
+ - 💻📱 Run tests on Windows, macOS, Linux, and Android
8
+ - 📦 Sandbox Obsidian so tests don't interfere with your system or each other
9
+ - 📂 Open and switch between vaults
10
+ - 🛠️ Provide helper functions for common testing tasks
11
+ - 🤖 Run tests in GitHub CI
14
12
 
15
13
  ## Installation and Setup
16
- If you want to get going quickly, you can use the
17
- [wdio-obsidian-service sample plugin](https://github.com/jesse-r-s-hines/wdio-obsidian-service-sample-plugin) which has
18
- all the setup you need to build and end-to-end test Obsidian plugins, including GitHub CI workflows.
14
+
15
+ If you want to get going quickly, you can use the [wdio-obsidian-service sample plugin](https://github.com/jesse-r-s-hines/wdio-obsidian-service-sample-plugin) as a template which has everything already set up to run end-to-end tests, including GitHub CI workflows.
19
16
 
20
17
  See also: [WebdriverIO | Getting Started](https://webdriver.io/docs/gettingstarted).
21
18
 
22
- To set up wdio-obsidian-service manually, run the WebdriverIO Starter Toolkit:
19
+ To set up `wdio-obsidian-service` run the WebdriverIO Starter Toolkit:
23
20
  ```bash
24
21
  npm init wdio@latest .
25
22
  ```
26
23
  Leave all options as default (including `E2E Testing - of Web or Mobile Applications`).
27
- Delete the generated `pageobjects` dir for now, or replace it with a stub for later.
24
+
25
+ Delete the generated `test/pageobjects` dir for now, or replace it with a stub for later.
28
26
 
29
27
  Then install `wdio-obsidian-service` and other deps:
30
28
  ```bash
31
29
  npm install --save-dev wdio-obsidian-service wdio-obsidian-reporter mocha @types/mocha
32
30
  ```
33
31
 
34
- And add this to `tsconfig.json`:
32
+ Add this to `tsconfig.json`:
35
33
  ```json
36
34
  {
37
35
  "compilerOptions": {
@@ -45,17 +43,14 @@ And add this to `tsconfig.json`:
45
43
  }
46
44
  ```
47
45
 
48
- Set up your `wdio.conf.ts` like so:
46
+ Rename `wdio.conf.ts` to `wdio.conf.mts` and set it up like so:
49
47
  ```ts
50
48
  import * as path from "path"
51
49
 
52
50
  export const config: WebdriverIO.Config = {
53
51
  runner: 'local',
54
-
55
- specs: [
56
- './test/specs/**/*.e2e.ts'
57
- ],
58
-
52
+ framework: 'mocha',
53
+ specs: ['./test/specs/**/*.e2e.ts'],
59
54
  // How many instances of Obsidian should be launched in parallel
60
55
  maxInstances: 4,
61
56
 
@@ -74,26 +69,24 @@ export const config: WebdriverIO.Config = {
74
69
  },
75
70
  }],
76
71
 
77
- framework: 'mocha',
78
72
  services: ["obsidian"],
79
73
  // You can use any wdio reporter, but they show the Chromium version
80
74
  // instead of the Obsidian version. obsidian reporter just wraps
81
75
  // spec reporter to show the Obsidian version.
82
76
  reporters: ['obsidian'],
83
77
 
78
+ // wdio-obsidian-service will download Obsidian versions into this directory
79
+ cacheDir: path.resolve(".obsidian-cache"),
84
80
  mochaOpts: {
85
81
  ui: 'bdd',
86
82
  timeout: 60000,
87
83
  // You can set mocha settings like "retry" and "bail"
88
84
  },
89
-
90
- cacheDir: path.resolve(".obsidian-cache"),
91
-
92
85
  logLevel: "warn",
93
86
  }
94
87
  ```
95
88
 
96
- And create a file `test/specs/test.e2e.ts` with something like:
89
+ And create a test file `test/specs/test.e2e.ts`:
97
90
  ```ts
98
91
  import { browser } from '@wdio/globals'
99
92
 
@@ -101,7 +94,7 @@ describe('Test my plugin', function() {
101
94
  before(async function() {
102
95
  // You can create test vaults and open them with reloadObsidian
103
96
  // Alternatively if all your tests use the same vault, you can
104
- // set the default vault in the wdio.conf.ts.
97
+ // set the default vault in the wdio.conf.mts.
105
98
  await browser.reloadObsidian({vault: "./test/vaults/simple"});
106
99
  })
107
100
  it('test command open-sample-modal-simple', async () => {
@@ -115,8 +108,14 @@ describe('Test my plugin', function() {
115
108
  })
116
109
  ```
117
110
 
118
- `wdio-obsidian-service` has a few helper functions that can be useful in your wdio conf, such as `obsidianBetaAvailable`
119
- which checks if there's a current Obsidian beta and you have the credentials to download it. E.g. to test on your `minAppVersion`, `latest`, and `latest-beta` if it's available, use:
111
+ Now you can run your tests with
112
+ ```bash
113
+ wdio run ./wdio.conf.mts
114
+ ```
115
+
116
+ Add that command to your `package.json` scripts and you are good to go!
117
+
118
+ `wdio-obsidian-service` has a few helper functions that can be useful in your `wdio.conf.mts`, such as `obsidianBetaAvailable` which checks if there's a current Obsidian beta and you have the credentials to download it. E.g. to test on your plugin on Obsidian `latest`, `latest-beta`, and your `minAppVersion` use:
120
119
  ```ts
121
120
  import { obsidianBetaAvailable } from "wdio-obsidian-service";
122
121
  const cacheDir = path.resolve(".obsidian-cache");
@@ -146,46 +145,19 @@ export const config: WebdriverIO.Config = {
146
145
  ```
147
146
  Note, to use top-level await you'll need to rename `wdio.conf.ts` to `wdio.conf.mts` so it's loaded as an ESM module.
148
147
 
149
- You can see the [sample plugin](https://github.com/jesse-r-s-hines/wdio-obsidian-service-sample-plugin) for more
150
- examples of how to write your wdio conf and e2e tests.
151
-
152
- ### Platform Support
153
- `wdio-obsidian-service` works on Windows, Linux, and MacOS.
154
-
155
- On Windows, you'll need to install [7zip](https://www.7-zip.org) and add it to the PATH so the service can extract the
156
- Obsidian installer. Windows firewall will sometimes complain about NodeJS, you can just cancel the popup it makes.
157
-
158
- Currently `wdio-obsidian-service` only works for Obsidian Desktop. Testing Obsidian Mobile may be added in the future
159
- using WDIO + Appium.
160
-
161
- ### Test Frameworks
162
- WebdriverIO can run tests using [Mocha](https://mochajs.org), [Jasmine](https://jasmine.github.io), and
163
- [Cucumber](https://cucumber.io/). Mocha is the easiest to set up and is used in all the wdio-obsidian-service examples.
164
- Mocha can also run your unit tests, typically with the addition of an assertion library like
165
- [Chai](https://www.chaijs.com). You can't run WebdriverIO using [Jest](https://jestjs.io), but if you already have Jest
166
- unit tests (or just prefer Jest) you can easily continue using Jest for your unit tests and Mocha just for your e2e
167
- tests. The built-in WebdriverIO [expect](https://webdriver.io/docs/api/expect-webdriverio) is very similar to Jest
168
- matchers, so should be familiar to use.
148
+ See the [sample plugin](https://github.com/jesse-r-s-hines/wdio-obsidian-service-sample-plugin) for more examples of how to write your `wdio.conf.mts` and e2e tests.
169
149
 
170
150
  ## Usage
171
151
 
172
152
  ### Obsidian App vs Installer Versions
173
- Obsidian is distributed in two parts, the "installer" which is the executable containing Electron, and the "app" which
174
- is a bundle of JavaScript containing the Obsidian code. Obsidian's self-update system only updates the app JS bundle,
175
- and not the base installer/Electron version. This makes Obsidian's auto-update fast as it only needs to download a few
176
- MiB of JS instead of all of Electron. But, it means different users with the same Obsidian app version may be running on
177
- different versions of Electron, which can cause subtle differences in plugin behavior.
178
153
 
179
- You can check your current Obsidian app and installer versions in the General settings tab.
180
-
181
- You can specify both `appVersion` and `installerVersion` in your `wdio.conf.mts` capabilities section.
154
+ Obsidian Desktop is distributed in two parts, the "installer" which is the executable containing Electron, and the "app" which is a bundle of JavaScript containing the Obsidian code. Obsidian's self-update system only updates the app JS bundle, and not the base installer/Electron version. This makes Obsidian's auto-update fast as it only needs to download a few MiB of JS instead of all of Electron. But, it means different users with the same Obsidian app version may be running on different versions of Electron, which can cause subtle differences in plugin behavior. You can specify both `appVersion` and `installerVersion` in your `wdio.conf.mts` capabilities section.
182
155
 
183
156
  To set the app version use `browserVersion` or `'wdio:obsidianOptions'.appVersion`. It can be set to one of:
184
157
  - a specific version string like "1.7.7"
185
158
  - "latest": run the latest non-beta Obsidian version
186
159
  - "latest-beta": run the latest beta Obsidian version (or latest is there is no current beta)
187
- - To download Obsidian beta versions you'll need to have an Obsidian account with Catalyst and set the
188
- `OBSIDIAN_USERNAME` and `OBSIDIAN_PASSWORD` environment variables. 2FA needs to be disabled.
160
+ - To download Obsidian beta versions you'll need have an Obsidian Insiders account and either set the `OBSIDIAN_EMAIL` and `OBSIDIAN_PASSWORD` env vars (`.env` is supported) or pre-download the Obsidian beta with `npx obsidian-launcher download -v latest-beta`.
189
161
  - "earliest": run the `minAppVersion` set in your plugin's `manifest.json`
190
162
 
191
163
  To set the installer version use `'wdio:obsidianOptions'.installerVersion`. It can be set to one of:
@@ -193,18 +165,13 @@ To set the installer version use `'wdio:obsidianOptions'.installerVersion`. It c
193
165
  - "latest": run the latest Obsidian installer compatible with `appVersion`
194
166
  - "earliest": run the oldest Obsidian installer compatible with `appVersion`
195
167
 
196
- You can see more configuration options for the capabilities
197
- [here](https://jesse-r-s-hines.github.io/wdio-obsidian-service/wdio-obsidian-service/ObsidianCapabilityOptions.html).
168
+ You can see more configuration options for the capabilities [here](https://jesse-r-s-hines.github.io/wdio-obsidian-service/wdio-obsidian-service/ObsidianCapabilityOptions.html).
198
169
 
199
170
  ### Opening and Switching between Vaults
200
- If all your tests use the same vault, you can set the vault in the `wdio:obsidianOptions` capabilities section. If you
201
- need to switch between vaults during your test you can use the `reloadObsidian` or `resetVault` functions. These can
202
- also be useful for reseting state between tests to avoid tests affecting each other (such as in Mocha `before` and
203
- `beforeEach` hooks).
204
-
205
- `browser.reloadObsidian` completely reboots Obsidian with a fresh copy of the vault. This will clear all state, but is
206
- quite slow so avoid calling it too often.
207
- E.g.
171
+
172
+ If all your tests use the same vault, you can set the vault in the `wdio:obsidianOptions` capabilities section. If you need to switch between vaults during your test you can use the `reloadObsidian` or `resetVault` functions. These can also be useful for resetting state between tests (such as in Mocha `before` and `beforeEach` hooks).
173
+
174
+ `browser.reloadObsidian` reboots Obsidian with a fresh copy of the vault. This will clear all state, but is quite slow. E.g.
208
175
  ```ts
209
176
  it("test the thing", async function() {
210
177
  await browser.reloadObsidian({vault: "test/vaults/simple"});
@@ -212,9 +179,7 @@ it("test the thing", async function() {
212
179
  })
213
180
  ```
214
181
 
215
- `obsidianPage.resetVault` is a faster alternative to `reloadObsidian`. It resets vault files to their original state in
216
- place without rebooting Obsidian. It only resets vault files, not Obsidian configuration etc, but in many cases that's
217
- all you need. You'll often want to put this in a `beforeEach`.
182
+ `obsidianPage.resetVault` is a faster alternative to `reloadObsidian`. It updates the vault by modifying files in place without reloading Obsidian. It only updates vault files, not Obsidian configuration etc, but in many cases that's all you need. You'll often want to put this in a `beforeEach`.
218
183
  ```ts
219
184
  import { obsidianPage } from 'wdio-obsidian-service';
220
185
  it("test the thing", async function() {
@@ -226,15 +191,112 @@ it("test the thing", async function() {
226
191
  })
227
192
  ```
228
193
 
194
+ ## Platform Support
195
+
196
+ `wdio-obsidian-service` can test Obsidian desktop on Windows, MacOS, and Linux.
197
+
198
+ There are two approaches to testing Obsidian mobile. You can emulate the mobile UI in desktop app, which is easy to set up but an imperfect emulation of mobile. Or you can run tests on the real mobile app using an Android Virtual Device (avd). `wdio-obsidian-service` supports both options.
199
+
200
+ Testing on iOS is currently not supported.
201
+
202
+ ### Mobile Emulation
203
+
204
+ Testing your plugin with "mobile emulation" is very easy to set up. Just add a capability like this in your `wdio.conf.mts`:
205
+ ```js
206
+ // ...
207
+ capabilities: [{
208
+ browserName: "obsidian",
209
+ browserVersion: "latest",
210
+ 'wdio:obsidianOptions': {
211
+ emulateMobile: true,
212
+ },
213
+ 'goog:chromeOptions': {
214
+ mobileEmulation: {
215
+ // can also set deviceName: "iPad" etc. instead of hard-coding size
216
+ deviceMetrics: { width: 390, height: 844 },
217
+ },
218
+ },
219
+ }],
220
+ ```
221
+
222
+ This will use Obsidian's [app.emulateMobile](https://docs.obsidian.md/Plugins/Getting+started/Mobile+development#Emulate+mobile+device+on+desktop) to test the mobile UI on the Electron desktop app. Note that the real Obsidian mobile app runs on [Capacitor.js ](https://capacitorjs.com) instead of Electron, so there are various platform differences that can't be properly emulated this way. E.g. Capacitor doesn't have access to node and Electron APIs, and has more limited access to the operating system. But if your plugin isn't directly interacting with the operating system or any advanced Electron APIs using mobile emulation will likely be sufficient.
223
+
224
+
225
+ ### Android
226
+
227
+ You can also test on the real mobile app using [Appium](https://appium.io) and [Android Studio](https://developer.android.com/studio). This is a bit more work to set up, but is a more accurate test.
228
+
229
+ To set this up, install Appium and the Appium Android driver:
230
+ ```bash
231
+ npm install --save-dev appium appium-uiautomator2-driver @wdio/appium-service
232
+ ```
233
+
234
+ Then follow these instructions: [Appium - Set up Android automation requirements](https://appium.io/docs/en/2.19/quickstart/uiauto2-driver/#set-up-android-automation-requirements)
235
+
236
+ You can skip the `appium driver install ...` bit as you already installed the driver via npm above.
237
+
238
+ Then use the Android Studio "Virtual Device Manager" to create a Android Virtual Device and name it `obsidian_test`.
239
+
240
+ Then set up a new `wdio.mobile.conf.mts` file like so:
241
+ ```ts
242
+ import * as path from "path"
243
+
244
+ export const config: WebdriverIO.Config = {
245
+ runner: 'local',
246
+ framework: 'mocha',
247
+ specs: ['./test/specs/**/*.e2e.ts'],
248
+
249
+ maxInstances: 1, // can't do android tests in parallel :(
250
+
251
+ capabilities: [{
252
+ browserName: "obsidian",
253
+ browserVersion: "latest",
254
+ platformName: 'Android',
255
+ 'appium:automationName': 'UiAutomator2',
256
+ 'appium:avd': "obsidian_test",
257
+ 'appium:enforceAppInstall': true,
258
+ 'wdio:obsidianOptions': {
259
+ plugins: ["."],
260
+ vault: "test/vaults/simple",
261
+ },
262
+ }],
263
+
264
+ services: ["obsidian"],
265
+ reporters: ['obsidian'],
266
+
267
+ cacheDir: path.resolve(".obsidian-cache"),
268
+ mochaOpts: {
269
+ ui: 'bdd',
270
+ timeout: 60000,
271
+ },
272
+ logLevel: "warn",
273
+ }
274
+ ```
275
+ and run
276
+ ```bash
277
+ wdio run ./wdio.mobile.conf.mts
278
+ ```
279
+
280
+ This will spin up the Android Virtual Device, install Obsidian in it, and run your tests on it.
281
+
282
+ See also: The [sample plugin](https://github.com/jesse-r-s-hines/wdio-obsidian-service-sample-plugin) for an example `wdio.mobile.conf.mts` file, [Appium](https://appium.github.io/appium.io/docs/en/writing-running-appium/caps) and [Appium UiAutomator2](https://github.com/appium/appium-uiautomator2-driver?tab=readme-ov-file#capabilities) for more capability options you can use
283
+
284
+ ## Test Frameworks
285
+
286
+ WebdriverIO can run tests using [Mocha](https://mochajs.org), [Jasmine](https://jasmine.github.io), and [Cucumber](https://cucumber.io/). Mocha is the easiest to set up and is used in all the `wdio-obsidian-service` examples. Mocha can also run your unit tests, typically with the addition of an assertion library like [Chai](https://www.chaijs.com). You can't run WebdriverIO using [Jest](https://jestjs.io), but if you already have Jest unit tests (or just prefer Jest) you can easily continue using Jest for your unit tests and Mocha just for your e2e tests. The built-in WebdriverIO [expect](https://webdriver.io/docs/api/expect-webdriverio) is very similar to Jest matchers, so should be familiar to use.
287
+
229
288
  ### API Docs
230
- API docs, including all configuration options and helper functions, are available
231
- [here](https://jesse-r-s-hines.github.io/wdio-obsidian-service/wdio-obsidian-service/README.html).
289
+
290
+ API docs, including all configuration options and helper functions, are available [here](https://jesse-r-s-hines.github.io/wdio-obsidian-service/wdio-obsidian-service/README.html).
291
+
292
+ Some key bits:
293
+ - See [ObsidianCapabilityOptions](https://jesse-r-s-hines.github.io/wdio-obsidian-service/wdio-obsidian-service/ObsidianCapabilityOptions.html) for all the options you can pass to `wdio:obsidianOptions` in your wdio.conf.mts
294
+ - See [ObsidianBrowserCommands](https://jesse-r-s-hines.github.io/wdio-obsidian-service/wdio-obsidian-service/ObsidianBrowserCommands.html) and [ObsidianPage](https://jesse-r-s-hines.github.io/wdio-obsidian-service/wdio-obsidian-service/ObsidianPage.html) for various useful helper functions
295
+
296
+ And of course, see also [WDIO's documentation](https://webdriver.io/docs/gettingstarted) and the [many browser commands it provides](https://webdriver.io/docs/api/browser).
232
297
 
233
298
  ### GitHub CI Workflows
234
- The sample plugin has workflows set up to release and test your plugin, which you can see
235
- [here](https://github.com/jesse-r-s-hines/wdio-obsidian-service-sample-plugin#github-workflows).
299
+ The sample plugin has workflows set up to release and test your plugin, which you can see [here](https://github.com/jesse-r-s-hines/wdio-obsidian-service-sample-plugin#github-workflows).
236
300
 
237
301
  ### obsidian-launcher CLI
238
- `wdio-obsidian-service` depends on `obsidian-launcher` so the `obsidian-launcher` CLI is also available, with some
239
- commands for launching different Obsidian versions. CLI docs available
240
- [here](https://jesse-r-s-hines.github.io/wdio-obsidian-service/obsidian-launcher/README.html#cli).
302
+ `wdio-obsidian-service` depends on [obsidian-launcher](../../packages/obsidian-launcher/README.md) so the `obsidian-launcher` CLI is also available, with some commands for launching different Obsidian versions. CLI docs available [here](https://jesse-r-s-hines.github.io/wdio-obsidian-service/obsidian-launcher/README.html#cli).
File without changes