From 357d0502d9b61d6edcfe0bf050893a648082b86f Mon Sep 17 00:00:00 2001 From: Jeff Yates Date: Wed, 18 Mar 2026 11:53:25 -0500 Subject: [PATCH] [multiplatformtesting] Add cross-platform testing --- .github/workflows/nodejs.yml | 15 +++++++++++---- src/__tests__/discover-packages.test.ts | 9 ++++++++- src/__tests__/find-matching-bins.test.ts | 9 ++++++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 67f23c1..559a425 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -55,14 +55,14 @@ jobs: with: exclude: .github/,.storybook/ - coverage: - name: Update test coverage + test: + name: Test on ${{ matrix.os }} env: CI: true runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-latest, macos-latest, windows-latest] node-version: [20.x] steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd @@ -84,15 +84,22 @@ jobs: shell: bash run: pnpm install --frozen-lockfile + - name: Run tests + if: ${{ matrix.os != 'ubuntu-latest' }} + run: pnpm test --run + - name: Run tests with coverage + if: ${{ matrix.os == 'ubuntu-latest' }} run: pnpm coverage + - name: Upload coverage + if: ${{ matrix.os == 'ubuntu-latest' }} uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} build: - needs: [coverage, lint] + needs: [lint, test] name: Build env: CI: true diff --git a/src/__tests__/discover-packages.test.ts b/src/__tests__/discover-packages.test.ts index 99f93b3..2d1e002 100644 --- a/src/__tests__/discover-packages.test.ts +++ b/src/__tests__/discover-packages.test.ts @@ -1,3 +1,4 @@ +import path from "node:path"; import * as manypkg from "@manypkg/get-packages"; import {beforeEach, describe, expect, it, vi} from "vitest"; import {discoverPackages} from "../discover-packages"; @@ -8,6 +9,10 @@ vi.mock("@manypkg/get-packages", () => ({ getPackages: vi.fn(), })); +function normalizePathForComparison(filePath: string): string { + return filePath.replaceAll(path.sep, "/"); +} + describe("discoverPackages", () => { beforeEach(() => { vi.clearAllMocks(); @@ -77,7 +82,9 @@ describe("discoverPackages", () => { const result = await discoverPackages(workspaceRoot); // Assert - expect(result[0].path).toBe("/test/workspace/packages/test"); + expect(normalizePathForComparison(result[0].path)).toBe( + "/test/workspace/packages/test", + ); }); it("should map package versions correctly", async () => { diff --git a/src/__tests__/find-matching-bins.test.ts b/src/__tests__/find-matching-bins.test.ts index de35034..9218644 100644 --- a/src/__tests__/find-matching-bins.test.ts +++ b/src/__tests__/find-matching-bins.test.ts @@ -1,3 +1,4 @@ +import path from "node:path"; import {beforeEach, describe, expect, it, vi} from "vitest"; import type {PackageInfo} from "../discover-packages"; import {findMatchingBins} from "../find-matching-bins"; @@ -9,6 +10,10 @@ vi.mock("node:fs/promises", () => ({ import * as fs from "node:fs/promises"; +function normalizePathForComparison(filePath: string): string { + return filePath.replaceAll(path.sep, "/"); +} + describe("findMatchingBins", () => { beforeEach(() => { vi.clearAllMocks(); @@ -118,7 +123,9 @@ describe("findMatchingBins", () => { const matches = await findMatchingBins(packages, "x"); // Assert - expect(matches[0].binPath).toBe("/test/path/dist/x.mjs"); + expect(normalizePathForComparison(matches[0].binPath)).toBe( + "/test/path/dist/x.mjs", + ); }); it("should return empty array when no bins match", async () => {