@vickbk/tests 0.0.0-stage → 0.2.0

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/LICENSE +21 -0
  3. package/README.md +225 -2
  4. package/dist/console-Cf1taTRK.mjs +39 -0
  5. package/dist/console-Cf1taTRK.mjs.map +1 -0
  6. package/dist/dom-DeHbD1ni.mjs +459 -0
  7. package/dist/dom-DeHbD1ni.mjs.map +1 -0
  8. package/dist/index-CKsosUpb.d.mts +249 -0
  9. package/dist/index-CKsosUpb.d.mts.map +1 -0
  10. package/dist/index-DtGBqDev.d.mts +25 -0
  11. package/dist/index-DtGBqDev.d.mts.map +1 -0
  12. package/dist/index.cjs +3 -0
  13. package/dist/index.d.cts +6 -0
  14. package/dist/index.d.cts.map +1 -0
  15. package/dist/index.d.mts +6 -0
  16. package/dist/index.d.mts.map +1 -0
  17. package/dist/index.mjs +1 -0
  18. package/dist/pattern-to-regex-BrMJtzu8.cjs +19 -0
  19. package/dist/pattern-to-regex-BrMJtzu8.cjs.map +1 -0
  20. package/dist/pattern-to-regex-CO5Y0oDU.mjs +14 -0
  21. package/dist/pattern-to-regex-CO5Y0oDU.mjs.map +1 -0
  22. package/dist/playwright.cjs +327 -0
  23. package/dist/playwright.cjs.map +1 -0
  24. package/dist/playwright.d.cts +254 -0
  25. package/dist/playwright.d.cts.map +1 -0
  26. package/dist/playwright.d.mts +254 -0
  27. package/dist/playwright.d.mts.map +1 -0
  28. package/dist/playwright.mjs +308 -0
  29. package/dist/playwright.mjs.map +1 -0
  30. package/dist/promises.cjs +45 -0
  31. package/dist/promises.cjs.map +1 -0
  32. package/dist/promises.d.cts +34 -0
  33. package/dist/promises.d.cts.map +1 -0
  34. package/dist/promises.d.mts +34 -0
  35. package/dist/promises.d.mts.map +1 -0
  36. package/dist/promises.mjs +43 -0
  37. package/dist/promises.mjs.map +1 -0
  38. package/dist/react.cjs +173 -0
  39. package/dist/react.cjs.map +1 -0
  40. package/dist/react.d.cts +17 -0
  41. package/dist/react.d.cts.map +1 -0
  42. package/dist/react.d.mts +17 -0
  43. package/dist/react.d.mts.map +1 -0
  44. package/dist/react.mjs +170 -0
  45. package/dist/react.mjs.map +1 -0
  46. package/dist/rolldown-runtime-VH7oDXx4.cjs +28 -0
  47. package/dist/types-BlSFP07Z.d.cts +8 -0
  48. package/dist/types-BlSFP07Z.d.cts.map +1 -0
  49. package/dist/types-BlSFP07Z.d.mts +8 -0
  50. package/dist/types-BlSFP07Z.d.mts.map +1 -0
  51. package/dist/vitest/console.d.mts +2 -0
  52. package/dist/vitest/console.mjs +1 -0
  53. package/dist/vitest/dom.d.mts +2 -0
  54. package/dist/vitest/dom.mjs +1 -0
  55. package/dist/vitest.d.mts +49 -0
  56. package/dist/vitest.d.mts.map +1 -0
  57. package/dist/vitest.mjs +57 -0
  58. package/dist/vitest.mjs.map +1 -0
  59. package/package.json +165 -3
package/CHANGELOG.md ADDED
@@ -0,0 +1,39 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.2.0] - 2026-10-27
11
+
12
+ ### Added
13
+
14
+ - Add `@vickbk/tests/vitest/console` as a dedicated entrypoint for console controls.
15
+ - Add `@vickbk/tests/vitest/dom` as a dedicated entrypoint for DOM queries, assertions, interactions, and toggle-event support.
16
+ - Add `@vickbk/tests/promises` as a framework-independent entrypoint for `resolvedPromise` and `rejectedPromise`.
17
+
18
+ ### Changed
19
+
20
+ - Organize Vitest helpers into specialized entrypoints so consumers can import only the helper categories they need.
21
+ - Update the root README and Vitest documentation to describe the public entrypoints, their intended use, and their dependency requirements.
22
+
23
+ ### Deprecated
24
+
25
+ - Deprecate `resolvedPromise` and `rejectedPromise` when imported from `@vickbk/tests/vitest`. Use `@vickbk/tests/promises` instead.
26
+ - Retain the deprecated promise exports from the aggregate Vitest entrypoint for backward compatibility.
27
+
28
+ ## [0.1.0] - 2026-10-24
29
+
30
+ ### Added
31
+
32
+ - Shared text-pattern utilities and types, including `patternToRegex`, `LABEL_LOCATOR`, `TEXT_MATCHER`, `TEXT_PATTERN`, and `TEXT_WITH_NTH` through `@vickbk/tests`.
33
+ - Vitest utilities for DOM assertions, console controls, user interactions, promise helpers, and toggle-event handling through `@vickbk/tests/vitest`.
34
+ - React Server Component tree resolution through `@vickbk/tests/react`.
35
+ - Playwright utilities for assertions, locators, interactions, and reusable test execution through `@vickbk/tests/playwright`.
36
+ - Public package entrypoints for shared helpers, Vitest utilities, React utilities, and Playwright utilities.
37
+ - TypeScript declaration files for the published entrypoints.
38
+ - ESM and CommonJS builds for supported entrypoints, with the `@vickbk/tests/vitest` entrypoint published as ESM-only.
39
+ - Package documentation covering installation, peer dependencies, setup, and API usage.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vick Bake
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,226 @@
1
- # Temporary Holding Version
1
+ # @vickbk/tests
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4
+ [![npm version](https://img.shields.io/npm/v/@vickbk/tests.svg)](https://www.npmjs.com/package/@vickbk/tests)
5
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/vickbk/tests/lint-test-docs.yml?branch=main)](https://github.com/vickbk/tests/actions)
6
+ [![Test Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen.svg)](https://github.com/vickbk/tests)
7
+
8
+ Reusable testing utilities for TypeScript projects: framework-agnostic shared helpers, promise helpers, Vitest utilities, React Server Component helpers, and a Playwright DSL. Import only the entrypoint that matches the functionality and integrations your project needs.
9
+
10
+ ## Overview
11
+
12
+ The package is organized around focused public entrypoints:
13
+
14
+ - **Shared utilities** provide text-pattern helpers and types.
15
+ - **Promise helpers** provide settled-promise utilities without requiring Vitest or Testing Library.
16
+ - **Vitest utilities** provide console controls, DOM assertions and interactions, and toggle-event support.
17
+ - **React utilities** provide React Server Component (RSC) tree resolution.
18
+ - **Playwright utilities** provide assertions, locators, interactions, and a reusable runner.
19
+
20
+ > The Vitest Aggregate entrypoint re-exports console, DOM, and promises (Deprecated) helpers. For dependency isolation, prefer the specialized entrypoint that matches your needs.
21
+
22
+ ## Installation
23
+
24
+ Install the package as a development dependency:
25
+
26
+ ```sh
27
+ pnpm add -D @vickbk/tests
28
+ ```
29
+
30
+ Install the peer dependencies required by the integrations you use.
31
+
32
+ For Vitest DOM tests:
33
+
34
+ ```sh
35
+ pnpm add -D vitest jsdom @testing-library/react @testing-library/user-event @testing-library/jest-dom
36
+ ```
37
+
38
+ For console helpers, install Vitest.
39
+
40
+ For promise helpers, no dependency is required by the promises entrypoint.
41
+
42
+ For Playwright tests, install `@playwright/test`.
43
+ For React Server Component helpers, install `react` and `react-dom` (and `@types/react` when using TypeScript).
44
+
45
+ ## Public entrypoints
46
+
47
+ | Import path | Purpose |
48
+ | ------------------------------ | -------------------------------------------------------------------------------- |
49
+ | `@vickbk/tests` | Shared text-pattern utilities and types |
50
+ | `@vickbk/tests/promises` | Framework-independent settled-promise helpers |
51
+ | `@vickbk/tests/vitest` | Aggregate Vitest API: console, DOM, toggle-event, and deprecated promise exports |
52
+ | `@vickbk/tests/vitest/console` | Console controls using Vitest spies |
53
+ | `@vickbk/tests/vitest/dom` | DOM queries, assertions, interactions, and toggle-event support |
54
+ | `@vickbk/tests/react` | React Server Component tree resolution |
55
+ | `@vickbk/tests/playwright` | Playwright assertions, locators, interactions, and runner |
56
+
57
+ **Module format:** The `@vickbk/tests/vitest`, `@vickbk/tests/vitest/console` and `@vickbk/tests/vitest/dom` entrypoints are ESM-only. Use `import` to consume them; CommonJS `require()` is not supported. Other entrypoints support dual module format.
58
+
59
+ ## Shared text-pattern helpers
60
+
61
+ The shared API provides `patternToRegex` and the `LABEL_LOCATOR`, `TEXT_MATCHER`, `TEXT_PATTERN`, and `TEXT_WITH_NTH` types.
62
+
63
+ ```ts
64
+ import { patternToRegex, type TEXT_MATCHER } from "@vickbk/tests";
65
+
66
+ const matcher: TEXT_MATCHER = ["Welcome", 0];
67
+ const caseInsensitive = patternToRegex("Welcome");
68
+ ```
69
+
70
+ ## Promise helpers
71
+
72
+ The dedicated promises entrypoint provides `resolvedPromise` and `rejectedPromise`. These helpers produce settled promises with Vitest-style `status` and `value`/`reason` properties, useful when testing consumers that inspect promise state.
73
+
74
+ ```ts
75
+ import { rejectedPromise, resolvedPromise } from "@vickbk/tests/promises";
76
+
77
+ const ready = resolvedPromise({ id: "item-1" });
78
+ expect(ready.status).toBe("fulfilled");
79
+ expect(ready.value.id).toBe("item-1");
80
+
81
+ await expect(rejectedPromise(new Error("unavailable"))).rejects.toThrow(
82
+ "unavailable",
83
+ );
84
+ ```
85
+
86
+ Prefer `@vickbk/tests/promises` for all new code. The same helpers remain exported from `@vickbk/tests/vitest` for backward compatibility, but those re-exports are deprecated. Migrate existing imports to the dedicated promises entrypoint.
87
+
88
+ ## Vitest setup
89
+
90
+ The package supports Node.js 20 and newer. Its peer dependency ranges are:
91
+
92
+ | Peer dependency | Supported range | Used for |
93
+ | ----------------------------- | ---------------------- | ----------------------------------------------------- |
94
+ | `vitest` | `^5.0.4` | Vitest helpers, including console controls |
95
+ | `@testing-library/react` | `^16.0.0` | DOM queries, interactions, and toggle events |
96
+ | `@testing-library/user-event` | `^14.6.8` | User-like DOM interactions |
97
+ | `@testing-library/jest-dom` | `^7.0.1` | DOM matcher setup used by assertion helpers |
98
+ | `@playwright/test` | `^1.64.0` | Playwright helpers and direct `test`/`expect` exports |
99
+ | `react`, `react-dom` | `^18.0.0` or `^19.0.0` | React integrations and RSC helpers |
100
+ | `@types/react` | `^18.0.0` or `^19.0.0` | React TypeScript types |
101
+
102
+ All peers are optional at the package level. Install the peers required by the entrypoints your project imports.
103
+ In particular, the promises entrypoint does not require any Library, and the console entrypoint requires vitest only.
104
+
105
+ Configure Vitest to use a DOM environment for tests that render components, and load the jest-dom Vitest matchers from a setup file:
106
+
107
+ ```ts
108
+ // vitest.config.ts
109
+ import { defineConfig } from "vitest/config";
110
+
111
+ export default defineConfig({
112
+ test: {
113
+ environment: "jsdom",
114
+ setupFiles: ["./tests/setup.ts"],
115
+ },
116
+ });
117
+ ```
118
+
119
+ ```ts
120
+ // tests/setup.ts
121
+ import "@testing-library/jest-dom/vitest";
122
+ ```
123
+
124
+ ## Vitest utilities
125
+
126
+ The aggregate entrypoint, `@vickbk/tests/vitest`, re-exports the Vitest helper categories. For smaller dependency footprints, import from `@vickbk/tests/vitest/console` or `@vickbk/tests/vitest/dom` instead.
127
+
128
+ ### Console controls
129
+
130
+ The console entrypoint exports `shutConsole` and `resetConsole`. These helpers suppress `console.log`, `console.warn`, and `console.error` during tests, then restore the original implementations.
131
+
132
+ ```ts
133
+ import { afterEach, beforeEach } from "vitest";
134
+ import { resetConsole, shutConsole } from "@vickbk/tests/vitest/console";
135
+
136
+ beforeEach(shutConsole);
137
+ afterEach(resetConsole);
138
+ ```
139
+
140
+ Console output is not suppressed merely by importing the module. Call `shutConsole()` to activate the spies and `resetConsole()` to restore the methods.
141
+
142
+ ### DOM assertions and interactions
143
+
144
+ Import DOM helpers from the dedicated DOM entrypoint:
145
+
146
+ ```tsx
147
+ import { render } from "@testing-library/react";
148
+ import { shouldHaveTestId, shouldSee } from "@vickbk/tests/vitest/dom";
149
+
150
+ render(
151
+ <main>
152
+ <h1>Welcome</h1>
153
+ <button data-testid="save-button">Save</button>
154
+ </main>,
155
+ );
156
+
157
+ const [heading] = shouldSee("Welcome");
158
+ const [saveButton] = shouldHaveTestId("save-button");
159
+ ```
160
+
161
+ `shouldSee` returns the matched elements, while `shouldHaveTestId` returns the elements located by test ID.
162
+
163
+ Other DOM helpers include `shouldNotSee`, `isChecked`, `isNotChecked`, `shouldHaveAttributes`, `shouldNotHaveTestId`, `userClicks`, `userTypes`, `userTypesMultiple`, and `togglePopover`.
164
+
165
+ ### Toggle events
166
+
167
+ The DOM entrypoint provides its own `fireEvent`, combining standard Testing Library event helpers with the package's `toggle` helper. No separate toggle-event installation is needed.
168
+
169
+ ```ts
170
+ import { fireEvent } from "@vickbk/tests/vitest/dom";
171
+
172
+ fireEvent.click(document.body);
173
+ fireEvent.toggle(document.body);
174
+ fireEvent.toggle(document.body, {
175
+ oldState: "open",
176
+ newState: "closed",
177
+ });
178
+ ```
179
+
180
+ `fireEvent.toggle(element, config?)` defaults to `oldState: "closed"` and `newState: "open"`. Either state can be overridden independently. The package-owned `fireEvent` does not augment or modify Testing Library's original export.
181
+
182
+ ### Aggregate entrypoint and compatibility
183
+
184
+ The `@vickbk/tests/vitest` entrypoint continues to export the console and DOM helpers, along with `resolvedPromise` and `rejectedPromise`.
185
+
186
+ The promise re-exports are deprecated. Import these helpers from `@vickbk/tests/promises` in new code and when migrating existing imports.
187
+
188
+ The aggregate entrypoint is convenient when a project uses all the Vitest helper categories. It is not intended to provide the same dependency isolation as the specialized entrypoints.
189
+
190
+ [For more details on the Vitest API](./src/features/vitest/README.md)
191
+
192
+ ## React utilities
193
+
194
+ The React entrypoint exposes `resolveRscTree` for resolving React Server Component trees.
195
+
196
+ ```tsx
197
+ import { resolveRscTree } from "@vickbk/tests/react";
198
+
199
+ const resolved = await resolveRscTree(<ServerPage />);
200
+ ```
201
+
202
+ [For more on the React API](./src/features/react/README.md)
203
+
204
+ ## Playwright utilities
205
+
206
+ Playwright helpers are imported from `@vickbk/tests/playwright`.
207
+
208
+ ```ts
209
+ import { expect, test } from "@playwright/test";
210
+ import { clickButton, getButton, shouldSee } from "@vickbk/tests/playwright";
211
+
212
+ test("saves the page", async ({ page }) => {
213
+ await page.goto("/");
214
+ await shouldSee(page, "Welcome");
215
+ await clickButton(page, "Save");
216
+ await expect(getButton(page, "Save")).toBeVisible();
217
+ });
218
+ ```
219
+
220
+ The public API also includes `shouldNotSee`, `isChecked`, `isNotChecked`, `getLocatorByText`, `getLabel`, `getLink`, `fillLocatorWith`, `setLocatorValue`, `setValueForLocators`, `clickLink`, `clickLabelInput`, `clickMultipleLabelInputs`, `clickBodyCorner`, and `runSimilarTests`.
221
+
222
+ [For more details on the Playwright API](./src/features/playwright/README.md)
223
+
224
+ ## License
225
+
226
+ MIT
@@ -0,0 +1,39 @@
1
+ import { vi } from "vitest";
2
+ //#region src/features/vitest/modules/console/utils/console.ts
3
+ const CONSOLES = [
4
+ "log",
5
+ "warn",
6
+ "error"
7
+ ];
8
+ let activeSpies = [];
9
+ /**
10
+ * Suppresses console.log, console.warn, and console.error until resetConsole runs.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * beforeEach(shutConsole);
15
+ * afterEach(resetConsole);
16
+ * ```
17
+ */
18
+ function shutConsole() {
19
+ resetConsole();
20
+ activeSpies = CONSOLES.map((cons) => vi.spyOn(console, cons).mockImplementation(() => {}));
21
+ }
22
+ /**
23
+ * Restores the console methods most recently suppressed by shutConsole.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * shutConsole();
28
+ * // Run code whose console output should be ignored.
29
+ * resetConsole();
30
+ * ```
31
+ */
32
+ function resetConsole() {
33
+ for (const spy of activeSpies) spy.mockRestore();
34
+ activeSpies = [];
35
+ }
36
+ //#endregion
37
+ export { shutConsole as n, resetConsole as t };
38
+
39
+ //# sourceMappingURL=console-Cf1taTRK.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console-Cf1taTRK.mjs","names":[],"sources":["../src/features/vitest/modules/console/utils/console.ts"],"sourcesContent":["import { MockInstance, vi } from \"vitest\";\n\nconst CONSOLES = [\"log\", \"warn\", \"error\"] as const;\n\nlet activeSpies: MockInstance[] = [];\n\n/**\n * Suppresses console.log, console.warn, and console.error until resetConsole runs.\n *\n * @example\n * ```ts\n * beforeEach(shutConsole);\n * afterEach(resetConsole);\n * ```\n */\nexport function shutConsole() {\n resetConsole();\n\n activeSpies = CONSOLES.map((cons) =>\n vi.spyOn(console, cons).mockImplementation(() => {}),\n );\n}\n\n/**\n * Restores the console methods most recently suppressed by shutConsole.\n *\n * @example\n * ```ts\n * shutConsole();\n * // Run code whose console output should be ignored.\n * resetConsole();\n * ```\n */\nexport function resetConsole() {\n for (const spy of activeSpies) {\n spy.mockRestore(); // Restores native console behavior\n }\n activeSpies = [];\n}\n"],"mappings":";;AAEA,MAAM,WAAW;CAAC;CAAO;CAAQ;AAAO;AAExC,IAAI,cAA8B,CAAC;;;;;;;;;;AAWnC,SAAgB,cAAc;CAC5B,aAAa;CAEb,cAAc,SAAS,KAAK,SAC1B,GAAG,MAAM,SAAS,IAAI,CAAC,CAAC,yBAAyB,CAAC,CAAC,CACrD;AACF;;;;;;;;;;;AAYA,SAAgB,eAAe;CAC7B,KAAK,MAAM,OAAO,aAChB,IAAI,YAAY;CAElB,cAAc,CAAC;AACjB"}