diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2bcf9b3..026559e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/packages/cli/package.json b/packages/cli/package.json index 369d471..7d3661a 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -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", diff --git a/packages/cli/test/snapshots.test.ts b/packages/cli/test/snapshots.test.ts index e4ab309..472019e 100644 --- a/packages/cli/test/snapshots.test.ts +++ b/packages/cli/test/snapshots.test.ts @@ -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(); @@ -34,11 +41,11 @@ const tests = [ [ "big.js@6.2.1.tgz", - `--definitely-typed ${new URL("../../../core/test/fixtures/@types__big.js@6.2.0.tgz", import.meta.url).pathname}`, + `--definitely-typed ${resolveFileRelativePath("../../../core/test/fixtures/@types__big.js@6.2.0.tgz")}`, ], [ "react@18.2.0.tgz", - `--definitely-typed ${new URL("../../../core/test/fixtures/@types__react@18.2.21.tgz", import.meta.url).pathname}`, + `--definitely-typed ${resolveFileRelativePath("../../../core/test/fixtures/@types__react@18.2.21.tgz")}`, ], ["eslint-module-utils@2.8.1.tgz", "--entrypoints-legacy --ignore-rules=cjs-only-exports-default"], @@ -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; @@ -85,7 +92,7 @@ describe("snapshots", async () => { } const snapshotURL = new URL(`../snapshots/${fixture}.md`, import.meta.url); // prettier-ignore - const expectedSnapshot = [ + const actualSnapshot = [ `# ${fixture}`, "", "```", @@ -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); } }); diff --git a/packages/core/package.json b/packages/core/package.json index d25d738..4fdc421 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -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" }, diff --git a/packages/core/test/snapshots.test.ts b/packages/core/test/snapshots.test.ts index 497b5c1..da2d5ea 100644 --- a/packages/core/test/snapshots.test.ts +++ b/packages/core/test/snapshots.test.ts @@ -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); } }); diff --git a/packages/core/test/utils.ts b/packages/core/test/utils.ts index 0375b6e..22a2c37 100644 --- a/packages/core/test/utils.ts +++ b/packages/core/test/utils.ts @@ -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,