Skip to content

Commit

Permalink
backport to typescript 4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
sorgloomer committed May 6, 2023
1 parent f8911ff commit b7bfb2d
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 37 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: ["14", "20"]
typescript: ["5.0", "4.9"]
node: ["20", "14"]
typescript: ["5.0", "4.3"]
name: TS ${{ matrix.typescript }} Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v2
Expand All @@ -23,6 +23,6 @@ jobs:
node-version: ${{ matrix.node }}
- run: npm install
- run: npm run compile
- run: npm install typescript@${{ matrix.typescript }}
- run: npm install --no-save typescript@${{ matrix.typescript }}
- run: npm run typecheck
- run: npm run test
14 changes: 8 additions & 6 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { JestConfigWithTsJest, pathsToModuleNameMapper } from "ts-jest";
import { JestConfigWithTsJest } from "ts-jest";

import { compilerOptions } from "./tsconfig.json";

export default {
const config: JestConfigWithTsJest = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: [
'<rootDir>/src/**/*.test.ts',
],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
} satisfies JestConfigWithTsJest;
moduleNameMapper: {
"^tsconfig\\.json$": "<rootDir>/$0",
"^(?:src|test)(?:/.*)?$": "<rootDir>/$0",
},
};
export default config;
22 changes: 19 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
},
"main": "lib",
"devDependencies": {
"compare-versions": "^6.0.0-rc.1",
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4",
"typescript": "5.0",
"zod": "^3.21.4"
},
"files": [
Expand Down
23 changes: 14 additions & 9 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { describe, expect, it } from "@jest/globals";
import { lazyCompileTsFile } from "@test/helpers/test-helpers";
import * as typescript from "typescript";
import * as versions from "compare-versions";
import { lazyCompileTsFile } from "test/helpers/test-helpers";

const itIf = (condition: boolean) => condition ? it : it.skip;

describe("ZodSafe", () => {

// language=typescript
const setup = `
import * as z from 'zod';
import { Exactly, ZodSafe } from "@src/index";
import { Exactly, ZodSafe } from "src/index";
enum TransferType {
deposit = "deposit",
withdraw = "withdraw",
Expand Down Expand Up @@ -35,11 +39,13 @@ describe("ZodSafe", () => {
expect(errors).toHaveLength(0);
});

it("is more expressive than the 'satisfies' operator", () => {
itIf(
versions.satisfies(typescript.version, ">=4.9")
)("is more expressive than the 'satisfies' operator", () => {
// language=typescript
const setup = `
import * as z from 'zod';
import { Exactly, ZodSafe } from "@src/index";
import { Exactly, ZodSafe } from "src/index";
interface Contact {
name: string;
}
Expand Down Expand Up @@ -69,7 +75,7 @@ describe("ZodSafe", () => {
// language=typescript
const errors = lazyCompileTsFile(`
import * as z from 'zod';
import { Exactly, ZodSafe } from "@src/index";
import { Exactly, ZodSafe } from "src/index";
ZodSafe(z.literal("FOO")).input<Exactly<"FOO">>();
`)();
Expand All @@ -79,7 +85,7 @@ describe("ZodSafe", () => {
// language=typescript
const errors = lazyCompileTsFile(`
import * as z from 'zod';
import { Exactly, ZodSafe } from "@src/index";
import { Exactly, ZodSafe } from "src/index";
ZodSafe(z.string()).input<Exactly<string>>();
`)();
Expand All @@ -90,7 +96,7 @@ describe("ZodSafe", () => {
// language=typescript
const errors = lazyCompileTsFile(`
import * as z from 'zod';
import { Exactly, ZodSafe } from "@src/index";
import { Exactly, ZodSafe } from "src/index";
ZodSafe(z.string()).input<Exactly<"FOO">>();
`)();
Expand All @@ -102,12 +108,11 @@ describe("ZodSafe", () => {
// language=typescript
const errors = lazyCompileTsFile(`
import * as z from 'zod';
import { Exactly, ZodSafe } from "@src/index";
import { Exactly, ZodSafe } from "src/index";
ZodSafe(z.literal("FOO")).input<Exactly<string>>();
`)();
expect(errors).toHaveLength(1);
expect(errors[0]).toContain(`Type 'string' is not assignable to type '"FOO"'.`);
});
});

2 changes: 1 addition & 1 deletion test/helpers/test-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@jest/globals';
import * as projectTsConfig from '@package/tsconfig.json';
import * as projectTsConfig from 'tsconfig.json';
import * as ts from 'typescript';

import { lazy, Producer } from './lazy';
Expand Down
15 changes: 1 addition & 14 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,7 @@
"types": [
"node"
],
"paths": {
"@src": [
"./src"
],
"@src/*": [
"./src/*"
],
"@test/*": [
"./test/*"
],
"@package/*": [
"./*"
]
},
"baseUrl": ".",
"experimentalDecorators": true
},
"moduleResolution": "node"
Expand Down

0 comments on commit b7bfb2d

Please sign in to comment.