dsh-plugin-toolkit 0.3.0 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.2
4
+
5
+ - `expectSnapshot(html, dir, name)`: the assertion form of `compare`, so a baseline test reads like a test and fails with the element that moved.
6
+ - README: how to keep a DOM baseline, and how to assert what assistive tech sees.
7
+
8
+ ## 0.3.1
9
+
10
+ - `unmount()` now waits one macrotask before the DOM goes away. React schedules work during its own unmount, and closing jsdom first turned that into `ReferenceError: window is not defined` after a passing test. Found by the example plugin's second test.
11
+ - The README links `dsh-plugin-example` and documents that `unmount()` is async.
12
+
3
13
  ## 0.3.0
4
14
 
5
15
  - `dsh-plugin dev`: copy a rebuilt bundle into the installed plugin, then confirm the reload from the host's `/plugins/events` stream. Subscribing happens *before* the write, because a copy made first is reported to nobody.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # dsh-plugin-toolkit
2
2
 
3
+ ![dsh-plugin-toolkit](docs/card.png)
4
+
3
5
  A preflight and release tool for [DeepSeek Harness](https://github.com/deepseek-ai/dsh) plugins, plus the pieces of the publishing ritual that kept going wrong by hand.
4
6
 
5
7
  ```
@@ -49,8 +51,33 @@ console.assert(panel.must('[role="status"]').textContent.includes('92'));
49
51
  await panel.unmount();
50
52
  ```
51
53
 
54
+ `unmount()` is async: it lets React finish the work its own unmount schedules before the DOM goes away. Skipping the `await` surfaces as `ReferenceError: window is not defined` *after* the test has already passed, which is a confusing way to learn it.
55
+
52
56
  What you get back: `text()`, `html()`, `query(selector)`, `must(selector)` (throws with the rendered HTML when it misses), `click(selector)`, `type(selector, value)`, `press(selector, key)`, `focus`, `attributes(selector)`, `snapshot(dir, name)` for a normalised DOM baseline, and `host` for assertions about what the bundle registered.
53
57
 
58
+ ### Keep a visual baseline
59
+
60
+ The DOM is the baseline: normalising class order and whitespace gives a file that fails for the reasons a screenshot would — a lost label, a control that stopped rendering — and can be reviewed in a diff instead of by eye.
61
+
62
+ ```js
63
+ import { expectSnapshot } from 'dsh-plugin-toolkit/testkit';
64
+
65
+ const panel = await mountClient({ file: 'client.js' });
66
+ expectSnapshot(panel.html(), '__snapshots__', 'panel'); // throws with the element that moved
67
+ await panel.unmount();
68
+ ```
69
+
70
+ First run writes nothing: it tells you to re-run with `UPDATE_SNAPSHOTS=1`, so a baseline is always a decision, never a side effect.
71
+
72
+ ### Check what assistive tech sees
73
+
74
+ ```js
75
+ assert.equal(panel.attributes('[role="tab"][aria-selected="true"]').id, 'tab-protection');
76
+ assert.match(panel.must('[role="status"]').textContent, /Score moved 71 → 77/);
77
+ ```
78
+
79
+ `must()` throws with the rendered markup when the selector misses, which is the difference between "the assertion failed" and "here is what the user actually got".
80
+
54
81
  To look at a bundle by hand:
55
82
 
56
83
  ```sh
@@ -65,6 +92,14 @@ $ npx dsh-plugin mount ../ai-context-doctor/plugin/client.js
65
92
  AIignore No workspace yet Could not read the report …
66
93
  ```
67
94
 
95
+ ## Start from the example
96
+
97
+ [`dsh-plugin-example`](https://github.com/WJDdidi-1/dsh-plugin-example) is a ~70-line plugin: one sidebar tab, two languages, one behaviour test, CI that runs `doctor` through the composite action. It is the shape this toolkit expects, so it is also the fastest way to see whether the toolkit fits your plugin.
98
+
99
+ ```sh
100
+ dsh plugin add dsh-plugin-example
101
+ ```
102
+
68
103
  ## Edit a plugin that is already installed
69
104
 
70
105
  The host already swaps a rebuilt bundle without a page reload: it watches each plugin's entry artifact and reports a `rebuilt` frame on `/plugins/events`. `dev` puts the new file where the host is looking, then **proves** the frame arrived instead of asking you to check by eye.
@@ -9,4 +9,4 @@ export { createHost } from './host.mjs';
9
9
  export { createFetch } from './fetch.mjs';
10
10
  export { createModuleLoader, loadBundle } from './load.mjs';
11
11
  export { mountClient } from './mount.mjs';
12
- export { compare, normalize, snapshotPath, write } from './snapshot.mjs';
12
+ export { compare, expectSnapshot, normalize, snapshotPath, write } from './snapshot.mjs';
@@ -184,7 +184,14 @@ export async function mountClient(options) {
184
184
  },
185
185
  writeSnapshot: (dir, name) => write(dir, name, root.innerHTML),
186
186
  unmount: async () => {
187
- await act(async () => clientRoot.unmount());
187
+ await act(async () => {
188
+ clientRoot.unmount();
189
+ // React schedules follow-up work, and a polling panel schedules timers.
190
+ // One macrotask lets that land while the DOM is still alive; closing the
191
+ // window first turns it into "ReferenceError: window is not defined"
192
+ // after the test has already passed.
193
+ await new Promise((resolve) => setTimeout(resolve, 0));
194
+ });
188
195
  globalThis.fetch = previousFetch;
189
196
  restoreGlobals();
190
197
  // A panel polls; jsdom's timers and rAF would keep the test process alive
@@ -45,3 +45,24 @@ export function write(dir, name, html) {
45
45
  fs.writeFileSync(file, `${normalize(html)}\n`);
46
46
  return file;
47
47
  }
48
+
49
+ /**
50
+ * The assertion form of `compare`, so a baseline test reads like a test and
51
+ * fails with the thing that moved rather than two walls of markup.
52
+ */
53
+ export function expectSnapshot(html, dir, name) {
54
+ const result = compare(dir, name, html);
55
+ if (result.status === 'same') return result;
56
+ if (result.status === 'missing') {
57
+ throw new Error(`no baseline at ${result.file}; run with UPDATE_SNAPSHOTS=1 to create it`);
58
+ }
59
+ const expected = result.expected.split(/(?=<)/);
60
+ const actual = result.actual.split(/(?=<)/);
61
+ const position = result.firstDifference;
62
+ throw new Error([
63
+ `${name} changed at element ${position}`,
64
+ ` expected: ${expected[position] ?? '(nothing)'}`,
65
+ ` actual: ${actual[position] ?? '(nothing)'}`,
66
+ ` baseline: ${result.file}`,
67
+ ].join('\n'));
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-toolkit",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Preflight, release and test DeepSeek Harness plugins: checks what the host needs, waits for npm to actually serve the version, and keeps the market index honest.",
5
5
  "type": "module",
6
6
  "bin": {