@describe-me/react 0.5.0-next.0 → 0.5.0-next.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/README.md CHANGED
@@ -24,7 +24,10 @@ Each entry point re-exports everything its test library offers, with the
24
24
  recording functions swapped in, so switching an existing test is one import.
25
25
  `@describe-me/react` swaps `render`. The Testing Library entry swaps `render`,
26
26
  `fireEvent` and `cleanup`: every `fireEvent` call records a frame, and
27
- `cleanup` takes the closing frame before it unmounts.
27
+ `cleanup` takes the closing frame before it unmounts. When the render frame is
28
+ taken follows the plugin's
29
+ [`renderFrame`](https://github.com/grzehub/describe-me#render-frame-timing)
30
+ option.
28
31
 
29
32
  ```tsx
30
33
  import { render, step } from '@describe-me/react'
package/dist/cleanup.js CHANGED
@@ -6,6 +6,7 @@ import { recorder } from '@describe-me/core';
6
6
  * state instead of an empty page.
7
7
  */
8
8
  export function cleanup() {
9
+ recorder.beforeInteraction();
9
10
  void recorder.capture('end', 'end of test', undefined, { settle: false });
10
11
  unmountAll();
11
12
  }
@@ -12,6 +12,7 @@ let depth = 0;
12
12
  * settling.
13
13
  */
14
14
  export function recordSyncAction(label, run) {
15
+ recorder.beforeInteraction();
15
16
  depth++;
16
17
  let result;
17
18
  try {
@@ -11,6 +11,8 @@ type RenderResult = ReturnType<typeof baseRender>;
11
11
  * keeps working. Testing Library wraps mounting in `act()`, which means the DOM
12
12
  * is committed when it returns, so frames are captured without settling: the
13
13
  * snapshot is taken right here, before the test's next line can change the DOM.
14
+ * `render`, `rerender` and `unmount` first take a render frame the plugin's
15
+ * `renderFrame` option deferred.
14
16
  *
15
17
  * Importing this module hands unmounting to the recorder's teardown rather
16
18
  * than to Testing Library's own auto-cleanup, which would run before the
@@ -15,6 +15,8 @@ recorder.onTeardown(unmountAll);
15
15
  * keeps working. Testing Library wraps mounting in `act()`, which means the DOM
16
16
  * is committed when it returns, so frames are captured without settling: the
17
17
  * snapshot is taken right here, before the test's next line can change the DOM.
18
+ * `render`, `rerender` and `unmount` first take a render frame the plugin's
19
+ * `renderFrame` option deferred.
18
20
  *
19
21
  * Importing this module hands unmounting to the recorder's teardown rather
20
22
  * than to Testing Library's own auto-cleanup, which would run before the
@@ -22,6 +24,7 @@ recorder.onTeardown(unmountAll);
22
24
  * `RTL_SKIP_AUTO_CLEANUP`.
23
25
  */
24
26
  export function render(ui, options) {
27
+ recorder.beforeInteraction();
25
28
  const result = baseRender(ui, options);
26
29
  if (recorder.isActive && isValidElement(ui)) {
27
30
  const info = describeElement(ui);
@@ -30,11 +33,18 @@ export function render(ui, options) {
30
33
  }
31
34
  const originalRerender = result.rerender;
32
35
  result.rerender = (next) => {
36
+ recorder.beforeInteraction();
33
37
  originalRerender(next);
34
38
  if (recorder.isActive && isValidElement(next)) {
35
39
  const info = describeElement(next);
36
40
  void recorder.capture('render', `rerender ${labelFor(info)}`, { props: info.props }, { settle: false });
37
41
  }
38
42
  };
43
+ const originalUnmount = result.unmount;
44
+ // Without this, a lazy test that ends with `unmount()` documents an empty page.
45
+ result.unmount = () => {
46
+ recorder.beforeInteraction();
47
+ originalUnmount();
48
+ };
39
49
  return result;
40
50
  }
package/dist/render.d.ts CHANGED
@@ -5,7 +5,8 @@ type RenderOptions = Parameters<BaseRender>[1];
5
5
  type Screen = Awaited<ReturnType<BaseRender>>;
6
6
  /**
7
7
  * Drop-in for `render` from vitest-browser-react. Records a frame after mount
8
- * and after every `rerender`.
8
+ * and after every `rerender`. `render`, `rerender` and `unmount` first take a
9
+ * render frame the plugin's `renderFrame` option deferred.
9
10
  */
10
11
  export declare function render(ui: ReactElement, options?: RenderOptions): Promise<Screen>;
11
12
  export {};
package/dist/render.js CHANGED
@@ -5,23 +5,34 @@ import { describeElement } from './describe-element.js';
5
5
  import { labelFor } from './label-for.js';
6
6
  /**
7
7
  * Drop-in for `render` from vitest-browser-react. Records a frame after mount
8
- * and after every `rerender`.
8
+ * and after every `rerender`. `render`, `rerender` and `unmount` first take a
9
+ * render frame the plugin's `renderFrame` option deferred.
9
10
  */
10
11
  export async function render(ui, options) {
12
+ const generation = recorder.generation;
13
+ recorder.beforeInteraction();
11
14
  const screen = await baseRender(ui, options);
12
15
  if (isValidElement(ui)) {
13
16
  const info = describeElement(ui);
14
17
  recorder.setComponent(info);
15
- await recorder.capture('render', labelFor(info), { props: info.props });
18
+ await recorder.capture('render', labelFor(info), { props: info.props }, { generation });
16
19
  }
17
20
  const originalRerender = screen.rerender.bind(screen);
18
21
  screen.rerender = (async (next) => {
22
+ const rerenderGeneration = recorder.generation;
23
+ recorder.beforeInteraction();
19
24
  const result = await originalRerender(next);
20
25
  if (isValidElement(next)) {
21
26
  const info = describeElement(next);
22
- await recorder.capture('render', `rerender ${labelFor(info)}`, { props: info.props });
27
+ await recorder.capture('render', `rerender ${labelFor(info)}`, { props: info.props }, { generation: rerenderGeneration });
23
28
  }
24
29
  return result;
25
30
  });
31
+ const originalUnmount = screen.unmount.bind(screen);
32
+ // Without this, a lazy test that ends with `unmount()` documents an empty page.
33
+ screen.unmount = () => {
34
+ recorder.beforeInteraction();
35
+ return originalUnmount();
36
+ };
26
37
  return screen;
27
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@describe-me/react",
3
- "version": "0.5.0-next.0",
3
+ "version": "0.5.0-next.2",
4
4
  "description": "React adapter for describe-me: drop-in render functions that record frames",
5
5
  "keywords": [
6
6
  "vitest",
@@ -46,7 +46,7 @@
46
46
  "./dist/render-testing-library.js"
47
47
  ],
48
48
  "dependencies": {
49
- "@describe-me/core": "^0.5.0-next.0"
49
+ "@describe-me/core": "^0.5.0-next.2"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@testing-library/react": "^16.0.0",