dsh-plugin-toolkit 0.3.1 → 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 +5 -0
- package/README.md +25 -0
- package/lib/testkit/index.mjs +1 -1
- package/lib/testkit/snapshot.mjs +21 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
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
|
+
|
|
3
8
|
## 0.3.1
|
|
4
9
|
|
|
5
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.
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# dsh-plugin-toolkit
|
|
2
2
|
|
|
3
|
+

|
|
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
|
```
|
|
@@ -53,6 +55,29 @@ await panel.unmount();
|
|
|
53
55
|
|
|
54
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.
|
|
55
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
|
+
|
|
56
81
|
To look at a bundle by hand:
|
|
57
82
|
|
|
58
83
|
```sh
|
package/lib/testkit/index.mjs
CHANGED
|
@@ -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';
|
package/lib/testkit/snapshot.mjs
CHANGED
|
@@ -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.
|
|
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": {
|