obsidian-plugin-dev-kit 0.0.0-stage → 0.3.2
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/LICENSE +21 -0
- package/README.md +223 -2
- package/bin/opdk.js +34 -0
- package/dist/build/args.d.ts +10 -0
- package/dist/build/args.js +45 -0
- package/dist/build/bundle-check.d.ts +17 -0
- package/dist/build/bundle-check.js +42 -0
- package/dist/build/bundle-file.d.ts +4 -0
- package/dist/build/bundle-file.js +29 -0
- package/dist/build/commands.d.ts +5 -0
- package/dist/build/commands.js +109 -0
- package/dist/build/config.d.ts +3 -0
- package/dist/build/config.js +103 -0
- package/dist/build/css-imports.d.ts +23 -0
- package/dist/build/css-imports.js +50 -0
- package/dist/build/css-step.d.ts +10 -0
- package/dist/build/css-step.js +27 -0
- package/dist/build/css.d.ts +24 -0
- package/dist/build/css.js +47 -0
- package/dist/build/options.d.ts +55 -0
- package/dist/build/options.js +70 -0
- package/dist/build/release.d.ts +5 -0
- package/dist/build/release.js +34 -0
- package/dist/build/report.d.ts +7 -0
- package/dist/build/report.js +16 -0
- package/dist/build/vault.d.ts +26 -0
- package/dist/build/vault.js +290 -0
- package/dist/build-info.json +1 -0
- package/dist/cli/argv.d.ts +14 -0
- package/dist/cli/argv.js +18 -0
- package/dist/cli/commands.d.ts +3 -0
- package/dist/cli/commands.js +7 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +23 -0
- package/dist/cli/process-reporter.d.ts +5 -0
- package/dist/cli/process-reporter.js +15 -0
- package/dist/cli/registry.d.ts +4 -0
- package/dist/cli/registry.js +15 -0
- package/dist/cli/reporter.d.ts +53 -0
- package/dist/cli/reporter.js +100 -0
- package/dist/cli/run.d.ts +9 -0
- package/dist/cli/run.js +61 -0
- package/dist/cli/types.d.ts +27 -0
- package/dist/cli/types.js +1 -0
- package/dist/cli/version.d.ts +13 -0
- package/dist/cli/version.js +61 -0
- package/dist/config/define-config.d.ts +3 -0
- package/dist/config/define-config.js +4 -0
- package/dist/config/load-config.d.ts +6 -0
- package/dist/config/load-config.js +70 -0
- package/dist/config/manifest.d.ts +3 -0
- package/dist/config/manifest.js +72 -0
- package/dist/config/types.d.ts +146 -0
- package/dist/config/types.js +23 -0
- package/dist/demo/args.d.ts +4 -0
- package/dist/demo/args.js +13 -0
- package/dist/demo/checks.d.ts +56 -0
- package/dist/demo/checks.js +124 -0
- package/dist/demo/commands.d.ts +3 -0
- package/dist/demo/commands.js +65 -0
- package/dist/demo/config.d.ts +57 -0
- package/dist/demo/config.js +337 -0
- package/dist/demo/ffmpeg-run.d.ts +18 -0
- package/dist/demo/ffmpeg-run.js +59 -0
- package/dist/demo/ffmpeg.d.ts +63 -0
- package/dist/demo/ffmpeg.js +111 -0
- package/dist/demo/films.d.ts +46 -0
- package/dist/demo/films.js +134 -0
- package/dist/demo/phone-layout.d.ts +38 -0
- package/dist/demo/phone-layout.js +98 -0
- package/dist/demo/phone-render.d.ts +28 -0
- package/dist/demo/phone-render.js +124 -0
- package/dist/demo/published.d.ts +16 -0
- package/dist/demo/published.js +72 -0
- package/dist/demo/run.d.ts +31 -0
- package/dist/demo/run.js +397 -0
- package/dist/demo/stills.d.ts +21 -0
- package/dist/demo/stills.js +62 -0
- package/dist/e2e/artifacts.d.ts +27 -0
- package/dist/e2e/artifacts.js +90 -0
- package/dist/e2e/cleanup.d.ts +54 -0
- package/dist/e2e/cleanup.js +109 -0
- package/dist/e2e/config.d.ts +9 -0
- package/dist/e2e/config.js +42 -0
- package/dist/e2e/create-test.d.ts +37 -0
- package/dist/e2e/create-test.js +109 -0
- package/dist/e2e/demo/clip.d.ts +21 -0
- package/dist/e2e/demo/clip.js +44 -0
- package/dist/e2e/demo/create-demo.d.ts +42 -0
- package/dist/e2e/demo/create-demo.js +439 -0
- package/dist/e2e/demo/manifest.d.ts +76 -0
- package/dist/e2e/demo/manifest.js +168 -0
- package/dist/e2e/demo/names.d.ts +18 -0
- package/dist/e2e/demo/names.js +44 -0
- package/dist/e2e/demo/options.d.ts +22 -0
- package/dist/e2e/demo/options.js +59 -0
- package/dist/e2e/demo/ownership.d.ts +27 -0
- package/dist/e2e/demo/ownership.js +65 -0
- package/dist/e2e/demo/page-scripts.d.ts +82 -0
- package/dist/e2e/demo/page-scripts.js +250 -0
- package/dist/e2e/demo/png.d.ts +8 -0
- package/dist/e2e/demo/png.js +23 -0
- package/dist/e2e/demo/presets.d.ts +43 -0
- package/dist/e2e/demo/presets.js +20 -0
- package/dist/e2e/demo/privacy.d.ts +18 -0
- package/dist/e2e/demo/privacy.js +30 -0
- package/dist/e2e/demo/still-options.d.ts +22 -0
- package/dist/e2e/demo/still-options.js +68 -0
- package/dist/e2e/demo/types.d.ts +184 -0
- package/dist/e2e/demo/types.js +1 -0
- package/dist/e2e/electron-binary.d.ts +15 -0
- package/dist/e2e/electron-binary.js +30 -0
- package/dist/e2e/fixtures.d.ts +62 -0
- package/dist/e2e/fixtures.js +68 -0
- package/dist/e2e/gate.d.ts +4 -0
- package/dist/e2e/gate.js +8 -0
- package/dist/e2e/global-setup.d.ts +11 -0
- package/dist/e2e/global-setup.js +17 -0
- package/dist/e2e/helpers/commands.d.ts +14 -0
- package/dist/e2e/helpers/commands.js +56 -0
- package/dist/e2e/helpers/create-helpers.d.ts +24 -0
- package/dist/e2e/helpers/create-helpers.js +582 -0
- package/dist/e2e/helpers/device-metrics.d.ts +21 -0
- package/dist/e2e/helpers/device-metrics.js +25 -0
- package/dist/e2e/helpers/ime.d.ts +13 -0
- package/dist/e2e/helpers/ime.js +19 -0
- package/dist/e2e/helpers/layout-page-scripts.d.ts +103 -0
- package/dist/e2e/helpers/layout-page-scripts.js +224 -0
- package/dist/e2e/helpers/layout.d.ts +83 -0
- package/dist/e2e/helpers/layout.js +148 -0
- package/dist/e2e/helpers/mobile.d.ts +31 -0
- package/dist/e2e/helpers/mobile.js +26 -0
- package/dist/e2e/helpers/page-scripts.d.ts +194 -0
- package/dist/e2e/helpers/page-scripts.js +467 -0
- package/dist/e2e/helpers/settings.d.ts +8 -0
- package/dist/e2e/helpers/settings.js +16 -0
- package/dist/e2e/helpers/settle.d.ts +28 -0
- package/dist/e2e/helpers/settle.js +33 -0
- package/dist/e2e/helpers/types.d.ts +193 -0
- package/dist/e2e/helpers/types.js +1 -0
- package/dist/e2e/helpers/view-mode.d.ts +23 -0
- package/dist/e2e/helpers/view-mode.js +35 -0
- package/dist/e2e/index.d.ts +14 -0
- package/dist/e2e/index.js +4 -0
- package/dist/e2e/internals.d.ts +155 -0
- package/dist/e2e/internals.js +8 -0
- package/dist/e2e/obsidian-path.d.ts +17 -0
- package/dist/e2e/obsidian-path.js +31 -0
- package/dist/e2e/options.d.ts +123 -0
- package/dist/e2e/options.js +244 -0
- package/dist/e2e/page-scripts.d.ts +45 -0
- package/dist/e2e/page-scripts.js +53 -0
- package/dist/e2e/peers.d.ts +9 -0
- package/dist/e2e/peers.js +19 -0
- package/dist/e2e/plugins.d.ts +32 -0
- package/dist/e2e/plugins.js +119 -0
- package/dist/e2e/process-tree.d.ts +33 -0
- package/dist/e2e/process-tree.js +133 -0
- package/dist/e2e/readiness.d.ts +23 -0
- package/dist/e2e/readiness.js +63 -0
- package/dist/e2e/seed.d.ts +34 -0
- package/dist/e2e/seed.js +122 -0
- package/dist/e2e/session.d.ts +71 -0
- package/dist/e2e/session.js +266 -0
- package/dist/e2e/vault.d.ts +52 -0
- package/dist/e2e/vault.js +146 -0
- package/dist/e2e/version.d.ts +25 -0
- package/dist/e2e/version.js +40 -0
- package/dist/eslint/index.d.ts +2 -0
- package/dist/eslint/index.js +1 -0
- package/dist/eslint/obsidian-plugin.d.ts +49 -0
- package/dist/eslint/obsidian-plugin.js +115 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/kit/args.d.ts +7 -0
- package/dist/kit/args.js +21 -0
- package/dist/kit/commands.d.ts +3 -0
- package/dist/kit/commands.js +52 -0
- package/dist/kit/files.d.ts +3 -0
- package/dist/kit/files.js +24 -0
- package/dist/kit/pins.d.ts +89 -0
- package/dist/kit/pins.js +178 -0
- package/dist/kit/remote.d.ts +13 -0
- package/dist/kit/remote.js +33 -0
- package/dist/kit/runners.d.ts +11 -0
- package/dist/kit/runners.js +53 -0
- package/dist/kit/terminal-text.d.ts +6 -0
- package/dist/kit/terminal-text.js +20 -0
- package/dist/kit/upgrade.d.ts +26 -0
- package/dist/kit/upgrade.js +162 -0
- package/dist/peers/resolve.d.ts +8 -0
- package/dist/peers/resolve.js +28 -0
- package/dist/peers/versions.d.ts +30 -0
- package/dist/peers/versions.js +32 -0
- package/dist/release/api-check.d.ts +27 -0
- package/dist/release/api-check.js +119 -0
- package/dist/release/args.d.ts +40 -0
- package/dist/release/args.js +120 -0
- package/dist/release/assets.d.ts +21 -0
- package/dist/release/assets.js +35 -0
- package/dist/release/build-check.d.ts +43 -0
- package/dist/release/build-check.js +184 -0
- package/dist/release/build-script.d.ts +12 -0
- package/dist/release/build-script.js +30 -0
- package/dist/release/build-tagged.d.ts +26 -0
- package/dist/release/build-tagged.js +52 -0
- package/dist/release/bump.d.ts +24 -0
- package/dist/release/bump.js +58 -0
- package/dist/release/changelog.d.ts +25 -0
- package/dist/release/changelog.js +148 -0
- package/dist/release/check.d.ts +38 -0
- package/dist/release/check.js +150 -0
- package/dist/release/commands.d.ts +3 -0
- package/dist/release/commands.js +154 -0
- package/dist/release/committed-tree.d.ts +63 -0
- package/dist/release/committed-tree.js +118 -0
- package/dist/release/config.d.ts +3 -0
- package/dist/release/config.js +28 -0
- package/dist/release/gh-access.d.ts +14 -0
- package/dist/release/gh-access.js +45 -0
- package/dist/release/gh.d.ts +10 -0
- package/dist/release/gh.js +33 -0
- package/dist/release/git.d.ts +49 -0
- package/dist/release/git.js +111 -0
- package/dist/release/interrupt.d.ts +30 -0
- package/dist/release/interrupt.js +60 -0
- package/dist/release/json.d.ts +33 -0
- package/dist/release/json.js +81 -0
- package/dist/release/kit-check.d.ts +8 -0
- package/dist/release/kit-check.js +51 -0
- package/dist/release/manifest-rules.d.ts +23 -0
- package/dist/release/manifest-rules.js +255 -0
- package/dist/release/preflight.d.ts +10 -0
- package/dist/release/preflight.js +65 -0
- package/dist/release/problems.d.ts +24 -0
- package/dist/release/problems.js +11 -0
- package/dist/release/project-files.d.ts +14 -0
- package/dist/release/project-files.js +16 -0
- package/dist/release/publish-command.d.ts +21 -0
- package/dist/release/publish-command.js +83 -0
- package/dist/release/publish-git.d.ts +37 -0
- package/dist/release/publish-git.js +108 -0
- package/dist/release/publish-state.d.ts +29 -0
- package/dist/release/publish-state.js +70 -0
- package/dist/release/publish-verify.d.ts +41 -0
- package/dist/release/publish-verify.js +112 -0
- package/dist/release/publish-wait.d.ts +25 -0
- package/dist/release/publish-wait.js +56 -0
- package/dist/release/publish.d.ts +35 -0
- package/dist/release/publish.js +181 -0
- package/dist/release/release-assets.d.ts +39 -0
- package/dist/release/release-assets.js +68 -0
- package/dist/release/release.d.ts +37 -0
- package/dist/release/release.js +179 -0
- package/dist/release/remote.d.ts +12 -0
- package/dist/release/remote.js +15 -0
- package/dist/release/reproducible.d.ts +16 -0
- package/dist/release/reproducible.js +34 -0
- package/dist/release/run-tests.d.ts +5 -0
- package/dist/release/run-tests.js +17 -0
- package/dist/release/semver.d.ts +8 -0
- package/dist/release/semver.js +60 -0
- package/dist/release/version-rules.d.ts +28 -0
- package/dist/release/version-rules.js +63 -0
- package/dist/release/versions-json.d.ts +15 -0
- package/dist/release/versions-json.js +88 -0
- package/dist/release/workflow-run.d.ts +44 -0
- package/dist/release/workflow-run.js +71 -0
- package/dist/scanner/code-checks.d.ts +41 -0
- package/dist/scanner/code-checks.js +82 -0
- package/dist/scanner/commands.d.ts +3 -0
- package/dist/scanner/commands.js +43 -0
- package/dist/scanner/config.d.ts +7 -0
- package/dist/scanner/config.js +25 -0
- package/dist/scanner/css-check.d.ts +26 -0
- package/dist/scanner/css-check.js +63 -0
- package/dist/scanner/eslint-nesting.d.ts +16 -0
- package/dist/scanner/eslint-nesting.js +45 -0
- package/dist/scanner/findings.d.ts +23 -0
- package/dist/scanner/findings.js +21 -0
- package/dist/scanner/git-files.d.ts +16 -0
- package/dist/scanner/git-files.js +73 -0
- package/dist/scanner/lint.d.ts +47 -0
- package/dist/scanner/lint.js +163 -0
- package/dist/scanner/meta-checks.d.ts +8 -0
- package/dist/scanner/meta-checks.js +22 -0
- package/dist/scanner/outside-project.d.ts +19 -0
- package/dist/scanner/outside-project.js +20 -0
- package/dist/scanner/run.d.ts +19 -0
- package/dist/scanner/run.js +78 -0
- package/dist/scanner/scanner-config.d.ts +114 -0
- package/dist/scanner/scanner-config.js +207 -0
- package/dist/scanner/typescript-gate.d.ts +30 -0
- package/dist/scanner/typescript-gate.js +73 -0
- package/dist/vitest/build-config.d.ts +17 -0
- package/dist/vitest/build-config.js +106 -0
- package/dist/vitest/define-unit-config.d.ts +27 -0
- package/dist/vitest/define-unit-config.js +45 -0
- package/dist/vitest/dom/elements.d.ts +87 -0
- package/dist/vitest/dom/elements.js +291 -0
- package/dist/vitest/dom/index.d.ts +1 -0
- package/dist/vitest/dom/index.js +1 -0
- package/dist/vitest/dom/install.d.ts +8 -0
- package/dist/vitest/dom/install.js +261 -0
- package/dist/vitest/dom/setup.d.ts +1 -0
- package/dist/vitest/dom/setup.js +3 -0
- package/dist/vitest/index.d.ts +3 -0
- package/dist/vitest/index.js +2 -0
- package/dist/vitest/options.d.ts +92 -0
- package/dist/vitest/options.js +136 -0
- package/dist/vitest/peers.d.ts +10 -0
- package/dist/vitest/peers.js +51 -0
- package/dist/vitest/workspace-root.d.ts +7 -0
- package/dist/vitest/workspace-root.js +39 -0
- package/docs/build.md +232 -0
- package/docs/ci.md +182 -0
- package/docs/demo.md +364 -0
- package/docs/e2e.md +563 -0
- package/docs/release.md +374 -0
- package/docs/scanner.md +204 -0
- package/docs/unit.md +291 -0
- package/package.json +100 -4
- package/plugins/opdk/skills/audit/SKILL.md +81 -0
- package/plugins/opdk/skills/build/SKILL.md +79 -0
- package/plugins/opdk/skills/demo/SKILL.md +102 -0
- package/plugins/opdk/skills/e2e/SKILL.md +132 -0
- package/plugins/opdk/skills/release/SKILL.md +84 -0
- package/plugins/opdk/skills/scanner/SKILL.md +60 -0
- package/plugins/opdk/skills/unit/SKILL.md +90 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import type { Locator } from "@playwright/test";
|
|
2
|
+
import type { DemoRect } from "./clip.js";
|
|
3
|
+
import type { FilmFrame, FilmKind } from "./manifest.js";
|
|
4
|
+
import type { ThemeMode } from "./names.js";
|
|
5
|
+
import type { DemoPresetName } from "./presets.js";
|
|
6
|
+
export type { DemoPresetName, DemoRect, FilmFrame, FilmKind, ThemeMode };
|
|
7
|
+
/** Picture options both films and stills take. */
|
|
8
|
+
export interface CaptureOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Shoots only this area: an element (its bounding box), or a rectangle in CSS pixels from the window's top-left
|
|
11
|
+
* corner. The shot fails when the area sticks out of the window; scroll the target into view first, or make the
|
|
12
|
+
* window bigger. Films need every frame to have the same size.
|
|
13
|
+
*/
|
|
14
|
+
readonly clip?: Locator | DemoRect;
|
|
15
|
+
/** CSS pixels added around `clip` on every side, cut at the window edge. Default 0. */
|
|
16
|
+
readonly padding?: number;
|
|
17
|
+
/** Selectors that must not be visible in this picture, on top of `demo.forbiddenSelectors`. */
|
|
18
|
+
readonly forbiddenSelectors?: readonly string[];
|
|
19
|
+
/**
|
|
20
|
+
* Take the picture although the run uses a vault from `OPDK_E2E_VAULT`, or a seed vault outside the plugin folder
|
|
21
|
+
* (the directory `playwright test` runs in). Default false: such a run is refused.
|
|
22
|
+
*/
|
|
23
|
+
readonly allowForeignVault?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface FilmOptions extends CaptureOptions {
|
|
26
|
+
/** Folder name of the film under `<outDir>/films/`. Default: the describe titles and the test title (and the project name when the config has several), lower case with dashes. A film with the same name is replaced by a later run; a second test of the same run that gets the same name fails. */
|
|
27
|
+
readonly name?: string;
|
|
28
|
+
/** `phone` films are shot in the mobile emulation (`obsidian.mobile()`), `desktop` films without it; the shot fails otherwise. */
|
|
29
|
+
readonly kind: FilmKind;
|
|
30
|
+
/** Frames per second the film is encoded at. Default 15. */
|
|
31
|
+
readonly fps?: number;
|
|
32
|
+
/** Texts a composed phone film lists beside the phone. A shot points at one by index. They are not drawn into the frames: use `demo.caption()` for that. */
|
|
33
|
+
readonly captions?: readonly string[];
|
|
34
|
+
/** Device pixels per CSS pixel. Default: `demo.scale` of the options, 2. */
|
|
35
|
+
readonly scale?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Show the cursor arrow in this film's frames. Default true. The arrow follows every mouse action of Playwright
|
|
38
|
+
* (`click()`, `check()`, `selectOption()`, `hover()`), not only `demo.moveAndClick()`, so a film that never meant to
|
|
39
|
+
* show a cursor has it at the place of the last click. `false` keeps it hidden in this film's frames, however the
|
|
40
|
+
* page was clicked. The tap dot of a phone film is not affected.
|
|
41
|
+
*/
|
|
42
|
+
readonly cursor?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface ShotOptions {
|
|
45
|
+
/** Seconds the frame stays on screen. */
|
|
46
|
+
readonly hold: number;
|
|
47
|
+
/** Index into the film's `captions`. */
|
|
48
|
+
readonly caption?: number;
|
|
49
|
+
/** Overrides the film's clip for this frame. */
|
|
50
|
+
readonly clip?: Locator | DemoRect;
|
|
51
|
+
/** Overrides the film's padding for this frame. */
|
|
52
|
+
readonly padding?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Run `obsidian.settle()` before the page is frozen: waits until the DOM has been quiet for 150 ms, fonts are loaded
|
|
55
|
+
* and the images in view are complete (budget: `timeouts.helpers.ui`). Default false, so a loading state filmed on
|
|
56
|
+
* purpose is taken as it is. A pause longer than `quietMs` before the render looks settled: assert on the element
|
|
57
|
+
* or raise `quietMs` (call `obsidian.settle({ quietMs })` yourself).
|
|
58
|
+
*/
|
|
59
|
+
readonly settle?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/** A film being recorded. */
|
|
62
|
+
export interface Film {
|
|
63
|
+
readonly name: string;
|
|
64
|
+
/** Absolute folder of the frames and the manifest. */
|
|
65
|
+
readonly dir: string;
|
|
66
|
+
/**
|
|
67
|
+
* Freezes the page, takes one frame and appends it to the manifest. Call it after the assertion that the app is in
|
|
68
|
+
* the state the frame should show; nothing here waits for the app.
|
|
69
|
+
*/
|
|
70
|
+
shot(options: ShotOptions): Promise<FilmFrame>;
|
|
71
|
+
}
|
|
72
|
+
export interface StillOptions extends CaptureOptions {
|
|
73
|
+
/** A destination: the PNG has exactly its pixels. Cannot be combined with `clip` or `scale`. */
|
|
74
|
+
readonly preset?: DemoPresetName;
|
|
75
|
+
/** Device pixels per CSS pixel. Default: `demo.scale` of the options, 2. */
|
|
76
|
+
readonly scale?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Run `obsidian.settle()` before the page is frozen: waits until the DOM has been quiet for 150 ms, fonts are loaded
|
|
79
|
+
* and the images in view are complete (budget: `timeouts.helpers.ui`). Default false, so a loading state filmed on
|
|
80
|
+
* purpose is taken as it is. A pause longer than `quietMs` before the render looks settled: assert on the element
|
|
81
|
+
* or raise `quietMs` (call `obsidian.settle({ quietMs })` yourself).
|
|
82
|
+
*/
|
|
83
|
+
readonly settle?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Show the cursor arrow in this still. Default true: the arrow sits at the place of the last mouse action, whether it
|
|
86
|
+
* came from `demo.moveAndClick()` or a plain Playwright click. `false` keeps it out of this still only; the next
|
|
87
|
+
* film or still decides for itself.
|
|
88
|
+
*/
|
|
89
|
+
readonly cursor?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Whether `opdk demo` copies this still to the output folder. Default true. `false` keeps the PNG in
|
|
92
|
+
* `<outDir>/stills` only, for a still that feeds another tool (a listing composer) and is not a picture to publish.
|
|
93
|
+
*/
|
|
94
|
+
readonly publish?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* The name of an output folder in `demo.outputs` of `opdk.config.mjs` (`{ listing: "docs/listing" }`): `opdk demo`
|
|
97
|
+
* copies this still there instead of the default folder. Cannot be combined with `publish: false`.
|
|
98
|
+
*/
|
|
99
|
+
readonly out?: string;
|
|
100
|
+
}
|
|
101
|
+
export interface StillResult {
|
|
102
|
+
/** Absolute path of the PNG. */
|
|
103
|
+
readonly file: string;
|
|
104
|
+
/** Pixels. */
|
|
105
|
+
readonly width: number;
|
|
106
|
+
readonly height: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Which parts of the UI `demo.cleanUi()` hides. `true`, the default of every key, hides the part; `false` shows it.
|
|
110
|
+
* Each call sets the first five, so the last call decides. `sidebars` is different: it only folds the panels, once,
|
|
111
|
+
* and `false` leaves them as they are.
|
|
112
|
+
*/
|
|
113
|
+
export interface CleanUiOptions {
|
|
114
|
+
readonly ribbon?: boolean;
|
|
115
|
+
readonly statusBar?: boolean;
|
|
116
|
+
/** The row of tabs with the sidebar toggles and the `+` button. */
|
|
117
|
+
readonly tabHeaders?: boolean;
|
|
118
|
+
/** The bar above a note with back and forward, the title and the view actions. */
|
|
119
|
+
readonly viewHeader?: boolean;
|
|
120
|
+
/** The note title above the text. */
|
|
121
|
+
readonly inlineTitle?: boolean;
|
|
122
|
+
/** Folds the left and right side panels (the file explorer, the outline). `false` keeps them as they are. */
|
|
123
|
+
readonly sidebars?: boolean;
|
|
124
|
+
}
|
|
125
|
+
export interface TypeSlowlyOptions {
|
|
126
|
+
/** Milliseconds between keys. Default 40. */
|
|
127
|
+
readonly delayMs?: number;
|
|
128
|
+
}
|
|
129
|
+
export interface TapOptions {
|
|
130
|
+
/** Runs while the finger is down (the dot is small), for a frame of the press: `whilePressed: () => film.shot({ hold: 0.3 })`. */
|
|
131
|
+
readonly whilePressed?: () => Promise<unknown>;
|
|
132
|
+
}
|
|
133
|
+
/** The `demo` fixture: films and stills of the running Obsidian, overlays, and the settings that make a picture reproducible. */
|
|
134
|
+
export interface DemoHelpers {
|
|
135
|
+
/**
|
|
136
|
+
* Starts a film of stills. The film's folder is emptied now, so a retake replaces its frames. Throws at once when
|
|
137
|
+
* the run uses a foreign vault, when this test already started a film with the same name, and when another test of
|
|
138
|
+
* this run wrote a film of that name (each film folder holds an `owner.json` that says who wrote it).
|
|
139
|
+
*/
|
|
140
|
+
film(options: FilmOptions): Film;
|
|
141
|
+
/**
|
|
142
|
+
* Takes one picture, `<outDir>/stills/<name>.png`, replacing an earlier one. Fails when another test of this run
|
|
143
|
+
* wrote a still of that name.
|
|
144
|
+
*/
|
|
145
|
+
still(name: string, options?: StillOptions): Promise<StillResult>;
|
|
146
|
+
/** Moves the cursor to the target in steps the viewer can follow and clicks it. Fails when the target is not visible. */
|
|
147
|
+
moveAndClick(target: Locator): Promise<void>;
|
|
148
|
+
/** Puts the tap dot on the target, presses and releases it, then hides the dot. Fails when the target is not visible. */
|
|
149
|
+
tap(target: Locator, options?: TapOptions): Promise<void>;
|
|
150
|
+
/** Types into the focused element, key by key. Fails when nothing editable (an input, a textarea, a contenteditable) has focus. */
|
|
151
|
+
typeSlowly(text: string, options?: TypeSlowlyOptions): Promise<void>;
|
|
152
|
+
/** Clicks the target with the cursor, then types into it, key by key. Fails when the target is not visible. */
|
|
153
|
+
typeSlowly(target: Locator, text: string, options?: TypeSlowlyOptions): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* Waits `seconds` for the viewer's sake, a deliberate pause in the pacing of a recorded take. Seconds, not
|
|
156
|
+
* milliseconds (an earlier harness's `beat` took milliseconds): more than 60 fails. It is not a wait for the app: use an
|
|
157
|
+
* assertion for that. Films of stills take their timing from `hold`, not from this.
|
|
158
|
+
*/
|
|
159
|
+
beat(seconds: number): Promise<void>;
|
|
160
|
+
/** Shows a caption bar at the bottom of the window (in every frame until changed), or removes it with `null`. The text is shown as plain text. */
|
|
161
|
+
caption(text: string | null): Promise<void>;
|
|
162
|
+
/** Hides the cursor or the tap dot until the mouse moves again. */
|
|
163
|
+
hideCursor(): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Hides parts of the UI that distract from a picture, using Obsidian's own settings where they exist and a class on
|
|
166
|
+
* the page for the status bar and the tab headers, and folds both side panels. It survives `reload()`, `mobile()` and `desktop()`.
|
|
167
|
+
*/
|
|
168
|
+
cleanUi(options?: CleanUiOptions): Promise<void>;
|
|
169
|
+
/**
|
|
170
|
+
* Freezes the clock of the window at `date`: `new Date()`, `Date.now()` and `moment()` return it, timers keep
|
|
171
|
+
* running. It survives `reload()`. A date string without a time zone is read in the time zone of the machine
|
|
172
|
+
* running the test, and the page shows it in that zone too, so the same test gives the same text everywhere; a
|
|
173
|
+
* string with `Z` or an offset shows a different wall clock time in another zone.
|
|
174
|
+
*
|
|
175
|
+
* Limits: the dates of files in Obsidian's explorer or in search come from the file system and are not frozen, and
|
|
176
|
+
* code that measures elapsed time with `Date.now()` sees none pass (timers still fire).
|
|
177
|
+
*/
|
|
178
|
+
freezeTime(date: Date | string | number): Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Runs `scene` once per theme, in order. Inside it `film()` and `still()` add `-light` or `-dark` to their names, so
|
|
181
|
+
* one scene gives `<name>-light` and `<name>-dark`. The theme stays on the last one afterwards.
|
|
182
|
+
*/
|
|
183
|
+
themes(modes: readonly ThemeMode[], scene: (mode: ThemeMode) => Promise<void>): Promise<void>;
|
|
184
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** What the check needs from the machine, injectable so tests need no real `node_modules`. */
|
|
2
|
+
export interface ElectronProbe {
|
|
3
|
+
/** Absolute path of `electron/package.json` as the plugin at `cwd` resolves it; throws when it cannot. */
|
|
4
|
+
resolvePackageJson(cwd: string): string;
|
|
5
|
+
exists(file: string): boolean;
|
|
6
|
+
}
|
|
7
|
+
/** The real thing: Node's resolution from the plugin's folder, and the file system. */
|
|
8
|
+
export declare function createElectronProbe(): ElectronProbe;
|
|
9
|
+
/**
|
|
10
|
+
* Fails early when the plugin's `electron` has no binary yet. Electron 44 does not download it at install time: it
|
|
11
|
+
* writes `path.txt` next to its `package.json` on first use, a download of about 100 MB. Without this check the
|
|
12
|
+
* first `_electron.launch` would spend that time inside the launch timeout (45 s) and fail with a message that
|
|
13
|
+
* does not mention the download.
|
|
14
|
+
*/
|
|
15
|
+
export declare function assertElectronInstalled(cwd: string, probe: ElectronProbe): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
/** The real thing: Node's resolution from the plugin's folder, and the file system. */
|
|
5
|
+
export function createElectronProbe() {
|
|
6
|
+
return {
|
|
7
|
+
resolvePackageJson: (cwd) => createRequire(path.join(cwd, "noop.js")).resolve("electron/package.json"),
|
|
8
|
+
exists: (file) => fs.existsSync(file),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Fails early when the plugin's `electron` has no binary yet. Electron 44 does not download it at install time: it
|
|
13
|
+
* writes `path.txt` next to its `package.json` on first use, a download of about 100 MB. Without this check the
|
|
14
|
+
* first `_electron.launch` would spend that time inside the launch timeout (45 s) and fail with a message that
|
|
15
|
+
* does not mention the download.
|
|
16
|
+
*/
|
|
17
|
+
export function assertElectronInstalled(cwd, probe) {
|
|
18
|
+
let packageJson;
|
|
19
|
+
try {
|
|
20
|
+
packageJson = probe.resolvePackageJson(cwd);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
throw new Error(`Cannot find the "electron" package from ${cwd}. The plugin needs "electron" as a devDependency to run e2e tests: npm install --save-dev electron.`, { cause: error });
|
|
24
|
+
}
|
|
25
|
+
if (!probe.exists(path.join(path.dirname(packageJson), "path.txt"))) {
|
|
26
|
+
throw new Error(`Electron is installed in ${path.dirname(packageJson)} but its binary is not downloaded yet. Electron downloads it on first use (about 100 MB), ` +
|
|
27
|
+
`which would not fit in the launch timeout. Run "node ${path.join(path.dirname(packageJson), "install.js")}" once and run the tests again. ` +
|
|
28
|
+
`In CI, cache the Electron download (the ELECTRON_CACHE folder) and run that command in a step before the tests.`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type ResolvedOptions } from "./options.js";
|
|
2
|
+
import type { ObsidianSession, SessionContext } from "./session.js";
|
|
3
|
+
/** The side effects the fixture bodies use, injectable so their control flow can be tested without Playwright. */
|
|
4
|
+
export interface FixtureDeps {
|
|
5
|
+
/** Starts a session for one test (see `startSession`). */
|
|
6
|
+
readonly start: (context: SessionContext) => Promise<ObsidianSession>;
|
|
7
|
+
/** Sweeps old temp folders when a worker starts (see `sweepAtWorkerStart`). */
|
|
8
|
+
readonly sweep: (olderThanHours: number | false) => void;
|
|
9
|
+
}
|
|
10
|
+
/** The part of Playwright's `TestInfo` the session fixture uses. */
|
|
11
|
+
export interface FixtureTestInfo {
|
|
12
|
+
readonly title: string;
|
|
13
|
+
readonly annotations: {
|
|
14
|
+
type: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
}[];
|
|
17
|
+
readonly attachments: {
|
|
18
|
+
name: string;
|
|
19
|
+
contentType: string;
|
|
20
|
+
path?: string;
|
|
21
|
+
}[];
|
|
22
|
+
/** 0 for the first run of the test. */
|
|
23
|
+
readonly retry: number;
|
|
24
|
+
/** Set once the test body has finished; `expectedStatus` differs from it when the test failed. */
|
|
25
|
+
readonly status?: string | undefined;
|
|
26
|
+
readonly expectedStatus: string;
|
|
27
|
+
readonly outputPath: (...segments: string[]) => string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Playwright's own `trace` and `video` option fixtures: the project's `use` with any `test.use(...)` of the spec file
|
|
31
|
+
* or describe block applied on top. They decide what is recorded for the Obsidian window.
|
|
32
|
+
*/
|
|
33
|
+
export interface RecordingOptions {
|
|
34
|
+
readonly trace?: unknown;
|
|
35
|
+
readonly video?: unknown;
|
|
36
|
+
/** The `seed` option of the test (`test.use({ seed })`); checked before anything is created. */
|
|
37
|
+
readonly seed?: unknown;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Time on top of `launch + ready + trace + 2 * close` that the session fixture may take: the process-tree kill (up to two
|
|
41
|
+
* 3 s polls, about 6 s), folder removal with retries (about 1 s per folder, two folders) and slack.
|
|
42
|
+
*/
|
|
43
|
+
export declare const FIXTURE_TIMEOUT_MARGIN_MS = 20000;
|
|
44
|
+
/**
|
|
45
|
+
* The fixture's own time limit. Setup and teardown of a fixture share this one slot, and by default it is the test
|
|
46
|
+
* timeout (60 s). The kit's budgets (launch 45 s + ready 30 s) are longer than that, so without a limit of its own
|
|
47
|
+
* Playwright could abandon the setup while it was still waiting for Obsidian, and nothing would run the cleanup.
|
|
48
|
+
* With a hung Obsidian the teardown can spend `trace` once (stopping the trace) and `close` twice (closing the app
|
|
49
|
+
* and finishing the video). The kit's own timeouts therefore always fire first, `startSession`
|
|
50
|
+
* tears down what it created, and the test fails with the kit's message.
|
|
51
|
+
*/
|
|
52
|
+
export declare function sessionFixtureTimeout(timeouts?: ResolvedOptions["timeouts"]): number;
|
|
53
|
+
/**
|
|
54
|
+
* The bodies of the fixtures `createObsidianTest` registers, as plain functions: the worker-scoped sweep and the
|
|
55
|
+
* per-test session. `session` always tears the session down, also when the test body throws, and a failing teardown
|
|
56
|
+
* fails the test (it is never swallowed; when both fail the error carries both).
|
|
57
|
+
*/
|
|
58
|
+
export declare function createFixtureFunctions(options: ResolvedOptions, deps: FixtureDeps): {
|
|
59
|
+
sweep: (args: object, use: (value: undefined) => Promise<void>) => Promise<void>;
|
|
60
|
+
session: (args: RecordingOptions, use: (value: ObsidianSession) => Promise<void>, testInfo: FixtureTestInfo) => Promise<void>;
|
|
61
|
+
sessionTimeoutMs: number;
|
|
62
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { parseTraceSetting, parseVideoSetting } from "./artifacts.js";
|
|
2
|
+
import { DEFAULT_TIMEOUTS } from "./options.js";
|
|
3
|
+
import { resolveSeed } from "./seed.js";
|
|
4
|
+
/**
|
|
5
|
+
* Time on top of `launch + ready + trace + 2 * close` that the session fixture may take: the process-tree kill (up to two
|
|
6
|
+
* 3 s polls, about 6 s), folder removal with retries (about 1 s per folder, two folders) and slack.
|
|
7
|
+
*/
|
|
8
|
+
export const FIXTURE_TIMEOUT_MARGIN_MS = 20_000;
|
|
9
|
+
/**
|
|
10
|
+
* The fixture's own time limit. Setup and teardown of a fixture share this one slot, and by default it is the test
|
|
11
|
+
* timeout (60 s). The kit's budgets (launch 45 s + ready 30 s) are longer than that, so without a limit of its own
|
|
12
|
+
* Playwright could abandon the setup while it was still waiting for Obsidian, and nothing would run the cleanup.
|
|
13
|
+
* With a hung Obsidian the teardown can spend `trace` once (stopping the trace) and `close` twice (closing the app
|
|
14
|
+
* and finishing the video). The kit's own timeouts therefore always fire first, `startSession`
|
|
15
|
+
* tears down what it created, and the test fails with the kit's message.
|
|
16
|
+
*/
|
|
17
|
+
export function sessionFixtureTimeout(timeouts = DEFAULT_TIMEOUTS) {
|
|
18
|
+
return timeouts.launch + timeouts.ready + timeouts.trace + 2 * timeouts.close + FIXTURE_TIMEOUT_MARGIN_MS;
|
|
19
|
+
}
|
|
20
|
+
function describe(error) {
|
|
21
|
+
return error instanceof Error ? error.message : String(error);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The bodies of the fixtures `createObsidianTest` registers, as plain functions: the worker-scoped sweep and the
|
|
25
|
+
* per-test session. `session` always tears the session down, also when the test body throws, and a failing teardown
|
|
26
|
+
* fails the test (it is never swallowed; when both fail the error carries both).
|
|
27
|
+
*/
|
|
28
|
+
export function createFixtureFunctions(options, deps) {
|
|
29
|
+
return {
|
|
30
|
+
sweep: async (_args, use) => {
|
|
31
|
+
deps.sweep(options.sweepAfterHours);
|
|
32
|
+
await use(undefined);
|
|
33
|
+
},
|
|
34
|
+
session: async ({ trace, video, seed }, use, testInfo) => {
|
|
35
|
+
const resolvedSeed = resolveSeed(seed, Object.keys(options.data));
|
|
36
|
+
const session = await deps.start({
|
|
37
|
+
label: testInfo.title,
|
|
38
|
+
seed: resolvedSeed,
|
|
39
|
+
annotate: (type, description) => {
|
|
40
|
+
testInfo.annotations.push({ type, description });
|
|
41
|
+
},
|
|
42
|
+
artifacts: {
|
|
43
|
+
trace: parseTraceSetting(trace),
|
|
44
|
+
video: parseVideoSetting(video),
|
|
45
|
+
retry: testInfo.retry,
|
|
46
|
+
outputPath: (name) => testInfo.outputPath(name),
|
|
47
|
+
attach: (name, file, contentType) => {
|
|
48
|
+
testInfo.attachments.push({ name, path: file, contentType });
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
try {
|
|
53
|
+
await use(session);
|
|
54
|
+
}
|
|
55
|
+
catch (bodyError) {
|
|
56
|
+
// Tear down anyway. If that fails too, report both: the cleanup failure must not hide why the test failed.
|
|
57
|
+
await session.teardown({ failed: true }).catch((cleanupError) => {
|
|
58
|
+
throw new AggregateError([bodyError, cleanupError], `The test failed and its cleanup failed too.\n- test: ${describe(bodyError)}\n- cleanup: ${describe(cleanupError)}`);
|
|
59
|
+
});
|
|
60
|
+
throw bodyError;
|
|
61
|
+
}
|
|
62
|
+
// After a normal return the body's result is on `testInfo`: a failed assertion or a timeout does not make
|
|
63
|
+
// `use` throw, it only sets the status.
|
|
64
|
+
await session.teardown({ failed: testInfo.status !== undefined && testInfo.status !== testInfo.expectedStatus });
|
|
65
|
+
},
|
|
66
|
+
sessionTimeoutMs: sessionFixtureTimeout(options.timeouts),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** True when `env[name]` is exactly "1": the on switch for specs that only run on request (a capture run, record mode). */
|
|
2
|
+
export declare function isGateOpen(env: Readonly<Record<string, string | undefined>>, name: string): boolean;
|
|
3
|
+
/** The skip reason a closed gate shows in the report. */
|
|
4
|
+
export declare function gateSkipReason(name: string): string;
|
package/dist/e2e/gate.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** True when `env[name]` is exactly "1": the on switch for specs that only run on request (a capture run, record mode). */
|
|
2
|
+
export function isGateOpen(env, name) {
|
|
3
|
+
return env[name] === "1";
|
|
4
|
+
}
|
|
5
|
+
/** The skip reason a closed gate shows in the report. */
|
|
6
|
+
export function gateSkipReason(name) {
|
|
7
|
+
return `set ${name}=1 to run this spec`;
|
|
8
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { VersionReader } from "../peers/versions.js";
|
|
2
|
+
import { type ElectronProbe } from "./electron-binary.js";
|
|
3
|
+
/**
|
|
4
|
+
* Checks once, before any test starts, that the plugin's Playwright and Electron are versions the kit supports and
|
|
5
|
+
* that its Electron has its binary. Playwright reports an error from a global setup once and runs nothing. The same
|
|
6
|
+
* check in a fixture ran again for every test: a worker is replaced after each failed test, a worker fixture runs
|
|
7
|
+
* again in the new worker, and a plugin with 59 tests got 59 identical failures (seen in a trial).
|
|
8
|
+
*/
|
|
9
|
+
export declare function checkElectron(cwd?: string, probe?: ElectronProbe, read?: VersionReader): void;
|
|
10
|
+
/** The entry Playwright calls: `defineObsidianConfig` registers this file as a `globalSetup`. */
|
|
11
|
+
export default function globalSetup(): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createVersionReader } from "../peers/resolve.js";
|
|
2
|
+
import { assertElectronInstalled, createElectronProbe } from "./electron-binary.js";
|
|
3
|
+
import { assertE2ePeers } from "./peers.js";
|
|
4
|
+
/**
|
|
5
|
+
* Checks once, before any test starts, that the plugin's Playwright and Electron are versions the kit supports and
|
|
6
|
+
* that its Electron has its binary. Playwright reports an error from a global setup once and runs nothing. The same
|
|
7
|
+
* check in a fixture ran again for every test: a worker is replaced after each failed test, a worker fixture runs
|
|
8
|
+
* again in the new worker, and a plugin with 59 tests got 59 identical failures (seen in a trial).
|
|
9
|
+
*/
|
|
10
|
+
export function checkElectron(cwd = process.cwd(), probe = createElectronProbe(), read = createVersionReader(cwd)) {
|
|
11
|
+
assertE2ePeers(read, "obsidian-plugin-dev-kit/e2e");
|
|
12
|
+
assertElectronInstalled(cwd, probe);
|
|
13
|
+
}
|
|
14
|
+
/** The entry Playwright calls: `defineObsidianConfig` registers this file as a `globalSetup`. */
|
|
15
|
+
export default function globalSetup() {
|
|
16
|
+
checkElectron();
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The registered command ids that look like the one asked for: ids that contain it or are contained in it, or that
|
|
3
|
+
* are within a third of its length in edit distance (a typo). Closest first, at most five.
|
|
4
|
+
*/
|
|
5
|
+
export declare function closeCommandIds(wanted: string, registered: readonly string[]): string[];
|
|
6
|
+
/** The error for `runCommand` with an id that is not registered. */
|
|
7
|
+
export declare function commandNotFoundMessage(wanted: string, registered: readonly string[]): string;
|
|
8
|
+
/** The error for a command that exists but whose `checkCallback` declined to run it. */
|
|
9
|
+
export declare function commandDeclinedMessage(id: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Obsidian hotkey notation to Playwright: `Mod` is Cmd on macOS and Ctrl elsewhere, which is what Playwright's
|
|
12
|
+
* `ControlOrMeta` means. Only whole `Mod` tokens change, so `Mod+Shift+P` becomes `ControlOrMeta+Shift+P`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function toPlaywrightKeys(keys: string): string;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** Longest list of close matches the "command not found" message shows. */
|
|
2
|
+
const MAX_MATCHES = 5;
|
|
3
|
+
function editDistance(a, b) {
|
|
4
|
+
let previous = Array.from({ length: b.length + 1 }, (_unused, index) => index);
|
|
5
|
+
for (let i = 1; i <= a.length; i++) {
|
|
6
|
+
const row = [i];
|
|
7
|
+
for (let j = 1; j <= b.length; j++) {
|
|
8
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
9
|
+
row.push(Math.min((previous[j] ?? 0) + 1, (row[j - 1] ?? 0) + 1, (previous[j - 1] ?? 0) + cost));
|
|
10
|
+
}
|
|
11
|
+
previous = row;
|
|
12
|
+
}
|
|
13
|
+
return previous[b.length] ?? 0;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The registered command ids that look like the one asked for: ids that contain it or are contained in it, or that
|
|
17
|
+
* are within a third of its length in edit distance (a typo). Closest first, at most five.
|
|
18
|
+
*/
|
|
19
|
+
export function closeCommandIds(wanted, registered) {
|
|
20
|
+
const needle = wanted.toLowerCase();
|
|
21
|
+
const maxDistance = Math.max(2, Math.ceil(needle.length / 3));
|
|
22
|
+
return registered
|
|
23
|
+
.map((id) => {
|
|
24
|
+
const lower = id.toLowerCase();
|
|
25
|
+
const contains = lower.includes(needle) || (lower.length >= 3 && needle.includes(lower));
|
|
26
|
+
return { id, score: contains ? 0 : editDistance(needle, lower), contains };
|
|
27
|
+
})
|
|
28
|
+
.filter((candidate) => candidate.contains || candidate.score <= maxDistance)
|
|
29
|
+
.sort((a, b) => a.score - b.score || a.id.localeCompare(b.id))
|
|
30
|
+
.slice(0, MAX_MATCHES)
|
|
31
|
+
.map((candidate) => candidate.id);
|
|
32
|
+
}
|
|
33
|
+
/** The error for `runCommand` with an id that is not registered. */
|
|
34
|
+
export function commandNotFoundMessage(wanted, registered) {
|
|
35
|
+
const close = closeCommandIds(wanted, registered);
|
|
36
|
+
const hint = close.length > 0
|
|
37
|
+
? `Close matches: ${close.join(", ")}.`
|
|
38
|
+
: `No registered id is similar (${String(registered.length)} commands are registered).`;
|
|
39
|
+
return (`Command "${wanted}" does not exist. ${hint} A command id is "<plugin id>:<command id>"; ` +
|
|
40
|
+
`list them with Object.keys(app.commands.commands) in the Obsidian developer console.`);
|
|
41
|
+
}
|
|
42
|
+
/** The error for a command that exists but whose `checkCallback` declined to run it. */
|
|
43
|
+
export function commandDeclinedMessage(id) {
|
|
44
|
+
return (`Command "${id}" exists but did not run: its checkCallback returned false. ` +
|
|
45
|
+
`The command needs a context that is missing, for example an open note with a focused editor.`);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Obsidian hotkey notation to Playwright: `Mod` is Cmd on macOS and Ctrl elsewhere, which is what Playwright's
|
|
49
|
+
* `ControlOrMeta` means. Only whole `Mod` tokens change, so `Mod+Shift+P` becomes `ControlOrMeta+Shift+P`.
|
|
50
|
+
*/
|
|
51
|
+
export function toPlaywrightKeys(keys) {
|
|
52
|
+
if (keys.trim() === "") {
|
|
53
|
+
throw new Error('press() needs a key or a combination such as "Mod+P" or "Escape".');
|
|
54
|
+
}
|
|
55
|
+
return keys.replace(/(^|\+)Mod(?=\+|$)/gi, "$1ControlOrMeta");
|
|
56
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CDPSession, Page } from "@playwright/test";
|
|
2
|
+
import type { HelperTimeouts } from "../options.js";
|
|
3
|
+
import { type DeviceMetricsTracker } from "./device-metrics.js";
|
|
4
|
+
import type { ObsidianHelpers } from "./types.js";
|
|
5
|
+
export interface HelperOptions {
|
|
6
|
+
/** How long a reload (mobile, desktop) may take until every plugin has loaded again. The session's `timeouts.ready`. */
|
|
7
|
+
readonly readyTimeoutMs: number;
|
|
8
|
+
/** How long each kind of helper wait may take. The session's `timeouts.helpers`. */
|
|
9
|
+
readonly timeouts: Required<HelperTimeouts>;
|
|
10
|
+
}
|
|
11
|
+
export interface HelperKit {
|
|
12
|
+
readonly helpers: ObsidianHelpers;
|
|
13
|
+
/**
|
|
14
|
+
* The window's one CDP session, opened on first use. The demo module shoots through it: Chromium keeps the device
|
|
15
|
+
* metrics of `mobile()` per session, and a second session that captures at another density drops them.
|
|
16
|
+
*/
|
|
17
|
+
cdpSession(): Promise<CDPSession>;
|
|
18
|
+
/** The device metrics override of that session. `mobile()`, `desktop()` and the demo's shots all set it through this one. */
|
|
19
|
+
readonly deviceMetrics: DeviceMetricsTracker;
|
|
20
|
+
/** Detaches the CDP session the IME and mobile helpers opened. The window itself is closed by the session. */
|
|
21
|
+
dispose(): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
/** Builds the helpers of one test, bound to its window. Everything that waits polls state; none sleeps. */
|
|
24
|
+
export declare function createHelpers(win: Page, options: HelperOptions): HelperKit;
|