@noma.to/qwik-testing-library 1.5.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 CHANGED
@@ -169,56 +169,19 @@ 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
- For this, create a _separate_ `vitest.config.ts` so you don't have to modify your project's `vite.config.ts`:
172
+ Add the `test` section to your `vite.config.ts`:
173
173
 
174
174
  ```ts
175
- // vitest.config.ts
176
-
177
- import {defineConfig, mergeConfig} from "vitest/config";
178
- import viteConfig from "./vite.config";
179
-
180
- export default defineConfig((configEnv) =>
181
- mergeConfig(
182
- viteConfig(configEnv),
183
- defineConfig({
184
- // qwik-testing-library needs to consider your project as a Qwik lib
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: [
199
- "@noma.to/qwik-testing-library/setup",
200
- "@testing-library/jest-dom/vitest", // optional, for DOM matchers
201
- ],
202
- globals: true,
203
- },
204
- }),
205
- ),
206
- );
207
- ```
208
-
209
- For now, `qwik-testing-library` needs to consider your project as a lib ([PR welcomed][prs] to simplify this).
210
- Hence, the `build.lib` section in the config above.
211
-
212
- As the build will try to use `./src/index.ts` as the entry point, we need to create it:
213
-
214
- ```ts
215
- // ./src/index.ts
216
-
217
- /**
218
- * DO NOT DELETE THIS FILE
219
- *
220
- * This entrypoint is needed by @noma.to/qwik-testing-library to run your tests
221
- */
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
+ },
222
185
  ```
223
186
 
224
187
  The `@noma.to/qwik-testing-library/setup` module configures Qwik globals (`qTest`, `qRuntimeQrl`, `qDev`,
@@ -55,21 +55,17 @@ async function render(ui, options = {}) {
55
55
  baseElement = document.body;
56
56
  }
57
57
  if (!container) {
58
- container = baseElement.insertBefore(document.createElement("host"), baseElement.firstChild);
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
- serverData
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(dom.prettyDOM(el, maxLength, {
86
- ...options2,
87
- filterNode: () => true
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(document.createElement("host"), baseElement.firstChild);
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
- serverData
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(prettyDOM(el, maxLength, {
63
- ...options2,
64
- filterNode: () => true
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
  };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@noma.to/qwik-testing-library",
3
- "version": "1.5.0",
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",