Skip to content

Commit

Permalink
fix: test not passing in Windows env
Browse files Browse the repository at this point in the history
  • Loading branch information
tvillaren committed Feb 19, 2024
1 parent f94702a commit 350412f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
29 changes: 15 additions & 14 deletions src/core/validateGeneratedTypes.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { sep } from "path";
import { validateGeneratedTypes } from "./validateGeneratedTypes";

describe("validateGeneratedTypes", () => {
Expand Down Expand Up @@ -408,13 +409,13 @@ describe("validateGeneratedTypes", () => {
const extraFiles = [
{
sourceText: `export type Hero = { name: string; }`,
relativePath: "./hero-module.ts",
relativePath: "hero-module.ts",
},
{
sourceText: `
import { z } from "zod";
export const heroSchema = z.object({ name: z.string() })`,
relativePath: "./zHero.ts",
relativePath: "zHero.ts",
},
];

Expand Down Expand Up @@ -452,7 +453,7 @@ describe("validateGeneratedTypes", () => {
it("should return no error if we reference a zod import in a subdirectory", () => {
const sourceTypes = {
sourceText: `
import { Hero } from "./zod/hero-module.ts"
import { Hero } from ".${sep}zod${sep}hero-module.ts"
export interface Citizen {
hero: Hero
Expand All @@ -464,7 +465,7 @@ describe("validateGeneratedTypes", () => {
const zodSchemas = {
sourceText: `// Generated by ts-to-zod
import { z } from "zod";
import { heroSchema } from "./zod/zHero.ts"
import { heroSchema } from ".${sep}zod${sep}zHero.ts"
export const citizenSchema = z.object({
hero: heroSchema
Expand All @@ -476,13 +477,13 @@ describe("validateGeneratedTypes", () => {
const extraFiles = [
{
sourceText: `export type Hero = { name: string; }`,
relativePath: "./zod/hero-module.ts",
relativePath: `.${sep}zod${sep}hero-module.ts`,
},
{
sourceText: `
import { z } from "zod";
export const heroSchema = z.object({ name: z.string() })`,
relativePath: "./zod/zHero.ts",
relativePath: `.${sep}zod${sep}zHero.ts`,
},
];

Expand Down Expand Up @@ -520,7 +521,7 @@ describe("validateGeneratedTypes", () => {
it("should return no error if we reference a zod import in a parent directory", () => {
const sourceTypes = {
sourceText: `
import { Hero } from "../hero-module.ts"
import { Hero } from "..${sep}hero-module.ts"
export interface Citizen {
hero: Hero
Expand All @@ -532,7 +533,7 @@ describe("validateGeneratedTypes", () => {
const zodSchemas = {
sourceText: `// Generated by ts-to-zod
import { z } from "zod";
import { heroSchema } from "../zHero.ts"
import { heroSchema } from "..${sep}zHero.ts"
export const citizenSchema = z.object({
hero: heroSchema
Expand All @@ -544,13 +545,13 @@ describe("validateGeneratedTypes", () => {
const extraFiles = [
{
sourceText: `export type Hero = { name: string; }`,
relativePath: "../hero-module.ts",
relativePath: `..${sep}hero-module.ts`,
},
{
sourceText: `
import { z } from "zod";
export const heroSchema = z.object({ name: z.string() })`,
relativePath: "../zHero.ts",
relativePath: `..${sep}zHero.ts`,
},
];

Expand Down Expand Up @@ -588,7 +589,7 @@ describe("validateGeneratedTypes", () => {
it("should return no error if we reference a zod import in an exotic path", () => {
const sourceTypes = {
sourceText: `
import { Hero } from "./hero-module.ts"
import { Hero } from "hero-module.ts"
export interface Citizen {
hero: Hero
Expand All @@ -600,7 +601,7 @@ describe("validateGeneratedTypes", () => {
const zodSchemas = {
sourceText: `// Generated by ts-to-zod
import { z } from "zod";
import { heroSchema } from "../../zod/zHero.ts"
import { heroSchema } from "..${sep}..${sep}zod${sep}zHero.ts"
export const citizenSchema = z.object({
hero: heroSchema
Expand All @@ -612,13 +613,13 @@ describe("validateGeneratedTypes", () => {
const extraFiles = [
{
sourceText: `export type Hero = { name: string; }`,
relativePath: "./hero-module.ts",
relativePath: "hero-module.ts",
},
{
sourceText: `
import { z } from "zod";
export const heroSchema = z.object({ name: z.string() })`,
relativePath: "../../zod/zHero.ts",
relativePath: `..${sep}..${sep}zod${sep}zHero.ts`,
},
];

Expand Down
15 changes: 10 additions & 5 deletions src/utils/countNetParentDirectoriesInRelativePath.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { sep } from "path";
import { countNetParentDirectoriesInRelativePath } from "./countNetParentDirectoriesInRelativePath";

describe("countNetUpFoldersInRelativePath", () => {
Expand All @@ -6,35 +7,39 @@ describe("countNetUpFoldersInRelativePath", () => {
});

it("should return 0 for a path with no parent directory", () => {
expect(countNetParentDirectoriesInRelativePath("folder/file.txt")).toBe(0);
expect(
countNetParentDirectoriesInRelativePath(`folder${sep}file.txt`)
).toBe(0);
});

it("should return 1 for a path with one parent directory", () => {
expect(
countNetParentDirectoriesInRelativePath("../folder1/folder2/file.txt")
countNetParentDirectoriesInRelativePath(
`..${sep}folder1${sep}folder2${sep}file.txt`
)
).toBe(1);
});

it("should return 2 for a path with two parent directories", () => {
expect(
countNetParentDirectoriesInRelativePath(
"../../folder1/folder2/folder3/file.txt"
`..${sep}..${sep}folder1${sep}folder2${sep}folder3${sep}file.txt`
)
).toBe(2);
});

it("should return 2 for a path with two parent directories not at the beginining", () => {
expect(
countNetParentDirectoriesInRelativePath(
"../folder1/../../folder2/folder3/file.txt"
`..${sep}folder1${sep}..${sep}..${sep}folder2${sep}folder3${sep}file.txt`
)
).toBe(2);
});

it("should return 3 for a path with 3 parent directories not at the beginining with more folders in between", () => {
expect(
countNetParentDirectoriesInRelativePath(
"../folder1/folder2/../../../..//folder3/file.txt"
`..${sep}folder1${sep}folder2${sep}..${sep}..${sep}..${sep}..${sep}${sep}folder3${sep}file.txt`
)
).toBe(3);
});
Expand Down

0 comments on commit 350412f

Please sign in to comment.