@jterrazz/test 3.0.0 → 3.1.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/README.md CHANGED
@@ -1,72 +1,47 @@
1
- # Package Typescript Test
1
+ *Hey there I’m Jean-Baptiste, just another developer doing weird things with code. All my projects live on [jterrazz.com](https://jterrazz.com) – complete with backstories and lessons learned. Feel free to poke around – you might just find something useful!*
2
2
 
3
- This package provides Vitest configuration and testing utilities for TypeScript projects, including MSW (Mock Service Worker) setup for API mocking.
3
+ # @jterrazz/test
4
4
 
5
- ## Installation
5
+ Mocking utilities for TypeScript testing.
6
6
 
7
- Install the package using npm:
7
+ ## Installation
8
8
 
9
9
  ```bash
10
- npm install -D @jterrazz/test
10
+ npm install -D @jterrazz/test vitest
11
11
  ```
12
12
 
13
- ## Usage
13
+ **Optional:** For API mocking with MSW:
14
14
 
15
- 1. Set up MSW for API mocking:
16
-
17
- ```typescript
18
- // handlers.ts
19
- import { http } from 'msw';
20
- import { setupServer } from '@jterrazz/test';
21
-
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);
15
+ ```bash
16
+ npm install -D msw
31
17
  ```
32
18
 
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
- ```
19
+ ## Usage
48
20
 
49
- 3. Using Date Mocking:
21
+ ### Date Mocking
50
22
 
51
23
  ```typescript
24
+ import { describe, test, expect, afterEach } from 'vitest';
52
25
  import { mockOfDate } from '@jterrazz/test';
53
26
 
54
27
  describe('Date Tests', () => {
28
+ afterEach(() => {
29
+ mockOfDate.reset();
30
+ });
31
+
55
32
  test('should mock dates', () => {
56
33
  const fixedDate = new Date('2024-01-01');
57
34
  mockOfDate.set(fixedDate);
58
35
 
59
36
  expect(new Date()).toEqual(fixedDate);
60
-
61
- // Reset the mock after your test
62
- mockOfDate.reset();
63
37
  });
64
38
  });
65
39
  ```
66
40
 
67
- 4. Using Extended Mocking:
41
+ ### Deep Mocking
68
42
 
69
43
  ```typescript
44
+ import { describe, test, expect } from 'vitest';
70
45
  import { mockOf } from '@jterrazz/test';
71
46
 
72
47
  interface UserService {
@@ -74,10 +49,9 @@ interface UserService {
74
49
  }
75
50
 
76
51
  describe('Mock Tests', () => {
77
- test('should use extended mocks', async () => {
52
+ test('should use deep mocks', async () => {
78
53
  const mockUserService = mockOf<UserService>();
79
54
 
80
- // Setup mock behavior
81
55
  mockUserService.getUser.mockResolvedValue({ id: '1', name: 'John' });
82
56
 
83
57
  const user = await mockUserService.getUser('1');
@@ -86,11 +60,16 @@ describe('Mock Tests', () => {
86
60
  });
87
61
  ```
88
62
 
89
- ## Features
63
+ ## API
64
+
65
+ | Export | Description |
66
+ |--------|-------------|
67
+ | `mockOfDate` | Date mocking utilities (`set`, `reset`) |
68
+ | `mockOf<T>()` | Create deep mock of any interface |
69
+ | `MockDatePort` | Type interface for date mocking |
70
+ | `MockPort` | Type interface for deep mocking |
90
71
 
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
72
+ ## Peer Dependencies
95
73
 
96
- Happy testing! 🚀
74
+ - `vitest` (required)
75
+ - `msw` (optional)
package/dist/index.cjs CHANGED
@@ -1,19 +1,11 @@
1
1
  'use strict';
2
2
 
3
- require('msw');
4
3
  var MockDatePackage = require('mockdate');
5
4
  var vitestMockExtended = require('vitest-mock-extended');
6
- var vitest = require('vitest');
7
5
 
8
6
  var mockOfDate = MockDatePackage;
9
- // Mock of Generic Types
7
+
10
8
  var mockOf = vitestMockExtended.mockDeep;
11
9
 
12
10
  exports.mockOf = mockOf;
13
11
  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,2 +1 @@
1
- export * from './msw/main.js';
2
- export * from './vitest/main.js';
1
+ export * from './mocking/index.js';
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- export * from './msw/main.js';
2
- export * from './vitest/main.js';
1
+ export * from './mocking/index.js';
3
2
 
4
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +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"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './mocking/index.js';\n"],"names":[],"mappings":"AAAA,cAAc,qBAAqB"}
@@ -0,0 +1,2 @@
1
+ export { type MockDatePort, mockOfDate } from './mock-of-date.js';
2
+ export { mockOf, type MockPort } from './mock-of.js';
@@ -0,0 +1,4 @@
1
+ export { mockOfDate } from './mock-of-date.js';
2
+ export { mockOf } from './mock-of.js';
3
+
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/mocking/index.ts"],"sourcesContent":["export { type MockDatePort, mockOfDate } from './mock-of-date.js';\nexport { mockOf, type MockPort } from './mock-of.js';\n"],"names":["mockOfDate","mockOf"],"mappings":"AAAA,SAA4BA,UAAU,QAAQ,oBAAoB;AAClE,SAASC,MAAM,QAAuB,eAAe"}
@@ -0,0 +1,5 @@
1
+ export interface MockDatePort {
2
+ reset: () => void;
3
+ set: (date: Date | number | string) => void;
4
+ }
5
+ export declare const mockOfDate: MockDatePort;
@@ -0,0 +1,4 @@
1
+ import MockDatePackage from 'mockdate';
2
+ export var mockOfDate = MockDatePackage;
3
+
4
+ //# sourceMappingURL=mock-of-date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/mocking/mock-of-date.ts"],"sourcesContent":["import MockDatePackage from 'mockdate';\n\nexport interface MockDatePort {\n reset: () => void;\n set: (date: Date | number | string) => void;\n}\n\nexport const mockOfDate: MockDatePort = MockDatePackage;\n"],"names":["MockDatePackage","mockOfDate"],"mappings":"AAAA,OAAOA,qBAAqB,WAAW;AAOvC,OAAO,IAAMC,aAA2BD,gBAAgB"}
@@ -0,0 +1,3 @@
1
+ import { type DeepMockProxy } from 'vitest-mock-extended';
2
+ export type MockPort = <T>() => DeepMockProxy<T>;
3
+ export declare const mockOf: MockPort;
@@ -0,0 +1,4 @@
1
+ import { mockDeep } from 'vitest-mock-extended';
2
+ export var mockOf = mockDeep;
3
+
4
+ //# sourceMappingURL=mock-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/mocking/mock-of.ts"],"sourcesContent":["import { type DeepMockProxy, mockDeep } from 'vitest-mock-extended';\n\nexport type MockPort = <T>() => DeepMockProxy<T>;\n\nexport const mockOf: MockPort = mockDeep;\n"],"names":["mockDeep","mockOf"],"mappings":"AAAA,SAA6BA,QAAQ,QAAQ,uBAAuB;AAIpE,OAAO,IAAMC,SAAmBD,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": "3.0.0",
4
+ "version": "3.1.0",
5
5
  "exports": {
6
6
  ".": {
7
7
  "require": "./dist/index.cjs",
@@ -13,21 +13,30 @@
13
13
  ],
14
14
  "type": "module",
15
15
  "scripts": {
16
- "build": "ts-compile",
17
- "lint": "code-standards",
16
+ "build": "ts-build",
17
+ "lint": "ts-check",
18
+ "lint:fix": "ts-fix",
18
19
  "test": "# No tests"
19
20
  },
20
21
  "devDependencies": {
21
- "@jterrazz/quality": "^2.2.0",
22
- "@jterrazz/typescript": "^2.2.0"
22
+ "@jterrazz/quality": "^5.0.1",
23
+ "@jterrazz/typescript": "^3.1.0",
24
+ "@types/node": "^24.10.1"
23
25
  },
24
26
  "dependencies": {
25
27
  "@types/mockdate": "^2.0.0",
26
28
  "mockdate": "^3.0.5",
27
- "msw": "^2.7.5",
28
- "vitest": "^3.1.2",
29
29
  "vitest-mock-extended": "^3.1.0"
30
30
  },
31
+ "peerDependencies": {
32
+ "msw": "^2.12.0",
33
+ "vitest": "^4.0.0"
34
+ },
35
+ "peerDependenciesMeta": {
36
+ "msw": {
37
+ "optional": true
38
+ }
39
+ },
31
40
  "publishConfig": {
32
41
  "registry": "https://registry.npmjs.org/"
33
42
  }
@@ -1,2 +0,0 @@
1
- import * as msw from 'msw';
2
- export default msw;
package/dist/msw/main.js DELETED
@@ -1,4 +0,0 @@
1
- import * as msw from 'msw';
2
- export default msw;
3
-
4
- //# sourceMappingURL=main.js.map
@@ -1 +0,0 @@
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"}
@@ -1,9 +0,0 @@
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';
@@ -1,9 +0,0 @@
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
@@ -1 +0,0 @@
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"}