@jaypie/testkit 1.0.28 → 1.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/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Finlayson Studio, LLC
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
@@ -25,6 +25,23 @@ The testkit provides a complete mock for Jaypie including:
25
25
  vi.mock("jaypie", async () => vi.importActual("@jaypie/testkit/mock"));
26
26
  ```
27
27
 
28
+ #### Error Spying
29
+
30
+ ```javascript
31
+ import { ConfigurationError } from "@jaypie/core";
32
+
33
+ vi.mock("jaypie", async () => vi.importActual("@jaypie/testkit/mock"));
34
+
35
+ test("ConfigurationError", () => {
36
+ try {
37
+ throw new ConfigurationError("Sorpresa!");
38
+ } catch (error) {
39
+ expect(error).toBeJaypieError();
40
+ expect(ConfigurationError).toHaveBeenCalled();
41
+ }
42
+ });
43
+ ```
44
+
28
45
  #### Log Spying
29
46
 
30
47
  ```javascript
@@ -333,6 +350,7 @@ const event = sqsTestRecords(
333
350
 
334
351
  | Date | Version | Summary |
335
352
  | ---------- | ------- | -------------- |
353
+ | 9/15/2024 | 1.0.29 | All errors exported as mocks |
336
354
  | 9/14/2024 | 1.0.28 | Matchers `toThrowBadGatewayError`, `toThrowGatewayTimeoutError`, `toThrowUnavailableError` |
337
355
  | 9/13/2024 | 1.0.27 | Matcher `toBeCalledAboveTrace` |
338
356
  | 7/16/2024 | 1.0.21 | Export Jaypie mock as default |
@@ -343,4 +361,4 @@ const event = sqsTestRecords(
343
361
 
344
362
  ## 📜 License
345
363
 
346
- Published by Finlayson Studio. All rights reserved
364
+ [MIT License](./LICENSE.txt). Published by Finlayson Studio
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@jaypie/testkit",
3
- "version": "1.0.28",
3
+ "version": "1.1.0",
4
+ "license": "MIT",
4
5
  "author": "Finlayson Studio",
5
6
  "type": "module",
6
7
  "exports": {
@@ -12,17 +13,8 @@
12
13
  "format": "npm run format:package && npm run format:lint",
13
14
  "format:lint": "eslint --fix .",
14
15
  "format:package": "sort-package-json ./package.json",
15
- "init:commander": "hygen jaypie commander-init",
16
- "init:deploy": "hygen jaypie workflow-npm",
17
16
  "lint": "eslint .",
18
- "new": "hygen jaypie vite",
19
- "new:command": "hygen jaypie command",
20
- "new:constants": "hygen jaypie constants",
21
- "new:hygen": "hygen jaypie hygen",
22
- "new:index": "hygen jaypie index",
23
- "new:model": "hygen jaypie model",
24
- "new:test": "hygen jaypie vitest",
25
- "test": "vitest",
17
+ "test": "vitest run .",
26
18
  "test:spec:constants": "vitest run ./src/__tests__/constants.spec.js",
27
19
  "test:spec:expressHandler.mock": "vitest run ./src/__tests__/expressHandler-supertest.mock.spec.js",
28
20
  "test:spec:index": "vitest run ./src/__tests__/index.spec.js",
@@ -39,21 +31,17 @@
39
31
  "test:spec:toThrowJaypieError.matcher": "vitest run ./src/matchers/__tests__/toThrowJaypieError.matcher.spec.js"
40
32
  },
41
33
  "dependencies": {
42
- "@jaypie/core": "^1.0.33",
34
+ "@jaypie/core": "^1.1.0",
43
35
  "jaypie": "^1.0.44",
44
36
  "jest-json-schema": "^6.1.0",
45
37
  "lodash.isequal": "^4.5.0",
46
38
  "uuid": "^9.0.1"
47
39
  },
48
40
  "devDependencies": {
49
- "eslint": "^8.57.0",
50
- "eslint-config-jaypie": "^1.0.7",
51
- "express": "^4.19.2",
52
- "hygen": "^6.2.11",
53
- "jest-extended": "^4.0.2",
54
- "prettier": "^3.2.5",
55
- "sort-package-json": "^2.8.0",
56
- "supertest": "^7.0.0",
57
- "vitest": "^1.4.0"
58
- }
41
+ "express": "^4.21.1"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "gitHead": "26b6847fa8b061594bd899c2e098822dad198e51"
59
47
  }
@@ -1,12 +1,31 @@
1
1
  import { getMessages as originalGetMessages } from "@jaypie/aws";
2
2
  import { force, uuid as originalUuid } from "@jaypie/core";
3
3
  import {
4
- BadRequestError,
4
+ // Core utilities
5
5
  HTTP,
6
6
  JAYPIE,
7
7
  log,
8
- UnavailableError,
9
- UnhandledError,
8
+ // Errors
9
+ BadGatewayError as BadGatewayErrorOriginal,
10
+ BadRequestError as BadRequestErrorOriginal,
11
+ ConfigurationError as ConfigurationErrorOriginal,
12
+ ForbiddenError as ForbiddenErrorOriginal,
13
+ GatewayTimeoutError as GatewayTimeoutErrorOriginal,
14
+ GoneError as GoneErrorOriginal,
15
+ IllogicalError as IllogicalErrorOriginal,
16
+ InternalError as InternalErrorOriginal,
17
+ MethodNotAllowedError as MethodNotAllowedErrorOriginal,
18
+ MultiError as MultiErrorOriginal,
19
+ NotFoundError as NotFoundErrorOriginal,
20
+ NotImplementedError as NotImplementedErrorOriginal,
21
+ ProjectError as ProjectErrorOriginal,
22
+ ProjectMultiError as ProjectMultiErrorOriginal,
23
+ RejectedError as RejectedErrorOriginal,
24
+ TeapotError as TeapotErrorOriginal,
25
+ UnauthorizedError as UnauthorizedErrorOriginal,
26
+ UnavailableError as UnavailableErrorOriginal,
27
+ UnhandledError as UnhandledErrorOriginal,
28
+ UnreachableCodeError as UnreachableCodeErrorOriginal,
10
29
  } from "@jaypie/core";
11
30
  import { beforeAll, vi } from "vitest";
12
31
 
@@ -64,6 +83,69 @@ export const sendMessage = vi.fn(() => {
64
83
  return { value: `_MOCK_MESSAGE_[${TAG}]` };
65
84
  });
66
85
 
86
+ // @jaypie/core Errors
87
+
88
+ export const BadGatewayError = vi.fn((...params) => {
89
+ return BadGatewayErrorOriginal(...params);
90
+ });
91
+ export const BadRequestError = vi.fn((...params) => {
92
+ return BadRequestErrorOriginal(...params);
93
+ });
94
+ export const ConfigurationError = vi.fn((...params) => {
95
+ return ConfigurationErrorOriginal(...params);
96
+ });
97
+ export const ForbiddenError = vi.fn((...params) => {
98
+ return ForbiddenErrorOriginal(...params);
99
+ });
100
+ export const GatewayTimeoutError = vi.fn((...params) => {
101
+ return GatewayTimeoutErrorOriginal(...params);
102
+ });
103
+ export const GoneError = vi.fn((...params) => {
104
+ return GoneErrorOriginal(...params);
105
+ });
106
+ export const IllogicalError = vi.fn((...params) => {
107
+ return IllogicalErrorOriginal(...params);
108
+ });
109
+ export const InternalError = vi.fn((...params) => {
110
+ return InternalErrorOriginal(...params);
111
+ });
112
+ export const MethodNotAllowedError = vi.fn((...params) => {
113
+ return MethodNotAllowedErrorOriginal(...params);
114
+ });
115
+ export const MultiError = vi.fn((...params) => {
116
+ return MultiErrorOriginal(...params);
117
+ });
118
+ export const NotFoundError = vi.fn((...params) => {
119
+ return NotFoundErrorOriginal(...params);
120
+ });
121
+ export const NotImplementedError = vi.fn((...params) => {
122
+ return NotImplementedErrorOriginal(...params);
123
+ });
124
+ export const ProjectError = vi.fn((...params) => {
125
+ return ProjectErrorOriginal(...params);
126
+ });
127
+ export const ProjectMultiError = vi.fn((...params) => {
128
+ return ProjectMultiErrorOriginal(...params);
129
+ });
130
+ export const RejectedError = vi.fn((...params) => {
131
+ return RejectedErrorOriginal(...params);
132
+ });
133
+ export const TeapotError = vi.fn((...params) => {
134
+ return TeapotErrorOriginal(...params);
135
+ });
136
+ export const UnauthorizedError = vi.fn((...params) => {
137
+ return UnauthorizedErrorOriginal(...params);
138
+ });
139
+ export const UnavailableError = vi.fn((...params) => {
140
+ return UnavailableErrorOriginal(...params);
141
+ });
142
+ export const UnhandledError = vi.fn((...params) => {
143
+ return UnhandledErrorOriginal(...params);
144
+ });
145
+ export const UnreachableCodeError = vi.fn((...params) => {
146
+ return UnreachableCodeErrorOriginal(...params);
147
+ });
148
+
67
149
  // @jaypie/core Functions
68
150
 
69
151
  export const envBoolean = vi.fn(() => {
@@ -181,7 +263,6 @@ export const expressHandler = vi.fn((handler, props = {}) => {
181
263
  for (let i = 0; i < keys.length; i += 1) {
182
264
  const key = keys[i];
183
265
  if (typeof props.locals[key] === "function") {
184
- // eslint-disable-next-line no-await-in-loop
185
266
  localsReq.locals[key] = await props.locals[key](
186
267
  localsReq,
187
268
  localsRes,
@@ -240,6 +321,7 @@ export const expressHandler = vi.fn((handler, props = {}) => {
240
321
  } else if (typeof response === "string") {
241
322
  try {
242
323
  res.status(status).json(JSON.parse(response));
324
+ // eslint-disable-next-line no-unused-vars
243
325
  } catch (error) {
244
326
  if (supertestMode) {
245
327
  res.status(status).send(response);
@@ -263,6 +345,12 @@ export const expressHandler = vi.fn((handler, props = {}) => {
263
345
 
264
346
  // For testing, this is the same as the jaypieHandler
265
347
  export const lambdaHandler = vi.fn((handler, props = {}) => {
348
+ // If handler is an object and options is a function, swap them
349
+ if (typeof handler === "object" && typeof props === "function") {
350
+ const temp = handler;
351
+ handler = props;
352
+ props = temp;
353
+ }
266
354
  return async (event, context, ...extra) => {
267
355
  return jaypieHandler(handler, props)(event, context, ...extra);
268
356
  };
@@ -1,13 +1,3 @@
1
- //
2
- //
3
- // Constants
4
- //
5
-
6
- //
7
- //
8
- // Helper Functions
9
- //
10
-
11
1
  //
12
2
  //
13
3
  // Main
@@ -29,6 +19,7 @@ const calledAboveTrace = (log) => {
29
19
  pass: true,
30
20
  };
31
21
  }
22
+ // eslint-disable-next-line no-unused-vars
32
23
  } catch (error) {
33
24
  throw Error(`[calledAboveTrace] log is not a mock object`);
34
25
  }
@@ -1,13 +1,3 @@
1
- //
2
- //
3
- // Constants
4
- //
5
-
6
- //
7
- //
8
- // Helper Functions
9
- //
10
-
11
1
  //
12
2
  //
13
3
  // Main
@@ -17,10 +7,10 @@ const toBeClass = (received) => {
17
7
  let pass = false;
18
8
  if (typeof received === "function") {
19
9
  try {
20
- // eslint-disable-next-line new-cap, no-new
21
10
  new received();
22
11
  pass = true;
23
- } catch (e) {
12
+ // eslint-disable-next-line no-unused-vars
13
+ } catch (error) {
24
14
  pass = false;
25
15
  }
26
16
  }
@@ -1,15 +1,5 @@
1
1
  import { v4 as uuid } from "uuid";
2
2
 
3
- //
4
- //
5
- // Constants
6
- //
7
-
8
- //
9
- //
10
- // Helper Functions
11
- //
12
-
13
3
  //
14
4
  //
15
5
  // Main
@@ -20,7 +10,6 @@ const sqsTestRecords = (...args) => {
20
10
 
21
11
  // See if only a single array was passed in and spread it
22
12
  if (args.length === 1 && Array.isArray(args[0])) {
23
- // eslint-disable-next-line no-param-reassign
24
13
  [args] = args;
25
14
  }
26
15