Skip to content

Commit

Permalink
Merge pull request #214 from jason-ha/test-on-windows
Browse files Browse the repository at this point in the history
test: support testing on Windows
  • Loading branch information
andrewbranch authored Sep 22, 2024
2 parents 93912ad + ede64c2 commit fcb4268
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 28 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ on:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"tsc": "tsc -b",
"local:install": "npm install -g .",
"local:uninstall": "npm uninstall -g @arethetypeswrong/cli",
"test": "tsc -b test && node --test 'test/dist/**/*.test.js'",
"test": "tsc -b test && node --test \"test/dist/**/*.test.js\"",
"prepack": "pnpm tsc"
},
"type": "module",
Expand Down
32 changes: 18 additions & 14 deletions packages/cli/test/snapshots.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { access, readFile, writeFile } from "fs/promises";
import { execSync, type SpawnSyncReturns } from "child_process";
import assert from "node:assert";
import path from "node:path";
import { after, describe, test } from "node:test";
import { fileURLToPath } from "node:url";

const attw = `node ${new URL("../../dist/index.js", import.meta.url).pathname}`;
const directoryPath = path.dirname(fileURLToPath(import.meta.url));
function resolveFileRelativePath(relPath: string) {
return path.resolve(directoryPath, relPath);
}

const attw = `node ${resolveFileRelativePath("../../dist/index.js")}`;
const updateSnapshots = process.env.UPDATE_SNAPSHOTS || process.env.U;
const testFilter = (process.env.TEST_FILTER || process.env.T)?.toLowerCase();

Expand Down Expand Up @@ -34,11 +41,11 @@ const tests = [

[
"[email protected]",
`--definitely-typed ${new URL("../../../core/test/fixtures/@[email protected]", import.meta.url).pathname}`,
`--definitely-typed ${resolveFileRelativePath("../../../core/test/fixtures/@[email protected]")}`,
],
[
"[email protected]",
`--definitely-typed ${new URL("../../../core/test/fixtures/@[email protected]", import.meta.url).pathname}`,
`--definitely-typed ${resolveFileRelativePath("../../../core/test/fixtures/@[email protected]")}`,
],

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

test(fixture, async () => {
const tarballPath = new URL(`../../../core/test/fixtures/${tarball}`, import.meta.url).pathname;
const tarballPath = resolveFileRelativePath(`../../../core/test/fixtures/${tarball}`);
let stdout;
let stderr = "";
let exitCode = 0;
Expand All @@ -85,7 +92,7 @@ describe("snapshots", async () => {
}
const snapshotURL = new URL(`../snapshots/${fixture}.md`, import.meta.url);
// prettier-ignore
const expectedSnapshot = [
const actualSnapshot = [
`# ${fixture}`,
"",
"```",
Expand All @@ -99,19 +106,16 @@ describe("snapshots", async () => {
].join("\n");

if (
await access(snapshotURL)
!updateSnapshots &&
(await access(snapshotURL)
.then(() => true)
.catch(() => false)
.catch(() => false))
) {
const snapshot = await readFile(snapshotURL, "utf8");
if (updateSnapshots) {
await writeFile(snapshotURL, expectedSnapshot);
snapshotsWritten.push(snapshotURL);
} else {
assert.strictEqual(snapshot, expectedSnapshot);
}
const expectedSnapshot = snapshot.replace(/\r\n/g, "\n");
assert.strictEqual(actualSnapshot, expectedSnapshot);
} else {
await writeFile(snapshotURL, expectedSnapshot);
await writeFile(snapshotURL, actualSnapshot);
snapshotsWritten.push(snapshotURL);
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"scripts": {
"tsc": "tsc",
"test": "tsc -b test && node --test 'test/dist/**/*.test.js'",
"test": "tsc -b test && node --test \"test/dist/**/*.test.js\"",
"snapshot": "node scripts/createSnapshotFixture.js",
"prepack": "pnpm tsc"
},
Expand Down
17 changes: 7 additions & 10 deletions packages/core/test/snapshots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,19 @@ describe("snapshots", async () => {
}

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

if (
await access(snapshotURL)
!updateSnapshots &&
(await access(snapshotURL)
.then(() => true)
.catch(() => false)
.catch(() => false))
) {
const snapshot = await readFile(snapshotURL, "utf8");
if (updateSnapshots) {
await writeFile(snapshotURL, expectedSnapshot);
snapshotsWritten.push(snapshotURL);
} else {
assert.strictEqual(snapshot, expectedSnapshot);
}
const expectedSnapshot = snapshot.replace(/\r\n/g, "\n");
assert.strictEqual(actualSnapshot, expectedSnapshot);
} else {
await writeFile(snapshotURL, expectedSnapshot);
await writeFile(snapshotURL, actualSnapshot);
snapshotsWritten.push(snapshotURL);
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function createTestPackage(
assert(name.startsWith(`/node_modules/${packageName}/`));
return [name, content];
}
return [path.join(`/node_modules/${packageName}`, name), content];
return [path.posix.join(`/node_modules/${packageName}`, name), content];
}),
),
packageName,
Expand Down

0 comments on commit fcb4268

Please sign in to comment.