Skip to content

Commit

Permalink
test: adding one more test to cover import without extension
Browse files Browse the repository at this point in the history
  • Loading branch information
tvillaren committed Feb 19, 2024
1 parent 88273a0 commit 7edc41e
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/core/validateGeneratedTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,74 @@ describe("validateGeneratedTypes", () => {
expect(errors).toEqual([]);
});

it("should return no error if we reference a zod import without its extension", () => {
const sourceTypes = {
sourceText: `
import { Hero } from "./hero-module"
export interface Citizen {
hero: Hero
};
`,
relativePath: "source.ts",
};

const zodSchemas = {
sourceText: `// Generated by ts-to-zod
import { z } from "zod";
import { heroSchema } from "./zHero"
export const citizenSchema = z.object({
hero: heroSchema
});
`,
relativePath: "source.zod.ts",
};

const extraFiles = [
{
sourceText: `export type Hero = { name: string; }`,
relativePath: "hero-module.ts",
},
{
sourceText: `
import { z } from "zod";
export const heroSchema = z.object({ name: z.string() })`,
relativePath: "zHero.ts",
},
];

const integrationTests = {
sourceText: `// Generated by ts-to-zod
import { z } from "zod";
import * as spec from "./${sourceTypes.relativePath.slice(0, -3)}";
import * as generated from "./${zodSchemas.relativePath.slice(0, -3)}";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function expectType<T>(_: T) {
/* noop */
}
export type CitizenInferredType = z.infer<typeof generated.citizenSchema>;
expectType<CitizenInferredType>({} as spec.Citizen);
expectType<spec.Citizen>({} as CitizenInferredType);
`,
relativePath: "source.integration.ts",
};

const errors = validateGeneratedTypes({
sourceTypes,
zodSchemas,
integrationTests,
skipParseJSDoc: false,
extraFiles,
});

expect(errors).toEqual([]);
});

it("should return no error if we use a deep external import", () => {
const sourceTypes = {
sourceText: `
Expand Down

0 comments on commit 7edc41e

Please sign in to comment.