@noma.to/qwik-testing-library 1.0.2 → 1.0.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.
Files changed (2) hide show
  1. package/README.md +69 -13
  2. package/package.json +2 -1
package/README.md CHANGED
@@ -132,7 +132,18 @@ npm install --save-dev @noma.to/qwik-testing-library
132
132
  This library supports `qwik` versions `1.7.2` and above.
133
133
 
134
134
  You may also be interested in installing `@testing-library/jest-dom` so you can
135
- use [the custom jest matchers][jest-dom].
135
+ use [the custom jest matchers][jest-dom] and [the user event library][user-event] to test interactions with the DOM.
136
+
137
+ ```shell
138
+ npm install --save-dev @testing-library/jest-dom @testing-library/user-event
139
+ ```
140
+
141
+ Finally, we need a DOM environment to run the tests in.
142
+ This library was tested (for now) only with `jsdom` so we recommend using it:
143
+
144
+ ```shell
145
+ npm install --save-dev jsdom
146
+ ```
136
147
 
137
148
  [npm]: https://www.npmjs.com/
138
149
 
@@ -140,22 +151,67 @@ use [the custom jest matchers][jest-dom].
140
151
 
141
152
  [jest-dom]: https://github.com/testing-library/jest-dom
142
153
 
154
+ [user-event]: https://github.com/testing-library/user-event
155
+
143
156
  ## Setup
144
157
 
145
158
  We recommend using `@noma.to/qwik-testing-library` with [Vitest][] as your test
146
- runner. To get started, configure how Vite will run your tests.
159
+ runner.
147
160
 
148
- ```diff
149
- // vite.config.js
150
-
151
- export default defineConfig({
152
- plugins: [qwikVite(), tsconfigPaths()],
153
- + test: {
154
- + environment: "jsdom",
155
- + setupFiles: ["./vitest.setup.ts"],
156
- + globals: true,
157
- + },
158
- });
161
+ If you haven't done so already, add vitest to your project using Qwik CLI:
162
+
163
+ ```shell
164
+ npm qwik add vitest
165
+ ```
166
+
167
+ After that, we need to configure Vitest so it can run your tests.
168
+ For this, create a _separate_ `vitest.config.ts` so you don't have to modify your project's `vite.config.ts`:
169
+
170
+ ```ts
171
+ // vitest.config.ts
172
+
173
+ import {defineConfig, mergeConfig} from "vitest/config";
174
+ import viteConfig from "./vite.config";
175
+
176
+ export default defineConfig((configEnv) =>
177
+ mergeConfig(
178
+ viteConfig(configEnv),
179
+ defineConfig({
180
+ // qwik-testing-library needs to consider your project as a Qwik lib
181
+ // if it's already a Qwik lib, you can remove this section
182
+ build: {
183
+ target: "es2020",
184
+ lib: {
185
+ entry: "./src/index.ts",
186
+ formats: ["es", "cjs"],
187
+ fileName: (format, entryName) =>
188
+ `${entryName}.qwik.${format === "es" ? "mjs" : "cjs"}`,
189
+ },
190
+ },
191
+ // configure your test environment
192
+ test: {
193
+ environment: "jsdom",
194
+ setupFiles: ["./vitest.setup.ts"],
195
+ globals: true,
196
+ },
197
+ }),
198
+ ),
199
+ );
200
+ ```
201
+
202
+ For now, `qwik-testing-library` needs to consider your project as a lib ([PR welcomed][prs] to simplify this).
203
+ Hence, the `build.lib` section in the config above.
204
+
205
+ As the build will try to use `./src/index.ts` as the entry point, we need to create it:
206
+
207
+ ```ts
208
+ // ./src/index.ts
209
+
210
+ /**
211
+ * DO NOT DELETE THIS FILE
212
+ *
213
+ * This entrypoint is needed by @noma.to/qwik-testing-library to run your tests
214
+ */
159
215
  ```
160
216
 
161
217
  Then, create the `vitest.setup.ts` file:
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@noma.to/qwik-testing-library",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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
+ "license": "MIT",
7
8
  "main": "./lib/index.qwik.mjs",
8
9
  "qwik": "./lib/index.qwik.mjs",
9
10
  "types": "./lib-types/index.d.ts",