@jterrazz/test 2.0.2 → 3.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jean-Baptiste Terrazzoni <contact@jterrazz.com>
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,26 +1,96 @@
1
1
  # Package Typescript Test
2
2
 
3
- This package provides Jest configuration and test packages for TypeScript projects.
3
+ This package provides Vitest configuration and testing utilities for TypeScript projects, including MSW (Mock Service Worker) setup for API mocking.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Install the package using npm:
8
8
 
9
9
  ```bash
10
- npm install @jterrazz/test --save-dev
10
+ npm install -D @jterrazz/test
11
11
  ```
12
12
 
13
13
  ## Usage
14
14
 
15
- 1. Create a Jest configuration file (e.g., `jest.config.js`) in your project root:
15
+ 1. Set up MSW for API mocking:
16
16
 
17
- ```javascript
18
- // jest.config.js
19
- import { jestConfig } from '@jterrazz/package-typescript-test';
17
+ ```typescript
18
+ // handlers.ts
19
+ import { http } from 'msw';
20
+ import { setupServer } from '@jterrazz/test';
20
21
 
21
- export default jestConfig();
22
+ // Define your API handlers
23
+ const handlers = [
24
+ http.get('/api/example', () => {
25
+ return new Response(JSON.stringify({ data: 'example' }));
26
+ }),
27
+ ];
28
+
29
+ // Setup MSW server
30
+ export const server = setupServer(...handlers);
31
+ ```
32
+
33
+ 2. You can now write your tests using Vitest and MSW!
34
+
35
+ ```typescript
36
+ import { describe, test, expect } from '@jterrazz/test';
37
+ import { server } from './handlers';
38
+
39
+ describe('API Tests', () => {
40
+ test('should handle API requests', async () => {
41
+ const response = await fetch('/api/example');
42
+ const data = await response.json();
43
+
44
+ expect(data).toEqual({ data: 'example' });
45
+ });
46
+ });
47
+ ```
48
+
49
+ 3. Using Date Mocking:
50
+
51
+ ```typescript
52
+ import { mockOfDate } from '@jterrazz/test';
53
+
54
+ describe('Date Tests', () => {
55
+ test('should mock dates', () => {
56
+ const fixedDate = new Date('2024-01-01');
57
+ mockOfDate.set(fixedDate);
58
+
59
+ expect(new Date()).toEqual(fixedDate);
60
+
61
+ // Reset the mock after your test
62
+ mockOfDate.reset();
63
+ });
64
+ });
65
+ ```
66
+
67
+ 4. Using Extended Mocking:
68
+
69
+ ```typescript
70
+ import { mockOf } from '@jterrazz/test';
71
+
72
+ interface UserService {
73
+ getUser: (id: string) => Promise<{ id: string; name: string }>;
74
+ }
75
+
76
+ describe('Mock Tests', () => {
77
+ test('should use extended mocks', async () => {
78
+ const mockUserService = mockOf<UserService>();
79
+
80
+ // Setup mock behavior
81
+ mockUserService.getUser.mockResolvedValue({ id: '1', name: 'John' });
82
+
83
+ const user = await mockUserService.getUser('1');
84
+ expect(user).toEqual({ id: '1', name: 'John' });
85
+ });
86
+ });
22
87
  ```
23
88
 
24
- 2. You can now test your TypeScript project!
89
+ ## Features
90
+
91
+ - Vitest configuration with TypeScript support
92
+ - MSW integration for API mocking
93
+ - Mock date utilities for time-based testing
94
+ - Extended mocking capabilities with vitest-mock-extended
25
95
 
26
96
  Happy testing! 🚀
package/dist/index.cjs ADDED
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ require('msw');
4
+ var MockDatePackage = require('mockdate');
5
+ var vitestMockExtended = require('vitest-mock-extended');
6
+ var vitest = require('vitest');
7
+
8
+ var mockOfDate = MockDatePackage;
9
+ // Mock of Generic Types
10
+ var mockOf = vitestMockExtended.mockDeep;
11
+
12
+ exports.mockOf = mockOf;
13
+ exports.mockOfDate = mockOfDate;
14
+ Object.keys(vitest).forEach(function (k) {
15
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
16
+ enumerable: true,
17
+ get: function () { return vitest[k]; }
18
+ });
19
+ });
package/dist/index.d.ts CHANGED
@@ -1,5 +1,2 @@
1
- import jestConfig from './jest/main.js';
2
- import jestEslint from './jest-eslint/main.js';
3
- import jestMockExtended from './jest-mock-extended/main.js';
4
- import msw from './msw/main.js';
5
- export { jestConfig, jestMockExtended, msw, jestEslint };
1
+ export * from './msw/main.js';
2
+ export * from './vitest/main.js';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './msw/main.js';
2
+ export * from './vitest/main.js';
3
+
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './msw/main.js';\nexport * from './vitest/main.js';\n"],"names":[],"mappings":"AAAA,cAAc,gBAAgB;AAC9B,cAAc,mBAAmB"}
@@ -0,0 +1,4 @@
1
+ import * as msw from 'msw';
2
+ export default msw;
3
+
4
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/msw/main.ts"],"sourcesContent":["import * as msw from 'msw';\n\nexport default msw;\n"],"names":["msw"],"mappings":"AAAA,YAAYA,SAAS,MAAM;AAE3B,eAAeA,IAAI"}
@@ -0,0 +1,9 @@
1
+ import { mockDeep } from 'vitest-mock-extended';
2
+ interface MockDatePort {
3
+ reset: () => void;
4
+ set: (date: Date | number | string) => void;
5
+ }
6
+ declare const mockOfDate: MockDatePort;
7
+ declare const mockOf: typeof mockDeep;
8
+ export { mockOf, mockOfDate };
9
+ export * from 'vitest';
@@ -0,0 +1,9 @@
1
+ import MockDatePackage from 'mockdate';
2
+ import { mockDeep } from 'vitest-mock-extended';
3
+ var mockOfDate = MockDatePackage;
4
+ // Mock of Generic Types
5
+ var mockOf = mockDeep;
6
+ export { mockOf, mockOfDate };
7
+ export * from 'vitest';
8
+
9
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/vitest/main.ts"],"sourcesContent":["import MockDatePackage from 'mockdate';\nimport { mockDeep } from 'vitest-mock-extended';\n\n// Mock of Dates\n\ninterface MockDatePort {\n reset: () => void;\n set: (date: Date | number | string) => void;\n}\n\nconst mockOfDate: MockDatePort = MockDatePackage;\n\n// Mock of Generic Types\n\nconst mockOf = mockDeep;\n\nexport { mockOf, mockOfDate };\nexport * from 'vitest';\n"],"names":["MockDatePackage","mockDeep","mockOfDate","mockOf"],"mappings":"AAAA,OAAOA,qBAAqB,WAAW;AACvC,SAASC,QAAQ,QAAQ,uBAAuB;AAShD,IAAMC,aAA2BF;AAEjC,wBAAwB;AAExB,IAAMG,SAASF;AAEf,SAASE,MAAM,EAAED,UAAU,GAAG;AAC9B,cAAc,SAAS"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jterrazz/test",
3
3
  "author": "Jean-Baptiste Terrazzoni <contact@jterrazz.com>",
4
- "version": "2.0.2",
4
+ "version": "3.0.0",
5
5
  "exports": {
6
6
  ".": {
7
7
  "require": "./dist/index.cjs",
@@ -14,22 +14,19 @@
14
14
  "type": "module",
15
15
  "scripts": {
16
16
  "build": "ts-compile",
17
- "build-watch": "ts-compile --watch",
18
- "lint": "quality-check"
17
+ "lint": "code-standards",
18
+ "test": "# No tests"
19
19
  },
20
20
  "devDependencies": {
21
- "@jterrazz/quality": "^2.0.3",
22
- "@jterrazz/typescript": "^2.0.1"
21
+ "@jterrazz/quality": "^2.2.0",
22
+ "@jterrazz/typescript": "^2.2.0"
23
23
  },
24
24
  "dependencies": {
25
- "@swc/jest": "^0.2.36",
26
- "@types/jest": "^29.5.12",
27
- "eslint-plugin-jest": "^28.5.0",
28
- "jest": "^29.7.0",
29
- "jest-mock-extended": "^3.0.7",
30
- "msw": "^2.7.3",
31
- "ts-jest": "^29.1.2",
32
- "tsconfig-to-swcconfig": "^2.7.0"
25
+ "@types/mockdate": "^2.0.0",
26
+ "mockdate": "^3.0.5",
27
+ "msw": "^2.7.5",
28
+ "vitest": "^3.1.2",
29
+ "vitest-mock-extended": "^3.1.0"
33
30
  },
34
31
  "publishConfig": {
35
32
  "registry": "https://registry.npmjs.org/"
package/LICENCE DELETED
@@ -1 +0,0 @@
1
- Copyright (c) 2O24 Jean-Baptiste Terrazzoni <jterrazzoni@gmail.com>. All rights reserved.
@@ -1,2 +0,0 @@
1
- import { JestConfigWithTsJest } from 'ts-jest';
2
- export default function (): Promise<JestConfigWithTsJest>;
@@ -1,2 +0,0 @@
1
- declare const _default: any[];
2
- export default _default;
@@ -1,2 +0,0 @@
1
- import * as jestMockExtended from 'jest-mock-extended';
2
- export default jestMockExtended;