@describe-me/vitest 0.5.2 → 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
@@ -11,7 +11,7 @@ pnpm add -D @describe-me/vitest @describe-me/react describe-me
11
11
  ```
12
12
 
13
13
  All describe-me packages must be on the same version
14
- ([Add it to your project](https://github.com/grzehub/describe-me#add-it-to-your-project)).
14
+ ([One version for all packages](https://grzehub.github.io/describe-me/installation.html#lockstep)).
15
15
 
16
16
  ## Usage
17
17
 
@@ -26,13 +26,16 @@ plugin detects where the tests run:
26
26
  `@testing-library/user-event` call, turns on `test.css` so imported
27
27
  stylesheets reach the snapshots, and sets `RTL_SKIP_AUTO_CLEANUP` so the
28
28
  component is unmounted only after the closing frame. The setup file sets
29
- React's `IS_REACT_ACT_ENVIRONMENT` where Testing Library would and turns it
30
- off while the recorder waits, so act warnings match a run without
31
- describe-me. It also works without user-event installed.
29
+ React's `IS_REACT_ACT_ENVIRONMENT` where Testing Library would. With
30
+ `@testing-library/react`, it takes user-event frames without a wait. The
31
+ flag is off for the few waits that remain, which can still move an act
32
+ warning
33
+ ([jsdom](https://grzehub.github.io/describe-me/environments.html#jsdom)). It
34
+ also works without user-event installed.
32
35
 
33
36
  jsdom has no layout, so positioned popovers show in the top-left corner and
34
37
  canvas stays blank
35
- ([Limitations in jsdom](https://github.com/grzehub/describe-me#limitations-in-jsdom)).
38
+ ([Limitations in jsdom](https://grzehub.github.io/describe-me/environments.html#jsdom-limits)).
36
39
 
37
40
  ```ts
38
41
  import { describeMe } from '@describe-me/vitest/plugin'
@@ -68,12 +71,12 @@ plugin the setup file does not know them.
68
71
  every frame's `<head>`, like Storybook's `preview-head.html`: typically the
69
72
  font links that the app shell loads and tests never do. It never reaches the
70
73
  test page, and the local files it links are copied into the output directory
71
- ([Fonts](https://github.com/grzehub/describe-me#fonts) in the root README).
74
+ ([Fonts](https://grzehub.github.io/describe-me/styles-and-fonts.html#fonts) in the docs).
72
75
 
73
76
  `describeMe({ renderFrame })` chooses when the render frame is taken:
74
77
  `'eager'` (default) right after mount, `'lazy'` right before the next
75
78
  interaction, or `{ pending: '<selector>' }` once a loader is gone. See
76
- [Render frame timing](https://github.com/grzehub/describe-me#render-frame-timing).
79
+ [Render frame timing](https://grzehub.github.io/describe-me/configuration.html#render-frame).
77
80
 
78
81
  The plugin adds its reporter to the ones your config names. If it names
79
82
  none, the reporter joins the ones Vitest picks on its own, such as `minimal`
@@ -102,5 +105,4 @@ export default defineConfig({
102
105
  the props tables are left out. `@testing-library/user-event` is an optional
103
106
  peer too, needed only in DOM environments.
104
107
 
105
- See the [root README](https://github.com/grzehub/describe-me#readme) for the
106
- full picture.
108
+ See the [docs](https://grzehub.github.io/describe-me/) for the full picture.
@@ -3,7 +3,8 @@
3
3
  * It comes in two shapes, the direct API (`userEvent.click(el)`) and an
4
4
  * instance from `userEvent.setup()`, and the first delegates to the second,
5
5
  * so both are patched and `recordAction`'s depth guard keeps one gesture to
6
- * one frame. When the optional peer is not installed, there is nothing to
7
- * patch. Safe to call more than once.
6
+ * one frame. Under @testing-library/react a frame is taken as soon as the
7
+ * call resolves, otherwise after one settle. When the optional peer is not
8
+ * installed, there is nothing to patch. Safe to call more than once.
8
9
  */
9
10
  export declare function patchTestingLibraryUserEvent(): Promise<void>;
@@ -1,6 +1,7 @@
1
1
  import { elementLabel } from '@describe-me/core';
2
2
  import { describeArg } from './describe-arg.js';
3
3
  import { recordAction } from './record-action.js';
4
+ import { testingLibraryWrapsInAct } from './testing-library-wraps-in-act.js';
4
5
  /** Every interaction of user-event 14 that can change what the page shows. */
5
6
  const METHODS = [
6
7
  'click',
@@ -31,7 +32,11 @@ function patchMethods(target) {
31
32
  if (typeof original !== 'function' || original[PATCHED]) {
32
33
  continue;
33
34
  }
34
- const wrapped = (...args) => recordAction(labelFor(method, args), async () => original.apply(target, args));
35
+ // Testing Library's wrappers commit the DOM before the call resolves. A settle
36
+ // would only move React updates into a wait with the act flag off.
37
+ const wrapped = (...args) => recordAction(labelFor(method, args), async () => original.apply(target, args), {
38
+ settle: !testingLibraryWrapsInAct(),
39
+ });
35
40
  wrapped[PATCHED] = true;
36
41
  target[method] = wrapped;
37
42
  }
@@ -41,8 +46,9 @@ function patchMethods(target) {
41
46
  * It comes in two shapes, the direct API (`userEvent.click(el)`) and an
42
47
  * instance from `userEvent.setup()`, and the first delegates to the second,
43
48
  * so both are patched and `recordAction`'s depth guard keeps one gesture to
44
- * one frame. When the optional peer is not installed, there is nothing to
45
- * patch. Safe to call more than once.
49
+ * one frame. Under @testing-library/react a frame is taken as soon as the
50
+ * call resolves, otherwise after one settle. When the optional peer is not
51
+ * installed, there is nothing to patch. Safe to call more than once.
46
52
  */
47
53
  export async function patchTestingLibraryUserEvent() {
48
54
  let userEvent;
@@ -1,2 +1,6 @@
1
- /** Run one user interaction and record a frame for it, but only for the outermost call. */
2
- export declare function recordAction<T>(label: string, run: () => Promise<T>): Promise<T>;
1
+ import type { CaptureOptions } from '@describe-me/core';
2
+ /**
3
+ * Run one user interaction and record a frame for it, but only for the outermost call.
4
+ * `settle: false` takes the frame as soon as the interaction resolves, without a wait.
5
+ */
6
+ export declare function recordAction<T>(label: string, run: () => Promise<T>, options?: Pick<CaptureOptions, 'settle'>): Promise<T>;
@@ -7,8 +7,11 @@ import { recorder } from '@describe-me/core';
7
7
  * test left running cannot swallow the next test's frame.
8
8
  */
9
9
  const nesting = { generation: -1, depth: 0 };
10
- /** Run one user interaction and record a frame for it, but only for the outermost call. */
11
- export async function recordAction(label, run) {
10
+ /**
11
+ * Run one user interaction and record a frame for it, but only for the outermost call.
12
+ * `settle: false` takes the frame as soon as the interaction resolves, without a wait.
13
+ */
14
+ export async function recordAction(label, run, options = {}) {
12
15
  const generation = recorder.generation;
13
16
  if (generation !== nesting.generation) {
14
17
  nesting.generation = generation;
@@ -26,7 +29,7 @@ export async function recordAction(label, run) {
26
29
  }
27
30
  }
28
31
  if (generation === nesting.generation && nesting.depth === 0) {
29
- await recorder.capture('action', label, undefined, { generation });
32
+ await recorder.capture('action', label, undefined, { generation, settle: options.settle });
30
33
  }
31
34
  return result;
32
35
  }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Whether @testing-library/dom still runs user-event calls through the
3
+ * `asyncWrapper` that @testing-library/react installed, so the DOM is committed
4
+ * when a call resolves. False when @describe-me/react/testing-library never loaded.
5
+ */
6
+ export declare function testingLibraryWrapsInAct(): boolean;
@@ -0,0 +1,11 @@
1
+ // `publish-testing-library-act.ts` in @describe-me/react writes this key.
2
+ const ACT_CHECK = Symbol.for('describe-me.testing-library-act');
3
+ /**
4
+ * Whether @testing-library/dom still runs user-event calls through the
5
+ * `asyncWrapper` that @testing-library/react installed, so the DOM is committed
6
+ * when a call resolves. False when @describe-me/react/testing-library never loaded.
7
+ */
8
+ export function testingLibraryWrapsInAct() {
9
+ const check = globalThis[ACT_CHECK];
10
+ return typeof check === 'function' && check() === true;
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@describe-me/vitest",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "Vitest integration for describe-me: plugin, setup file and reporter",
5
5
  "keywords": [
6
6
  "vitest",
@@ -60,13 +60,13 @@
60
60
  "dependencies": {
61
61
  "picomatch": "^4.0.3",
62
62
  "std-env": "^4.0.0",
63
- "@describe-me/core": "^0.5.2"
63
+ "@describe-me/core": "^0.5.3"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "vitest": "^4.0.0 || ^5.0.0",
67
67
  "typescript": "^5.0.0 || ^6.0.0",
68
68
  "@testing-library/user-event": "^14.0.0",
69
- "describe-me": "^0.5.2"
69
+ "describe-me": "^0.5.3"
70
70
  },
71
71
  "peerDependenciesMeta": {
72
72
  "typescript": {