@noma.to/qwik-testing-library 1.4.0 → 1.5.1
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 +17 -67
- package/lib/lib/qwik-testing-library.qwik.cjs +10 -15
- package/lib/lib/qwik-testing-library.qwik.mjs +10 -15
- package/lib/setup.qwik.cjs +8 -0
- package/lib/setup.qwik.mjs +8 -0
- package/lib-types/lib/qwik-testing-library.d.ts +1 -1
- package/lib-types/setup.d.ts +7 -0
- package/package.json +16 -11
package/README.md
CHANGED
|
@@ -131,7 +131,7 @@ should be installed as one of your project's `devDependencies`:
|
|
|
131
131
|
npm install --save-dev @noma.to/qwik-testing-library @testing-library/dom
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
-
This library supports `qwik` versions `1.
|
|
134
|
+
This library supports `qwik` versions `1.12.0` and above and `@testing-library/dom` versions `10.1.0` and above.
|
|
135
135
|
|
|
136
136
|
You may also be interested in installing `@testing-library/jest-dom` and `@testing-library/user-event` so you can
|
|
137
137
|
use [the custom jest matchers][jest-dom] and [the user event library][user-event] to test interactions with the DOM.
|
|
@@ -162,80 +162,30 @@ npm install --save-dev happy-dom
|
|
|
162
162
|
We recommend using `@noma.to/qwik-testing-library` with [Vitest][vitest] as your test
|
|
163
163
|
runner.
|
|
164
164
|
|
|
165
|
-
If you haven't done so already,
|
|
165
|
+
If you haven't done so already, install vitest:
|
|
166
166
|
|
|
167
167
|
```shell
|
|
168
|
-
npm
|
|
168
|
+
npm install --save-dev vitest
|
|
169
169
|
```
|
|
170
170
|
|
|
171
171
|
After that, we need to configure Vitest so it can run your tests.
|
|
172
|
-
|
|
172
|
+
Add the `test` section to your `vite.config.ts`:
|
|
173
173
|
|
|
174
174
|
```ts
|
|
175
|
-
//
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
// if it's already a Qwik lib, you can remove this section
|
|
186
|
-
build: {
|
|
187
|
-
target: "es2020",
|
|
188
|
-
lib: {
|
|
189
|
-
entry: "./src/index.ts",
|
|
190
|
-
formats: ["es", "cjs"],
|
|
191
|
-
fileName: (format, entryName) =>
|
|
192
|
-
`${entryName}.qwik.${format === "es" ? "mjs" : "cjs"}`,
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
// configure your test environment
|
|
196
|
-
test: {
|
|
197
|
-
environment: "jsdom", // or "happy-dom"
|
|
198
|
-
setupFiles: ["./vitest.setup.ts"],
|
|
199
|
-
globals: true,
|
|
200
|
-
},
|
|
201
|
-
}),
|
|
202
|
-
),
|
|
203
|
-
);
|
|
175
|
+
// vite.config.ts
|
|
176
|
+
|
|
177
|
+
test: {
|
|
178
|
+
environment: "jsdom", // or "happy-dom"
|
|
179
|
+
setupFiles: [
|
|
180
|
+
"@noma.to/qwik-testing-library/setup",
|
|
181
|
+
"@testing-library/jest-dom/vitest", // optional, for DOM matchers
|
|
182
|
+
],
|
|
183
|
+
globals: true,
|
|
184
|
+
},
|
|
204
185
|
```
|
|
205
186
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
As the build will try to use `./src/index.ts` as the entry point, we need to create it:
|
|
210
|
-
|
|
211
|
-
```ts
|
|
212
|
-
// ./src/index.ts
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* DO NOT DELETE THIS FILE
|
|
216
|
-
*
|
|
217
|
-
* This entrypoint is needed by @noma.to/qwik-testing-library to run your tests
|
|
218
|
-
*/
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
Then, create the `vitest.setup.ts` file:
|
|
222
|
-
|
|
223
|
-
```ts
|
|
224
|
-
// vitest.setup.ts
|
|
225
|
-
|
|
226
|
-
// Configure DOM matchers to work in Vitest
|
|
227
|
-
import "@testing-library/jest-dom/vitest";
|
|
228
|
-
|
|
229
|
-
// This has to run before qdev.ts loads. `beforeAll` is too late
|
|
230
|
-
globalThis.qTest = false; // Forces Qwik to run as if it was in a Browser
|
|
231
|
-
globalThis.qRuntimeQrl = true;
|
|
232
|
-
globalThis.qDev = true;
|
|
233
|
-
globalThis.qInspector = false;
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
This setup will make sure that Qwik is properly configured.
|
|
237
|
-
It also loads `@testing-library/jest-dom/vitest` in your test runner
|
|
238
|
-
so you can use matchers like `expect(...).toBeInTheDocument()`.
|
|
187
|
+
The `@noma.to/qwik-testing-library/setup` module configures Qwik globals (`qTest`, `qRuntimeQrl`, `qDev`,
|
|
188
|
+
`qInspector`) for testing. It must run before any Qwik code loads, which is why it's added to `setupFiles`.
|
|
239
189
|
|
|
240
190
|
By default, Qwik Testing Library cleans everything up automatically for you.
|
|
241
191
|
You can opt out of this by setting the environment variable `QTL_SKIP_AUTO_CLEANUP` to `true`.
|
|
@@ -309,7 +259,7 @@ describe("<Counter />", () => {
|
|
|
309
259
|
await user.click(incrementBtn);
|
|
310
260
|
|
|
311
261
|
// assert that the counter is now 2
|
|
312
|
-
await
|
|
262
|
+
expect(await screen.findByText(/count:2/)).toBeInTheDocument();
|
|
313
263
|
});
|
|
314
264
|
})
|
|
315
265
|
```
|
|
@@ -55,21 +55,17 @@ async function render(ui, options = {}) {
|
|
|
55
55
|
baseElement = document.body;
|
|
56
56
|
}
|
|
57
57
|
if (!container) {
|
|
58
|
-
container = baseElement.insertBefore(
|
|
58
|
+
container = baseElement.insertBefore(
|
|
59
|
+
document.createElement("host"),
|
|
60
|
+
baseElement.firstChild
|
|
61
|
+
);
|
|
59
62
|
}
|
|
60
|
-
const wrappedUi = !Wrapper ? ui : /* @__PURE__ */ jsxRuntime.jsx(Wrapper, {
|
|
61
|
-
children: ui
|
|
62
|
-
});
|
|
63
|
+
const wrappedUi = !Wrapper ? ui : /* @__PURE__ */ jsxRuntime.jsx(Wrapper, { children: ui });
|
|
63
64
|
const doc = baseElement.ownerDocument;
|
|
64
65
|
const win = doc.defaultView;
|
|
65
66
|
new Function("document", "window", server.getQwikLoaderScript())(doc, win);
|
|
66
|
-
const { cleanup: cleanup2 } = await qwik.render(container, wrappedUi, {
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
mountedContainers.add({
|
|
70
|
-
container,
|
|
71
|
-
componentCleanup: cleanup2
|
|
72
|
-
});
|
|
67
|
+
const { cleanup: cleanup2 } = await qwik.render(container, wrappedUi, { serverData });
|
|
68
|
+
mountedContainers.add({ container, componentCleanup: cleanup2 });
|
|
73
69
|
return {
|
|
74
70
|
container,
|
|
75
71
|
baseElement,
|
|
@@ -82,10 +78,9 @@ async function render(ui, options = {}) {
|
|
|
82
78
|
return template.content;
|
|
83
79
|
}
|
|
84
80
|
},
|
|
85
|
-
debug: (el = baseElement, maxLength, options2) => Array.isArray(el) ? el.forEach((e) => console.log(dom.prettyDOM(e, maxLength, options2))) : console.log(
|
|
86
|
-
...options2,
|
|
87
|
-
|
|
88
|
-
})),
|
|
81
|
+
debug: (el = baseElement, maxLength, options2) => Array.isArray(el) ? el.forEach((e) => console.log(dom.prettyDOM(e, maxLength, options2))) : console.log(
|
|
82
|
+
dom.prettyDOM(el, maxLength, { ...options2, filterNode: () => true })
|
|
83
|
+
),
|
|
89
84
|
unmount: cleanup2,
|
|
90
85
|
...dom.getQueriesForElement(container, queries)
|
|
91
86
|
};
|
|
@@ -32,21 +32,17 @@ async function render(ui, options = {}) {
|
|
|
32
32
|
baseElement = document.body;
|
|
33
33
|
}
|
|
34
34
|
if (!container) {
|
|
35
|
-
container = baseElement.insertBefore(
|
|
35
|
+
container = baseElement.insertBefore(
|
|
36
|
+
document.createElement("host"),
|
|
37
|
+
baseElement.firstChild
|
|
38
|
+
);
|
|
36
39
|
}
|
|
37
|
-
const wrappedUi = !Wrapper ? ui : /* @__PURE__ */ jsx(Wrapper, {
|
|
38
|
-
children: ui
|
|
39
|
-
});
|
|
40
|
+
const wrappedUi = !Wrapper ? ui : /* @__PURE__ */ jsx(Wrapper, { children: ui });
|
|
40
41
|
const doc = baseElement.ownerDocument;
|
|
41
42
|
const win = doc.defaultView;
|
|
42
43
|
new Function("document", "window", getQwikLoaderScript())(doc, win);
|
|
43
|
-
const { cleanup: cleanup2 } = await qwik.render(container, wrappedUi, {
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
mountedContainers.add({
|
|
47
|
-
container,
|
|
48
|
-
componentCleanup: cleanup2
|
|
49
|
-
});
|
|
44
|
+
const { cleanup: cleanup2 } = await qwik.render(container, wrappedUi, { serverData });
|
|
45
|
+
mountedContainers.add({ container, componentCleanup: cleanup2 });
|
|
50
46
|
return {
|
|
51
47
|
container,
|
|
52
48
|
baseElement,
|
|
@@ -59,10 +55,9 @@ async function render(ui, options = {}) {
|
|
|
59
55
|
return template.content;
|
|
60
56
|
}
|
|
61
57
|
},
|
|
62
|
-
debug: (el = baseElement, maxLength, options2) => Array.isArray(el) ? el.forEach((e) => console.log(prettyDOM(e, maxLength, options2))) : console.log(
|
|
63
|
-
...options2,
|
|
64
|
-
|
|
65
|
-
})),
|
|
58
|
+
debug: (el = baseElement, maxLength, options2) => Array.isArray(el) ? el.forEach((e) => console.log(prettyDOM(e, maxLength, options2))) : console.log(
|
|
59
|
+
prettyDOM(el, maxLength, { ...options2, filterNode: () => true })
|
|
60
|
+
),
|
|
66
61
|
unmount: cleanup2,
|
|
67
62
|
...getQueriesForElement(container, queries)
|
|
68
63
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
globalThis.qTest = false;
|
|
4
|
+
globalThis.qRuntimeQrl = true;
|
|
5
|
+
globalThis.qDev = true;
|
|
6
|
+
globalThis.qInspector = false;
|
|
7
|
+
const __qwikSetupComplete = true;
|
|
8
|
+
exports.__qwikSetupComplete = __qwikSetupComplete;
|
package/package.json
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noma.to/qwik-testing-library",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Simple and complete Qwik testing utilities that encourage good testing practices.",
|
|
5
5
|
"repository": "https://github.com/ianlet/qwik-testing-library",
|
|
6
6
|
"homepage": "https://github.com/ianlet/qwik-testing-library",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"main": "./lib/index.qwik.mjs",
|
|
9
|
-
"qwik": "./lib/index.qwik.mjs",
|
|
10
9
|
"types": "./lib-types/index.d.ts",
|
|
10
|
+
"qwik": "./lib/index.qwik.mjs",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
13
|
"types": "./lib-types/index.d.ts",
|
|
14
14
|
"import": "./lib/index.qwik.mjs",
|
|
15
15
|
"require": "./lib/index.qwik.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./setup": {
|
|
18
|
+
"types": "./lib-types/setup.d.ts",
|
|
19
|
+
"import": "./lib/setup.qwik.mjs",
|
|
20
|
+
"require": "./lib/setup.qwik.cjs"
|
|
16
21
|
}
|
|
17
22
|
},
|
|
18
23
|
"files": [
|
|
@@ -35,17 +40,17 @@
|
|
|
35
40
|
},
|
|
36
41
|
"devDependencies": {
|
|
37
42
|
"@types/eslint": "8.56.10",
|
|
38
|
-
"@types/node": "
|
|
39
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
40
|
-
"@typescript-eslint/parser": "8.
|
|
43
|
+
"@types/node": "25.1.0",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "8.54.0",
|
|
45
|
+
"@typescript-eslint/parser": "8.54.0",
|
|
41
46
|
"eslint": "8.57.1",
|
|
42
|
-
"eslint-plugin-qwik": "1.
|
|
43
|
-
"prettier": "3.
|
|
44
|
-
"typescript": "5.9.
|
|
47
|
+
"eslint-plugin-qwik": "1.19.0",
|
|
48
|
+
"prettier": "3.8.1",
|
|
49
|
+
"typescript": "5.9.3",
|
|
45
50
|
"undici": "*",
|
|
46
|
-
"vite": "7.1
|
|
47
|
-
"vite-tsconfig-paths": "^
|
|
48
|
-
"vitest": "^
|
|
51
|
+
"vite": "7.3.1",
|
|
52
|
+
"vite-tsconfig-paths": "^6.0.5",
|
|
53
|
+
"vitest": "^4.0.18"
|
|
49
54
|
},
|
|
50
55
|
"peerDependencies": {
|
|
51
56
|
"@builder.io/qwik": ">= 1.12.0 < 2",
|