@apitree.cz/testing-library 0.1.0-next.05dd9cd

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 ADDED
@@ -0,0 +1,45 @@
1
+ <div align="center">
2
+
3
+ <a href="https://github.com/ApiTreeCZ">
4
+ <img alt="ApiTree s.r.o." src="https://www.apitree.cz/static/images/logo-header.svg" width="120" />
5
+ </a>
6
+
7
+ # Testing Library
8
+
9
+ ### [React Testing Library](https://testing-library.com/docs/react-testing-library/intro/) setup for [Vitest](https://vitest.dev) in ApiTree projects.
10
+
11
+ </div>
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pnpm add --save-dev @apitree.cz/testing-library @apitree.cz/vitest-config vitest
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ 1. Create `vitest.config.ts` in your project root:
22
+
23
+ ```typescript
24
+ export { config as default } from '@apitree.cz/vitest-config/react';
25
+ ```
26
+
27
+ 2. Create `tests/setup.ts`:
28
+
29
+ ```typescript
30
+ import '@apitree.cz/testing-library/setup';
31
+ ```
32
+
33
+ 3. Create test renderers in `tests/testing-library.ts`
34
+
35
+ ```typescript jsx
36
+ import { createRenderers } from '@apitree.cz/testing-library';
37
+ export * from '@apitree.cz/testing-library';
38
+ export const { render, renderHook } = createRenderers();
39
+ ```
40
+
41
+ > See [`CreateRenderersProps`](./src/testing-library.ts) for `createRenderers` props reference.
42
+
43
+ 4. Write your tests in `tests` directory and run them with `vitest --run` command.
44
+
45
+ > Use `tests/testing-library.ts` for importing Testing Library utilities.
@@ -0,0 +1 @@
1
+ export * from './testing-library.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './testing-library.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom/vitest';
package/dist/setup.js ADDED
@@ -0,0 +1,5 @@
1
+ import { cleanup } from '@testing-library/react';
2
+ import { afterEach } from 'vitest';
3
+ import '@testing-library/jest-dom/vitest';
4
+ afterEach(() => cleanup());
5
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,kCAAkC,CAAC;AAE1C,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { RenderHookOptions, RenderOptions } from '@testing-library/react';
2
+ import type { ReactElement } from 'react';
3
+ export interface CreateRenderersProps {
4
+ defaultWrapper?: RenderOptions['wrapper'] | undefined;
5
+ }
6
+ export declare const createRenderers: ({ defaultWrapper, }?: CreateRenderersProps) => {
7
+ render: (ui: ReactElement, options?: RenderOptions) => import("@testing-library/react").RenderResult<typeof import("@testing-library/dom/types/queries.js"), HTMLElement, HTMLElement>;
8
+ renderHook: <Result, Props>(render: (initialProps: Props) => Result, options?: RenderHookOptions<Props, typeof import("@testing-library/dom/types/queries.js"), HTMLElement, HTMLElement> | undefined) => import("@testing-library/react").RenderHookResult<Result, Props>;
9
+ };
10
+ export { queries } from '@testing-library/dom';
11
+ export * from '@testing-library/react';
12
+ export * from '@testing-library/user-event';
@@ -0,0 +1,18 @@
1
+ import { render, renderHook } from '@testing-library/react';
2
+ export const createRenderers = ({ defaultWrapper = function defaultWrapper({ children }) {
3
+ return children;
4
+ }, } = {}) => {
5
+ const customRender = (ui, options) => {
6
+ const { wrapper = defaultWrapper } = options ?? {};
7
+ return render(ui, { ...options, wrapper });
8
+ };
9
+ const customRenderHook = (render, options) => {
10
+ const { wrapper = defaultWrapper } = options ?? {};
11
+ return renderHook(render, { ...options, wrapper });
12
+ };
13
+ return { render: customRender, renderHook: customRenderHook };
14
+ };
15
+ export { queries } from '@testing-library/dom';
16
+ export * from '@testing-library/react';
17
+ export * from '@testing-library/user-event';
18
+ //# sourceMappingURL=testing-library.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing-library.js","sourceRoot":"","sources":["../src/testing-library.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAU5D,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAC9B,cAAc,GAAG,SAAS,cAAc,CAAC,EAAE,QAAQ,EAAE;IACnD,OAAO,QAAQ,CAAC;AAClB,CAAC,MACuB,EAAE,EAAE,EAAE;IAC9B,MAAM,YAAY,GAAG,CAAC,EAAgB,EAAE,OAAuB,EAAE,EAAE;QACjE,MAAM,EAAE,OAAO,GAAG,cAAc,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QACnD,OAAO,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;IAC7C,CAAC,CAAC;IACF,MAAM,gBAAgB,GAAG,CACvB,MAAuC,EACvC,OAAkC,EAClC,EAAE;QACF,MAAM,EAAE,OAAO,GAAG,cAAc,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QACnD,OAAO,UAAU,CAAC,MAAM,EAAE,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;IACrD,CAAC,CAAC;IACF,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC;AAChE,CAAC,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@apitree.cz/testing-library",
3
+ "version": "0.1.0-next.05dd9cd",
4
+ "description": "React Testing Library setup for Vitest in ApiTree projects.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/ApiTreeCZ/toolbox",
8
+ "directory": "packages/testing-library"
9
+ },
10
+ "sideEffects": false,
11
+ "type": "module",
12
+ "exports": {
13
+ ".": "./dist/index.js",
14
+ "./setup": "./dist/setup.js"
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "dependencies": {
20
+ "@testing-library/dom": "^9.3.3",
21
+ "@testing-library/jest-dom": "^6.1.4",
22
+ "@testing-library/react": "^14.0.0",
23
+ "@testing-library/user-event": "^14.5.1",
24
+ "jsdom": "^22.1.0"
25
+ },
26
+ "devDependencies": {
27
+ "@types/react": "^18.2.33",
28
+ "@types/react-dom": "^18.2.14",
29
+ "@vitest/coverage-istanbul": "^0.34.6",
30
+ "react": "^18.2.0",
31
+ "react-dom": "^18.2.0",
32
+ "vitest": "^0.34.6",
33
+ "@apitree.cz/vitest-config": "0.1.0-next.05dd9cd"
34
+ },
35
+ "peerDependencies": {
36
+ "react": "^18.2.0",
37
+ "react-dom": "^18.2.0",
38
+ "vitest": "^0.34.6"
39
+ },
40
+ "scripts": {
41
+ "build": "tsc --build tsconfig.build.json",
42
+ "cleanup": "rimraf .eslintcache .turbo tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo dist node_modules",
43
+ "fix": "run-p ts format:fix lint:fix",
44
+ "format": "prettier --check \"./**/*.{json,md}\"",
45
+ "format:fix": "pnpm run format --write",
46
+ "lint": "eslint --cache --ext cjs,ts,tsx .",
47
+ "lint:fix": "pnpm run lint --fix",
48
+ "qa": "run-p ts format lint",
49
+ "test": "vitest --run",
50
+ "test:coverage": "pnpm run test --coverage",
51
+ "ts": "tsc --build tsconfig.json"
52
+ }
53
+ }