@vertz/testing 0.2.0 → 0.2.1
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/dist/index.js +8 -10
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -12,14 +12,12 @@ import {
|
|
|
12
12
|
BadRequestException
|
|
13
13
|
} from "@vertz/server";
|
|
14
14
|
function validateSchema(schema, value, label) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (error instanceof BadRequestException)
|
|
19
|
-
throw error;
|
|
20
|
-
const message = error instanceof Error ? error.message : `Invalid ${label}`;
|
|
15
|
+
const result = schema.parse(value);
|
|
16
|
+
if (!result.ok) {
|
|
17
|
+
const message = result.error instanceof Error ? result.error.message : `Invalid ${label}`;
|
|
21
18
|
throw new BadRequestException(message);
|
|
22
19
|
}
|
|
20
|
+
return result.data;
|
|
23
21
|
}
|
|
24
22
|
var HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"];
|
|
25
23
|
function createTestApp() {
|
|
@@ -36,7 +34,7 @@ function createTestApp() {
|
|
|
36
34
|
let parsedOptions = {};
|
|
37
35
|
if (service.options && options) {
|
|
38
36
|
const parsed = service.options.safeParse(options);
|
|
39
|
-
if (parsed.
|
|
37
|
+
if (parsed.ok) {
|
|
40
38
|
parsedOptions = parsed.data;
|
|
41
39
|
} else {
|
|
42
40
|
throw new Error(`Invalid options for service ${service.moduleName}: ${parsed.error.issues.map((i) => i.message).join(", ")}`);
|
|
@@ -121,7 +119,7 @@ function createTestApp() {
|
|
|
121
119
|
const result = await entry.handler(ctx);
|
|
122
120
|
if (entry.responseSchema) {
|
|
123
121
|
const validation = entry.responseSchema.safeParse(result);
|
|
124
|
-
if (!validation.
|
|
122
|
+
if (!validation.ok) {
|
|
125
123
|
throw new ResponseValidationError(validation.error?.message ?? "Unknown validation error");
|
|
126
124
|
}
|
|
127
125
|
}
|
|
@@ -226,7 +224,7 @@ function createTestService(serviceDef) {
|
|
|
226
224
|
let options = {};
|
|
227
225
|
if (serviceDef.options) {
|
|
228
226
|
const parsed = serviceDef.options.safeParse(providedOptions);
|
|
229
|
-
if (parsed.
|
|
227
|
+
if (parsed.ok) {
|
|
230
228
|
options = parsed.data;
|
|
231
229
|
} else {
|
|
232
230
|
throw new Error(`Invalid options: ${parsed.error.issues.map((i) => i.message).join(", ")}`);
|
|
@@ -235,7 +233,7 @@ function createTestService(serviceDef) {
|
|
|
235
233
|
let env = {};
|
|
236
234
|
if (serviceDef.env) {
|
|
237
235
|
const parsed = serviceDef.env.safeParse(providedEnv);
|
|
238
|
-
if (parsed.
|
|
236
|
+
if (parsed.ok) {
|
|
239
237
|
env = parsed.data;
|
|
240
238
|
} else {
|
|
241
239
|
throw new Error(`Invalid env: ${parsed.error.issues.map((i) => i.message).join(", ")}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vertz/testing",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Testing utilities for Vertz applications",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"typecheck": "tsc --noEmit"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@vertz/core": "
|
|
35
|
-
"@vertz/server": "
|
|
34
|
+
"@vertz/core": "0.2.1",
|
|
35
|
+
"@vertz/server": "0.2.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@types/node": "^25.
|
|
39
|
-
"@vertz/schema": "
|
|
38
|
+
"@types/node": "^25.3.1",
|
|
39
|
+
"@vertz/schema": "0.2.1",
|
|
40
40
|
"@vitest/coverage-v8": "^4.0.18",
|
|
41
41
|
"bunup": "latest",
|
|
42
42
|
"typescript": "^5.7.0",
|