Skip to content

Commit

Permalink
Add Windows tests (back), skip DO test in macOS/Win
Browse files Browse the repository at this point in the history
  • Loading branch information
drwpow committed Aug 10, 2023
1 parent 50441d0 commit 0ae298d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 26 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,19 @@ jobs:
version: latest
- run: pnpm i
- run: pnpm test
env:
CI_ENV: macos
test-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
- uses: pnpm/action-setup@v2
with:
version: latest
- run: pnpm i
- run: pnpm test
env:
CI_ENV: windows
6 changes: 5 additions & 1 deletion packages/openapi-typescript/test/cjs.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
/* eslint-disable @typescript-eslint/no-var-requires */

// important: MUST use require()!
const fs = require("node:fs");
const openapiTS = require("../dist/index.cjs");
const yaml = require("js-yaml");

// note: this import is fine; it’s just a test helper
import { replaceLB } from "./helpers.js";

describe("CJS bundle", () => {
it("basic", async () => {
const input = yaml.load(fs.readFileSync(new URL("../examples/stripe-api.yaml", import.meta.url), "utf8"));
const output = await openapiTS(input);
expect(output).toBe(fs.readFileSync(new URL("../examples/stripe-api.ts", import.meta.url), "utf8"));
expect(output).toBe(replaceLB(fs.readFileSync(new URL("../examples/stripe-api.ts", import.meta.url), "utf8")));
});
});
28 changes: 15 additions & 13 deletions packages/openapi-typescript/test/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { execa } from "execa";
import fs from "node:fs";
import { URL } from "node:url";
import { replaceLB } from "./helpers.js";

const cwd = new URL("../", import.meta.url);
const cmd = "./bin/cli.js";
Expand All @@ -12,59 +13,60 @@ describe("CLI", () => {
test(
"GitHub API",
async () => {
const expected = fs.readFileSync(new URL("./examples/github-api.ts", cwd), "utf8").trim();
const expected = replaceLB(fs.readFileSync(new URL("./examples/github-api.ts", cwd), "utf8")).trim();
const { stdout } = await execa(cmd, ["./examples/github-api.yaml"], { cwd });
expect(stdout).toBe(expected);
},
TIMEOUT
TIMEOUT,
);
test(
"GitHub API (next)",
async () => {
const expected = fs.readFileSync(new URL("./examples/github-api-next.ts", cwd), "utf8").trim();
const expected = replaceLB(fs.readFileSync(new URL("./examples/github-api-next.ts", cwd), "utf8")).trim();
const { stdout } = await execa(cmd, ["./examples/github-api-next.yaml"], { cwd });
expect(stdout).toBe(expected);
},
TIMEOUT
TIMEOUT,
);
test(
"Octokit GHES 3.6 Diff to API",
async () => {
const expected = fs.readFileSync(new URL("./examples/octokit-ghes-3.6-diff-to-api.ts", cwd), "utf8").trim();
const expected = replaceLB(fs.readFileSync(new URL("./examples/octokit-ghes-3.6-diff-to-api.ts", cwd), "utf8")).trim();
const { stdout } = await execa(cmd, ["./examples/octokit-ghes-3.6-diff-to-api.json"], { cwd });
expect(stdout).toBe(expected);
},
TIMEOUT
TIMEOUT,
);
test(
"Stripe API",
async () => {
const expected = fs.readFileSync(new URL("./examples/stripe-api.ts", cwd), "utf8").trim();
const expected = replaceLB(fs.readFileSync(new URL("./examples/stripe-api.ts", cwd), "utf8")).trim();
const { stdout } = await execa(cmd, ["./examples/stripe-api.yaml"], { cwd });
expect(stdout).toBe(expected);
},
TIMEOUT
TIMEOUT,
);
test(
// this test runs too slowly on macos / windows in GitHub Actions
test.skipIf(process.env.CI_ENV === "macos" || process.env.CI_ENV === "windows")(
"DigitalOcean API (remote $refs)",
async () => {
const expected = fs.readFileSync(new URL("./examples/digital-ocean-api.ts", cwd), "utf8").trim();
const expected = replaceLB(fs.readFileSync(new URL("./examples/digital-ocean-api.ts", cwd), "utf8")).trim();
const { stdout } = await execa(cmd, ["./examples/digital-ocean-api/DigitalOcean-public.v2.yaml"], {
cwd,
});
expect(stdout).toBe(expected);
},
TIMEOUT
TIMEOUT,
);
test(
"stdin",
async () => {
const expected = fs.readFileSync(new URL("./examples/stripe-api.ts", cwd), "utf8").trim();
const expected = replaceLB(fs.readFileSync(new URL("./examples/stripe-api.ts", cwd), "utf8")).trim();
const input = fs.readFileSync(new URL("./examples/stripe-api.yaml", cwd));
const { stdout } = await execa(cmd, { input });
expect(stdout).toBe(expected);
},
TIMEOUT
TIMEOUT,
);
});

Expand Down
9 changes: 9 additions & 0 deletions packages/openapi-typescript/test/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const CLRF_RE = /\r\n/g;

/** Normalize all linebreaks to \n (for Windows tests) */
export function replaceLB(clrf: string): string {
if (process.env.CI_ENV === "windows") {
return clrf.replace(CLRF_RE, "\n");
}
return clrf;
}
30 changes: 18 additions & 12 deletions packages/openapi-typescript/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "node:fs";
import openapiTS from "../dist/index.js";
import type { OpenAPI3 } from "../src/types.js";
import { replaceLB } from "./helpers.js";

const BOILERPLATE = `/**
* This file was auto-generated by openapi-typescript.
Expand Down Expand Up @@ -784,7 +785,7 @@ export type operations = Record<string, never>;
},
},
},
{ exportType: false }
{ exportType: false },
);
expect(generated).toBe(`${BOILERPLATE}
export type paths = Record<string, never>;
Expand Down Expand Up @@ -826,7 +827,7 @@ export type operations = Record<string, never>;
},
},
},
{ exportType: true }
{ exportType: true },
);
expect(generated).toBe(`${BOILERPLATE}
export type paths = Record<string, never>;
Expand Down Expand Up @@ -1091,7 +1092,7 @@ export type operations = Record<string, never>;
},
},
},
{ exportType: false }
{ exportType: false },
);
expect(generated).toBe(`${BOILERPLATE}${ONE_OF_TYPE_HELPERS}
export type paths = Record<string, never>;
Expand Down Expand Up @@ -1144,7 +1145,7 @@ export type operations = Record<string, never>;
},
},
},
{ exportType: false }
{ exportType: false },
);
expect(generated).toBe(`${BOILERPLATE}${WITH_REQUIRED_TYPE_HELPERS}
export type paths = Record<string, never>;
Expand Down Expand Up @@ -1206,32 +1207,37 @@ export type operations = Record<string, never>;
describe("GitHub", () => {
test("default options", async () => {
const generated = await openapiTS(new URL("./github-api.yaml", EXAMPLES_DIR));
expect(generated).toBe(fs.readFileSync(new URL("./github-api.ts", EXAMPLES_DIR), "utf8"));
expect(generated).toBe(replaceLB(fs.readFileSync(new URL("./github-api.ts", EXAMPLES_DIR), "utf8")));
}, 30000);
});
describe("GitHub (next)", () => {
test("default options", async () => {
const generated = await openapiTS(new URL("./github-api-next.yaml", EXAMPLES_DIR));
expect(generated).toBe(fs.readFileSync(new URL("./github-api-next.ts", EXAMPLES_DIR), "utf8"));
expect(generated).toBe(replaceLB(fs.readFileSync(new URL("./github-api-next.ts", EXAMPLES_DIR), "utf8")));
}, 30000);
});
describe("Octokit GHES 3.6 Diff to API", () => {
test("default options", async () => {
const generated = await openapiTS(new URL("./octokit-ghes-3.6-diff-to-api.json", EXAMPLES_DIR));
expect(generated).toBe(fs.readFileSync(new URL("./octokit-ghes-3.6-diff-to-api.ts", EXAMPLES_DIR), "utf8"));
expect(generated).toBe(replaceLB(fs.readFileSync(new URL("./octokit-ghes-3.6-diff-to-api.ts", EXAMPLES_DIR), "utf8")));
}, 30000);
});
describe("Stripe", () => {
test("default options", async () => {
const generated = await openapiTS(new URL("./stripe-api.yaml", EXAMPLES_DIR));
expect(generated).toBe(fs.readFileSync(new URL("./stripe-api.ts", EXAMPLES_DIR), "utf8"));
expect(generated).toBe(replaceLB(fs.readFileSync(new URL("./stripe-api.ts", EXAMPLES_DIR), "utf8")));
}, 30000);
});
describe("DigitalOcean", () => {
test("default options", async () => {
const generated = await openapiTS(new URL("./digital-ocean-api/DigitalOcean-public.v2.yaml", EXAMPLES_DIR));
expect(generated).toBe(fs.readFileSync(new URL("./digital-ocean-api.ts", EXAMPLES_DIR), "utf8"));
}, 60000);
// this test runs too slowly on macos / windows in GitHub Actions
test.skipIf(process.env.CI_ENV === "macos" || process.env.CI_ENV === "windows")(
"default options",
async () => {
const generated = await openapiTS(new URL("./digital-ocean-api/DigitalOcean-public.v2.yaml", EXAMPLES_DIR));
expect(generated).toBe(replaceLB(fs.readFileSync(new URL("./digital-ocean-api.ts", EXAMPLES_DIR), "utf8")));
},
60000,
);
});
});
});

0 comments on commit 0ae298d

Please sign in to comment.