@describe-me/core 0.5.1 → 0.5.3

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
@@ -15,7 +15,7 @@ pnpm add -D @describe-me/core
15
15
  ```
16
16
 
17
17
  All describe-me packages must be on the same version
18
- ([Add it to your project](https://github.com/grzehub/describe-me#add-it-to-your-project)).
18
+ ([One version for all packages](https://grzehub.github.io/describe-me/installation.html#lockstep)).
19
19
 
20
20
  ## Usage
21
21
 
@@ -40,9 +40,8 @@ flight and takes a deferred render frame.
40
40
  The manifest types live in `@describe-me/core/types`, for tools that want to
41
41
  read `.describe-me/manifest.json` themselves. Stored snapshots point into
42
42
  `assets/` and `styles/` through `ASSET_URL_PREFIX` and `STYLE_URL_PREFIX`
43
- ([Output directory](https://github.com/grzehub/describe-me#output-directory) in
44
- the root README). `@describe-me/core/css-references` lists the `url()` and
43
+ ([The output directory](https://grzehub.github.io/describe-me/how-it-works.html#storage) in
44
+ the docs). `@describe-me/core/css-references` lists the `url()` and
45
45
  `@import` references in CSS text.
46
46
 
47
- See the [root README](https://github.com/grzehub/describe-me#readme) for the
48
- full picture.
47
+ See the [docs](https://grzehub.github.io/describe-me/) for the full picture.
@@ -8,13 +8,14 @@ type Teardown = () => void;
8
8
  */
9
9
  declare class Recorder {
10
10
  /** Which contract this recorder follows, so another copy of core can refuse it. */
11
- readonly protocol = 1;
11
+ readonly protocol = 2;
12
12
  private slots;
13
13
  private currentGeneration;
14
14
  private inFlight;
15
15
  private deferred;
16
16
  private pending;
17
17
  private renderFrame;
18
+ private aroundWait;
18
19
  private component?;
19
20
  private startedAt;
20
21
  private active;
@@ -28,9 +29,10 @@ declare class Recorder {
28
29
  */
29
30
  get generation(): number;
30
31
  /**
31
- * Choose when the render frame is taken, from the next render capture on.
32
- * The setup files call it with the plugin's options. A `pending` selector
33
- * the DOM rejects falls back to `'lazy'` with a warning.
32
+ * Choose when the render frame is taken, from the next render capture on,
33
+ * and what runs around each wait. The setup files call it with the plugin's
34
+ * options. A `pending` selector the DOM rejects falls back to `'lazy'` with
35
+ * a warning.
34
36
  */
35
37
  configure(options: RecorderOptions): void;
36
38
  /**
@@ -64,6 +66,7 @@ declare class Recorder {
64
66
  */
65
67
  private defer;
66
68
  private clearDeferred;
69
+ private waitToSettle;
67
70
  private settleThenFill;
68
71
  private fill;
69
72
  }
package/dist/recorder.js CHANGED
@@ -9,7 +9,7 @@ import { ANONYMOUS_COMPONENT, } from './types.js';
9
9
  * Bump it whenever the contract between the recorder and the adapters or setup
10
10
  * files changes: a method or property added, removed or changed in meaning.
11
11
  */
12
- const RECORDER_PROTOCOL = 1;
12
+ const RECORDER_PROTOCOL = 2;
13
13
  function isValidSelector(selector) {
14
14
  try {
15
15
  document.querySelector(selector);
@@ -36,6 +36,7 @@ class Recorder {
36
36
  deferred = null;
37
37
  pending = null;
38
38
  renderFrame = 'eager';
39
+ aroundWait = (wait) => wait();
39
40
  component;
40
41
  startedAt = 0;
41
42
  active = false;
@@ -63,12 +64,16 @@ class Recorder {
63
64
  return this.currentGeneration;
64
65
  }
65
66
  /**
66
- * Choose when the render frame is taken, from the next render capture on.
67
- * The setup files call it with the plugin's options. A `pending` selector
68
- * the DOM rejects falls back to `'lazy'` with a warning.
67
+ * Choose when the render frame is taken, from the next render capture on,
68
+ * and what runs around each wait. The setup files call it with the plugin's
69
+ * options. A `pending` selector the DOM rejects falls back to `'lazy'` with
70
+ * a warning.
69
71
  */
70
72
  configure(options) {
71
73
  const renderFrame = options.renderFrame ?? 'eager';
74
+ if (options.aroundWait !== undefined) {
75
+ this.aroundWait = options.aroundWait;
76
+ }
72
77
  if (typeof renderFrame === 'object' &&
73
78
  typeof document !== 'undefined' &&
74
79
  !isValidSelector(renderFrame.pending)) {
@@ -157,7 +162,7 @@ class Recorder {
157
162
  return false;
158
163
  }
159
164
  const generation = this.currentGeneration;
160
- await settle();
165
+ await this.waitToSettle();
161
166
  // The test ended, or an interaction took the frame, while this settled.
162
167
  if (generation !== this.currentGeneration || this.deferred !== slot) {
163
168
  return false;
@@ -215,8 +220,13 @@ class Recorder {
215
220
  this.pending?.dispose();
216
221
  this.pending = null;
217
222
  }
223
+ // Only the wait runs inside `aroundWait`, so whatever the wrapper changes is
224
+ // undone before the snapshot and the teardown.
225
+ waitToSettle() {
226
+ return this.aroundWait(settle);
227
+ }
218
228
  async settleThenFill(slot, generation) {
219
- await settle();
229
+ await this.waitToSettle();
220
230
  if (generation === this.currentGeneration) {
221
231
  this.fill(slot);
222
232
  }
package/dist/types.d.ts CHANGED
@@ -49,10 +49,18 @@ export type RenderFrameMode = 'eager' | 'lazy' | {
49
49
  pending: string;
50
50
  timeout?: number;
51
51
  };
52
+ /** Runs one wait of the recorder. It must call `wait` once and resolve after it. */
53
+ export type AroundWait = (wait: () => Promise<void>) => Promise<void>;
52
54
  /** Options for `recorder.configure()`. */
53
55
  export interface RecorderOptions {
54
56
  /** When the render frame is taken. Default: `'eager'`. */
55
57
  renderFrame?: RenderFrameMode;
58
+ /**
59
+ * Runs each wait of the recorder. It is kept when omitted, so a later
60
+ * `configure({ renderFrame })` keeps the setup file's wrapper. By default
61
+ * it runs `wait` as is.
62
+ */
63
+ aroundWait?: AroundWait;
56
64
  }
57
65
  /** Options for `recorder.capture()`. */
58
66
  export interface CaptureOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@describe-me/core",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "Recorder and manifest types for describe-me: living component docs from your tests",
5
5
  "keywords": [
6
6
  "vitest",