Skip to content

Commit fcb4268

Browse files
authored
Merge pull request #214 from jason-ha/test-on-windows
test: support testing on Windows
2 parents 93912ad + ede64c2 commit fcb4268

File tree

6 files changed

+32
-28
lines changed

6 files changed

+32
-28
lines changed

.github/workflows/ci.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ on:
55

66
jobs:
77
build:
8-
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
os: [ubuntu-latest, windows-latest]
11+
runs-on: ${{ matrix.os }}
912
steps:
1013
- uses: actions/checkout@v3
1114
with:

packages/cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"tsc": "tsc -b",
4141
"local:install": "npm install -g .",
4242
"local:uninstall": "npm uninstall -g @arethetypeswrong/cli",
43-
"test": "tsc -b test && node --test 'test/dist/**/*.test.js'",
43+
"test": "tsc -b test && node --test \"test/dist/**/*.test.js\"",
4444
"prepack": "pnpm tsc"
4545
},
4646
"type": "module",

packages/cli/test/snapshots.test.ts

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { access, readFile, writeFile } from "fs/promises";
22
import { execSync, type SpawnSyncReturns } from "child_process";
33
import assert from "node:assert";
4+
import path from "node:path";
45
import { after, describe, test } from "node:test";
6+
import { fileURLToPath } from "node:url";
57

6-
const attw = `node ${new URL("../../dist/index.js", import.meta.url).pathname}`;
8+
const directoryPath = path.dirname(fileURLToPath(import.meta.url));
9+
function resolveFileRelativePath(relPath: string) {
10+
return path.resolve(directoryPath, relPath);
11+
}
12+
13+
const attw = `node ${resolveFileRelativePath("../../dist/index.js")}`;
714
const updateSnapshots = process.env.UPDATE_SNAPSHOTS || process.env.U;
815
const testFilter = (process.env.TEST_FILTER || process.env.T)?.toLowerCase();
916

@@ -34,11 +41,11 @@ const tests = [
3441

3542
[
3643
37-
`--definitely-typed ${new URL("../../../core/test/fixtures/@[email protected]", import.meta.url).pathname}`,
44+
`--definitely-typed ${resolveFileRelativePath("../../../core/test/fixtures/@[email protected]")}`,
3845
],
3946
[
4047
41-
`--definitely-typed ${new URL("../../../core/test/fixtures/@[email protected]", import.meta.url).pathname}`,
48+
`--definitely-typed ${resolveFileRelativePath("../../../core/test/fixtures/@[email protected]")}`,
4249
],
4350

4451
["[email protected]", "--entrypoints-legacy --ignore-rules=cjs-only-exports-default"],
@@ -69,7 +76,7 @@ describe("snapshots", async () => {
6976
}
7077

7178
test(fixture, async () => {
72-
const tarballPath = new URL(`../../../core/test/fixtures/${tarball}`, import.meta.url).pathname;
79+
const tarballPath = resolveFileRelativePath(`../../../core/test/fixtures/${tarball}`);
7380
let stdout;
7481
let stderr = "";
7582
let exitCode = 0;
@@ -85,7 +92,7 @@ describe("snapshots", async () => {
8592
}
8693
const snapshotURL = new URL(`../snapshots/${fixture}.md`, import.meta.url);
8794
// prettier-ignore
88-
const expectedSnapshot = [
95+
const actualSnapshot = [
8996
`# ${fixture}`,
9097
"",
9198
"```",
@@ -99,19 +106,16 @@ describe("snapshots", async () => {
99106
].join("\n");
100107

101108
if (
102-
await access(snapshotURL)
109+
!updateSnapshots &&
110+
(await access(snapshotURL)
103111
.then(() => true)
104-
.catch(() => false)
112+
.catch(() => false))
105113
) {
106114
const snapshot = await readFile(snapshotURL, "utf8");
107-
if (updateSnapshots) {
108-
await writeFile(snapshotURL, expectedSnapshot);
109-
snapshotsWritten.push(snapshotURL);
110-
} else {
111-
assert.strictEqual(snapshot, expectedSnapshot);
112-
}
115+
const expectedSnapshot = snapshot.replace(/\r\n/g, "\n");
116+
assert.strictEqual(actualSnapshot, expectedSnapshot);
113117
} else {
114-
await writeFile(snapshotURL, expectedSnapshot);
118+
await writeFile(snapshotURL, actualSnapshot);
115119
snapshotsWritten.push(snapshotURL);
116120
}
117121
});

packages/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"scripts": {
2121
"tsc": "tsc",
22-
"test": "tsc -b test && node --test 'test/dist/**/*.test.js'",
22+
"test": "tsc -b test && node --test \"test/dist/**/*.test.js\"",
2323
"snapshot": "node scripts/createSnapshotFixture.js",
2424
"prepack": "pnpm tsc"
2525
},

packages/core/test/snapshots.test.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,19 @@ describe("snapshots", async () => {
5858
}
5959

6060
const snapshotURL = new URL(`../snapshots/${fixture}.json`, import.meta.url);
61-
const expectedSnapshot = JSON.stringify(analysis, null, 2) + "\n";
61+
const actualSnapshot = JSON.stringify(analysis, null, 2) + "\n";
6262

6363
if (
64-
await access(snapshotURL)
64+
!updateSnapshots &&
65+
(await access(snapshotURL)
6566
.then(() => true)
66-
.catch(() => false)
67+
.catch(() => false))
6768
) {
6869
const snapshot = await readFile(snapshotURL, "utf8");
69-
if (updateSnapshots) {
70-
await writeFile(snapshotURL, expectedSnapshot);
71-
snapshotsWritten.push(snapshotURL);
72-
} else {
73-
assert.strictEqual(snapshot, expectedSnapshot);
74-
}
70+
const expectedSnapshot = snapshot.replace(/\r\n/g, "\n");
71+
assert.strictEqual(actualSnapshot, expectedSnapshot);
7572
} else {
76-
await writeFile(snapshotURL, expectedSnapshot);
73+
await writeFile(snapshotURL, actualSnapshot);
7774
snapshotsWritten.push(snapshotURL);
7875
}
7976
});

packages/core/test/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function createTestPackage(
1414
assert(name.startsWith(`/node_modules/${packageName}/`));
1515
return [name, content];
1616
}
17-
return [path.join(`/node_modules/${packageName}`, name), content];
17+
return [path.posix.join(`/node_modules/${packageName}`, name), content];
1818
}),
1919
),
2020
packageName,

0 commit comments

Comments
 (0)