Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: drop SWC; use TS for cjs/esm bundles #8

Merged
merged 2 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tall-fireants-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'zod-validation-error': patch
---

Drop SWC; Fix ESM export
7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

# env:
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

jobs:
block-autosquash:
if: github.event.pull_request.draft == false
Expand All @@ -24,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
node-version: [16.x]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -56,7 +53,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
node-version: [16.x]

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
# This makes action fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Use Node.js 14.x
- name: Use Node.js 16.x
uses: actions/setup-node@v1
with:
version: 14.x
version: 16.x

- name: Install Dependencies
run: yarn
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v14.17
v16
29 changes: 0 additions & 29 deletions config/browser-esm.json

This file was deleted.

19 changes: 0 additions & 19 deletions config/jest.config.ts

This file was deleted.

31 changes: 0 additions & 31 deletions config/node-cjs.json

This file was deleted.

31 changes: 0 additions & 31 deletions config/node-esm.json

This file was deleted.

5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
jmike marked this conversation as resolved.
Show resolved Hide resolved
preset: 'ts-jest',
collectCoverageFrom: ['lib/**/*.{js,ts}'],
testRegex: './lib/.*\\.(test|spec)\\.(js|ts)$',
};
105 changes: 59 additions & 46 deletions lib/ValidationError.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as zod from 'zod';
import { ZodError } from 'zod';

import {
fromZodError,
Expand All @@ -13,21 +14,23 @@ describe('fromZodError()', () => {
try {
emailSchema.parse('foobar');
} catch (err) {
const validationError = fromZodError(err);
expect(validationError).toBeInstanceOf(ValidationError);
expect(validationError.message).toMatchInlineSnapshot(
`"Validation error: Invalid email"`
);
expect(validationError.details).toMatchInlineSnapshot(`
Array [
Object {
if (err instanceof ZodError) {
const validationError = fromZodError(err);
expect(validationError).toBeInstanceOf(ValidationError);
expect(validationError.message).toMatchInlineSnapshot(
`"Validation error: Invalid email"`
);
expect(validationError.details).toMatchInlineSnapshot(`
[
{
"code": "invalid_string",
"message": "Invalid email",
"path": Array [],
"path": [],
"validation": "email",
},
]
`);
}
}
});

Expand All @@ -43,35 +46,39 @@ describe('fromZodError()', () => {
name: 'a',
});
} catch (err) {
const validationError = fromZodError(err);
expect(validationError).toBeInstanceOf(ValidationError);
expect(validationError.message).toMatchInlineSnapshot(
`"Validation error: Number must be greater than 0 at \\"id\\"; String must contain at least 2 character(s) at \\"name\\""`
);
expect(validationError.details).toMatchInlineSnapshot(`
Array [
Object {
if (err instanceof ZodError) {
const validationError = fromZodError(err);
expect(validationError).toBeInstanceOf(ValidationError);
expect(validationError.message).toMatchInlineSnapshot(
`"Validation error: Number must be greater than 0 at "id"; String must contain at least 2 character(s) at "name""`
);
expect(validationError.details).toMatchInlineSnapshot(`
[
{
"code": "too_small",
"exact": false,
"inclusive": false,
"message": "Number must be greater than 0",
"minimum": 0,
"path": Array [
"path": [
"id",
],
"type": "number",
},
Object {
{
"code": "too_small",
"exact": false,
"inclusive": true,
"message": "String must contain at least 2 character(s)",
"minimum": 2,
"path": Array [
"path": [
"name",
],
"type": "string",
},
]
`);
}
}
});

Expand All @@ -81,42 +88,44 @@ describe('fromZodError()', () => {
try {
objSchema.parse([1, 'a', true, 1.23]);
} catch (err) {
const validationError = fromZodError(err);
expect(validationError).toBeInstanceOf(ValidationError);
expect(validationError.message).toMatchInlineSnapshot(
`"Validation error: Expected number, received string at \\"[1]\\"; Expected number, received boolean at \\"[2]\\"; Expected integer, received float at \\"[3]\\""`
);
expect(validationError.details).toMatchInlineSnapshot(`
Array [
Object {
if (err instanceof ZodError) {
const validationError = fromZodError(err);
expect(validationError).toBeInstanceOf(ValidationError);
expect(validationError.message).toMatchInlineSnapshot(
`"Validation error: Expected number, received string at "[1]"; Expected number, received boolean at "[2]"; Expected integer, received float at "[3]""`
);
expect(validationError.details).toMatchInlineSnapshot(`
[
{
"code": "invalid_type",
"expected": "number",
"message": "Expected number, received string",
"path": Array [
"path": [
1,
],
"received": "string",
},
Object {
{
"code": "invalid_type",
"expected": "number",
"message": "Expected number, received boolean",
"path": Array [
"path": [
2,
],
"received": "boolean",
},
Object {
{
"code": "invalid_type",
"expected": "integer",
"message": "Expected integer, received float",
"path": Array [
"path": [
3,
],
"received": "float",
},
]
`);
}
}
});

Expand All @@ -138,46 +147,50 @@ describe('fromZodError()', () => {
},
});
} catch (err) {
const validationError = fromZodError(err);
expect(validationError).toBeInstanceOf(ValidationError);
expect(validationError.message).toMatchInlineSnapshot(
`"Validation error: Number must be greater than 0 at \\"id\\"; Expected number, received string at \\"arr[1]\\"; String must contain at least 2 character(s) at \\"nestedObj.name\\""`
);
expect(validationError.details).toMatchInlineSnapshot(`
Array [
Object {
if (err instanceof ZodError) {
const validationError = fromZodError(err);
expect(validationError).toBeInstanceOf(ValidationError);
expect(validationError.message).toMatchInlineSnapshot(
`"Validation error: Number must be greater than 0 at "id"; Expected number, received string at "arr[1]"; String must contain at least 2 character(s) at "nestedObj.name""`
);
expect(validationError.details).toMatchInlineSnapshot(`
[
{
"code": "too_small",
"exact": false,
"inclusive": false,
"message": "Number must be greater than 0",
"minimum": 0,
"path": Array [
"path": [
"id",
],
"type": "number",
},
Object {
{
"code": "invalid_type",
"expected": "number",
"message": "Expected number, received string",
"path": Array [
"path": [
"arr",
1,
],
"received": "string",
},
Object {
{
"code": "too_small",
"exact": false,
"inclusive": true,
"message": "String must contain at least 2 character(s)",
"minimum": 2,
"path": Array [
"path": [
"nestedObj",
"name",
],
"type": "string",
},
]
`);
}
}
});
});
Expand Down
Loading