Skip to content

Commit 6899a51

Browse files
authored
Add Windows tests (back), skip DO test in macOS/Win (#1294)
1 parent a65beac commit 6899a51

File tree

11 files changed

+155
-141
lines changed

11 files changed

+155
-141
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,19 @@ jobs:
6262
version: latest
6363
- run: pnpm i
6464
- run: pnpm test
65+
env:
66+
CI_ENV: macos
67+
test-windows:
68+
runs-on: windows-latest
69+
steps:
70+
- uses: actions/checkout@v3
71+
- uses: actions/setup-node@v3
72+
with:
73+
node-version: 20
74+
- uses: pnpm/action-setup@v2
75+
with:
76+
version: latest
77+
- run: pnpm i
78+
- run: pnpm test
79+
env:
80+
CI_ENV: windows

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"devDependencies": {
2626
"@astrojs/sitemap": "^2.0.1",
27-
"@types/node": "^20.4.4",
27+
"@types/node": "^20.4.9",
2828
"html-escaper": "^3.0.3",
2929
"typescript": "^5.1.6"
3030
}

packages/openapi-fetch/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"nanostores": "^0.9.3",
6464
"openapi-typescript": "^6.4.2",
6565
"typescript": "^5.1.6",
66-
"vitest": "^0.33.0",
66+
"vitest": "^0.34.1",
6767
"vitest-fetch-mock": "^0.2.2"
6868
}
6969
}

packages/openapi-typescript/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@
7272
"degit": "^2.8.4",
7373
"del-cli": "^5.0.0",
7474
"esbuild": "^0.19.0",
75-
"execa": "^6.1.0",
75+
"execa": "^7.2.0",
7676
"vite": "^4.4.9",
77-
"vite-node": "^0.33.0",
78-
"vitest": "^0.33.0"
77+
"vite-node": "^0.34.1",
78+
"vitest": "^0.34.1"
7979
}
8080
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
22

3+
// important: MUST use require()!
34
const fs = require("node:fs");
5+
const { URL } = require("node:url");
46
const openapiTS = require("../dist/index.cjs");
57
const yaml = require("js-yaml");
68

9+
// note: this import is fine; it’s just a test helper
10+
import { readFile } from "./helpers.js";
11+
712
describe("CJS bundle", () => {
813
it("basic", async () => {
914
const input = yaml.load(fs.readFileSync(new URL("../examples/stripe-api.yaml", import.meta.url), "utf8"));
1015
const output = await openapiTS(input);
11-
expect(output).toBe(fs.readFileSync(new URL("../examples/stripe-api.ts", import.meta.url), "utf8"));
16+
expect(output).toBe(readFile(new URL("../examples/stripe-api.ts", import.meta.url)));
1217
});
1318
});

packages/openapi-typescript/test/cli.test.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { execa } from "execa";
2-
import fs from "node:fs";
3-
import { URL } from "node:url";
2+
import { URL, fileURLToPath } from "node:url";
3+
import os from "node:os";
4+
import { readFile } from "./helpers.js";
45

5-
const cwd = new URL("../", import.meta.url);
6+
const root = new URL("../", import.meta.url);
7+
const cwd = os.platform() === "win32" ? fileURLToPath(root) : root; // execa bug: fileURLToPath required on Windows
68
const cmd = "./bin/cli.js";
79
const TIMEOUT = 90000;
810

@@ -12,59 +14,60 @@ describe("CLI", () => {
1214
test(
1315
"GitHub API",
1416
async () => {
15-
const expected = fs.readFileSync(new URL("./examples/github-api.ts", cwd), "utf8").trim();
17+
const expected = readFile(new URL("./examples/github-api.ts", root)).trim();
1618
const { stdout } = await execa(cmd, ["./examples/github-api.yaml"], { cwd });
1719
expect(stdout).toBe(expected);
1820
},
19-
TIMEOUT
21+
TIMEOUT,
2022
);
2123
test(
2224
"GitHub API (next)",
2325
async () => {
24-
const expected = fs.readFileSync(new URL("./examples/github-api-next.ts", cwd), "utf8").trim();
26+
const expected = readFile(new URL("./examples/github-api-next.ts", root)).trim();
2527
const { stdout } = await execa(cmd, ["./examples/github-api-next.yaml"], { cwd });
2628
expect(stdout).toBe(expected);
2729
},
28-
TIMEOUT
30+
TIMEOUT,
2931
);
3032
test(
3133
"Octokit GHES 3.6 Diff to API",
3234
async () => {
33-
const expected = fs.readFileSync(new URL("./examples/octokit-ghes-3.6-diff-to-api.ts", cwd), "utf8").trim();
35+
const expected = readFile(new URL("./examples/octokit-ghes-3.6-diff-to-api.ts", root)).trim();
3436
const { stdout } = await execa(cmd, ["./examples/octokit-ghes-3.6-diff-to-api.json"], { cwd });
3537
expect(stdout).toBe(expected);
3638
},
37-
TIMEOUT
39+
TIMEOUT,
3840
);
3941
test(
4042
"Stripe API",
4143
async () => {
42-
const expected = fs.readFileSync(new URL("./examples/stripe-api.ts", cwd), "utf8").trim();
44+
const expected = readFile(new URL("./examples/stripe-api.ts", root)).trim();
4345
const { stdout } = await execa(cmd, ["./examples/stripe-api.yaml"], { cwd });
4446
expect(stdout).toBe(expected);
4547
},
46-
TIMEOUT
48+
TIMEOUT,
4749
);
48-
test(
50+
// this test runs too slowly on macos / windows in GitHub Actions (but not natively)
51+
test.skipIf(process.env.CI_ENV === "macos" || process.env.CI_ENV === "windows")(
4952
"DigitalOcean API (remote $refs)",
5053
async () => {
51-
const expected = fs.readFileSync(new URL("./examples/digital-ocean-api.ts", cwd), "utf8").trim();
54+
const expected = readFile(new URL("./examples/digital-ocean-api.ts", root)).trim();
5255
const { stdout } = await execa(cmd, ["./examples/digital-ocean-api/DigitalOcean-public.v2.yaml"], {
5356
cwd,
5457
});
5558
expect(stdout).toBe(expected);
5659
},
57-
TIMEOUT
60+
TIMEOUT,
5861
);
5962
test(
6063
"stdin",
6164
async () => {
62-
const expected = fs.readFileSync(new URL("./examples/stripe-api.ts", cwd), "utf8").trim();
63-
const input = fs.readFileSync(new URL("./examples/stripe-api.yaml", cwd));
65+
const expected = readFile(new URL("./examples/stripe-api.ts", root)).trim();
66+
const input = readFile(new URL("./examples/stripe-api.yaml", root));
6467
const { stdout } = await execa(cmd, { input });
6568
expect(stdout).toBe(expected);
6669
},
67-
TIMEOUT
70+
TIMEOUT,
6871
);
6972
});
7073

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import fs from "node:fs";
2+
3+
export const CLRF_RE = /\r\n/g;
4+
5+
/** Normalize all linebreaks to \n when reading files (for Windows tests) */
6+
export function readFile(filepath: fs.PathOrFileDescriptor): string {
7+
const contents = fs.readFileSync(filepath, "utf8"); // Windows hack: fileURLToPath needed :/
8+
if (process.env.CI_ENV === "windows") {
9+
return contents.replace(CLRF_RE, "\n"); // only do work on Windows
10+
}
11+
return contents;
12+
}

packages/openapi-typescript/test/index.test.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import fs from "node:fs";
1+
import { URL } from "node:url";
22
import openapiTS from "../dist/index.js";
33
import type { OpenAPI3 } from "../src/types.js";
4+
import { readFile } from "./helpers.js";
45

56
const BOILERPLATE = `/**
67
* This file was auto-generated by openapi-typescript.
@@ -784,7 +785,7 @@ export type operations = Record<string, never>;
784785
},
785786
},
786787
},
787-
{ exportType: false }
788+
{ exportType: false },
788789
);
789790
expect(generated).toBe(`${BOILERPLATE}
790791
export type paths = Record<string, never>;
@@ -826,7 +827,7 @@ export type operations = Record<string, never>;
826827
},
827828
},
828829
},
829-
{ exportType: true }
830+
{ exportType: true },
830831
);
831832
expect(generated).toBe(`${BOILERPLATE}
832833
export type paths = Record<string, never>;
@@ -1091,7 +1092,7 @@ export type operations = Record<string, never>;
10911092
},
10921093
},
10931094
},
1094-
{ exportType: false }
1095+
{ exportType: false },
10951096
);
10961097
expect(generated).toBe(`${BOILERPLATE}${ONE_OF_TYPE_HELPERS}
10971098
export type paths = Record<string, never>;
@@ -1144,7 +1145,7 @@ export type operations = Record<string, never>;
11441145
},
11451146
},
11461147
},
1147-
{ exportType: false }
1148+
{ exportType: false },
11481149
);
11491150
expect(generated).toBe(`${BOILERPLATE}${WITH_REQUIRED_TYPE_HELPERS}
11501151
export type paths = Record<string, never>;
@@ -1206,32 +1207,37 @@ export type operations = Record<string, never>;
12061207
describe("GitHub", () => {
12071208
test("default options", async () => {
12081209
const generated = await openapiTS(new URL("./github-api.yaml", EXAMPLES_DIR));
1209-
expect(generated).toBe(fs.readFileSync(new URL("./github-api.ts", EXAMPLES_DIR), "utf8"));
1210+
expect(generated).toBe(readFile(new URL("./github-api.ts", EXAMPLES_DIR)));
12101211
}, 30000);
12111212
});
12121213
describe("GitHub (next)", () => {
12131214
test("default options", async () => {
12141215
const generated = await openapiTS(new URL("./github-api-next.yaml", EXAMPLES_DIR));
1215-
expect(generated).toBe(fs.readFileSync(new URL("./github-api-next.ts", EXAMPLES_DIR), "utf8"));
1216+
expect(generated).toBe(readFile(new URL("./github-api-next.ts", EXAMPLES_DIR)));
12161217
}, 30000);
12171218
});
12181219
describe("Octokit GHES 3.6 Diff to API", () => {
12191220
test("default options", async () => {
12201221
const generated = await openapiTS(new URL("./octokit-ghes-3.6-diff-to-api.json", EXAMPLES_DIR));
1221-
expect(generated).toBe(fs.readFileSync(new URL("./octokit-ghes-3.6-diff-to-api.ts", EXAMPLES_DIR), "utf8"));
1222+
expect(generated).toBe(readFile(new URL("./octokit-ghes-3.6-diff-to-api.ts", EXAMPLES_DIR)));
12221223
}, 30000);
12231224
});
12241225
describe("Stripe", () => {
12251226
test("default options", async () => {
12261227
const generated = await openapiTS(new URL("./stripe-api.yaml", EXAMPLES_DIR));
1227-
expect(generated).toBe(fs.readFileSync(new URL("./stripe-api.ts", EXAMPLES_DIR), "utf8"));
1228+
expect(generated).toBe(readFile(new URL("./stripe-api.ts", EXAMPLES_DIR)));
12281229
}, 30000);
12291230
});
12301231
describe("DigitalOcean", () => {
1231-
test("default options", async () => {
1232-
const generated = await openapiTS(new URL("./digital-ocean-api/DigitalOcean-public.v2.yaml", EXAMPLES_DIR));
1233-
expect(generated).toBe(fs.readFileSync(new URL("./digital-ocean-api.ts", EXAMPLES_DIR), "utf8"));
1234-
}, 60000);
1232+
// this test runs too slowly on macos / windows in GitHub Actions (not not natively)
1233+
test.skipIf(process.env.CI_ENV === "macos" || process.env.CI_ENV === "windows")(
1234+
"default options",
1235+
async () => {
1236+
const generated = await openapiTS(new URL("./digital-ocean-api/DigitalOcean-public.v2.yaml", EXAMPLES_DIR));
1237+
expect(generated).toBe(readFile(new URL("./digital-ocean-api.ts", EXAMPLES_DIR)));
1238+
},
1239+
60000,
1240+
);
12351241
});
12361242
});
12371243
});

packages/openapi-typescript/test/load.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { dump as stringifyYaml } from "js-yaml";
22
import { Readable } from "node:stream";
3+
import { URL } from "node:url";
34
import { Response, fetch as unidiciFetch } from "undici";
45
import internalLoad, { type LoadOptions } from "../src/load.js";
56
import type { Subschema } from "../src/types.js";

packages/openapi-typescript/test/yaml.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { execa } from "execa";
2+
import os from "node:os";
3+
import { URL, fileURLToPath } from "node:url";
24

3-
const CMD = "./bin/cli.js";
4-
const cwd = new URL("../", import.meta.url);
5+
const root = new URL("../", import.meta.url);
6+
const cwd = os.platform() === "win32" ? fileURLToPath(root) : root; // execa bug: fileURLToPath required on Windows
7+
const cmd = "./bin/cli.js";
58

69
describe("YAML features", () => {
710
it("merge", async () => {
8-
const result = await execa(CMD, ["./test/fixtures/yaml-merge.yaml"], { cwd });
11+
const result = await execa(cmd, ["./test/fixtures/yaml-merge.yaml"], { cwd });
912
expect(result.stdout).toMatchInlineSnapshot(`
1013
"/**
1114
* This file was auto-generated by openapi-typescript.

0 commit comments

Comments
 (0)