From 094704d8a9ba9368786f5249b832cdcb369cd38e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20van=20Velzen=20=F0=9F=81=B4?= Date: Fri, 26 Jun 2026 14:26:52 -0700 Subject: [PATCH] Fix unitest to pass on Win32 --- .../yarnpkg-libzip/tests/ZipOpenFS.test.ts | 5 +++- packages/yarnpkg-shell/tests/shell.test.ts | 26 +++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/yarnpkg-libzip/tests/ZipOpenFS.test.ts b/packages/yarnpkg-libzip/tests/ZipOpenFS.test.ts index fe75d7818187..c31b8a92547e 100644 --- a/packages/yarnpkg-libzip/tests/ZipOpenFS.test.ts +++ b/packages/yarnpkg-libzip/tests/ZipOpenFS.test.ts @@ -28,6 +28,8 @@ export const ZIP_FILE3 = ppath.join(ZIP_DIR3, `foo.txt`); export const ZIP_FILE4 = ppath.join(ZIP_DIR4, `foo.txt`); export const ZIP_FILE5 = ppath.join(ZIP_DIR5, `foo.txt`); +const itSkipWin32 = process.platform !== `win32` ? it : it.skip; + afterEach(() => { jest.useRealTimers(); }); @@ -100,7 +102,8 @@ describe(`ZipOpenFS`, () => { fs.discardAndClose(); }); - it(`can read from a zip file that's a symlink`, () => { + // This test does not work on win32 because the checked in symlink is not properly materialized from git. + itSkipWin32(`can read from a zip file that's a symlink`, () => { const fs = new ZipOpenFS(); expect(fs.readFileSync(ZIP_FILE4, `utf8`)).toEqual(`foo\n`); diff --git a/packages/yarnpkg-shell/tests/shell.test.ts b/packages/yarnpkg-shell/tests/shell.test.ts index be7b68bd6079..bea6adee4259 100644 --- a/packages/yarnpkg-shell/tests/shell.test.ts +++ b/packages/yarnpkg-shell/tests/shell.test.ts @@ -20,6 +20,10 @@ const expectResult = async (promise: Promise, {exitCode = 0, stdout = ``, s return await expect(promise).resolves.toMatchObject({exitCode, stdout, stderr}); }; +// Not all windows sku's ship cat on the path. findstr with "^" will match all the test cases here to map stdin to stdout +// Should https://learn.microsoft.com/en-us/windows/core-utils/overview ship by default with windows, this can be removed and replaced with cat +const catTool = isNotWin32 ? `cat` : `findstr "^"`; + const bufferResult = async (command: string, args: Array = [], options: Partial & {tty?: boolean} = {}): Promise => { const stdout = new PassThrough(); const stderr = new PassThrough(); @@ -778,7 +782,7 @@ describe(`Shell`, () => { await xfs.writeFilePromise(file, `hello world\n`); await expectResult(bufferResult( - `cat < "${file}"`, + `${catTool} < "${file}"`, ), { stdout: `hello world\n`, }); @@ -791,7 +795,7 @@ describe(`Shell`, () => { await xfs.writeFilePromise(file, `hello world\n`); await expectResult(bufferResult( - `cat 0< "${file}"`, + `${catTool} 0< "${file}"`, ), { stdout: `hello world\n`, }); @@ -807,7 +811,7 @@ describe(`Shell`, () => { await xfs.writeFilePromise(file2, `hello world\n`); await expectResult(bufferResult( - `cat < "${file1}" < "${file2}"`, + `${catTool} < "${file1}" < "${file2}"`, ), { stdout: `foo bar baz\nhello world\n`, }); @@ -820,15 +824,15 @@ describe(`Shell`, () => { await xfs.writeFilePromise(file, `hello world\n`); await expect(bufferResult( - `cat 1< "${file}"`, + `${catTool} 1< "${file}"`, )).rejects.toThrowError(`Unsupported file descriptor: "1"`); await expect(bufferResult( - `cat 2< "${file}"`, + `${catTool} 2< "${file}"`, )).rejects.toThrowError(`Unsupported file descriptor: "2"`); await expect(bufferResult( - `cat 3< "${file}"`, + `${catTool} 3< "${file}"`, )).rejects.toThrowError(`Unsupported file descriptor: "3"`); }); }); @@ -837,7 +841,7 @@ describe(`Shell`, () => { describe(`<<<`, () => { it(`should support input redirections (string)`, async () => { await expectResult(bufferResult( - `cat <<< "hello world"`, + `${catTool} <<< "hello world"`, ), { stdout: `hello world\n`, }); @@ -845,7 +849,7 @@ describe(`Shell`, () => { it(`should support input redirections to fd (string)`, async () => { await expectResult(bufferResult( - `cat 0<<< "hello world"`, + `${catTool} 0<<< "hello world"`, ), { stdout: `hello world\n`, }); @@ -854,15 +858,15 @@ describe(`Shell`, () => { it(`should throw on input redirections to unsupported file descriptors`, async () => { await xfs.mktempPromise(async tmpDir => { await expect(bufferResult( - `cat 1<<< "hello world"`, + `${catTool} 1<<< "hello world"`, )).rejects.toThrowError(`Unsupported file descriptor: "1"`); await expect(bufferResult( - `cat 2<<< "hello world"`, + `${catTool} 2<<< "hello world"`, )).rejects.toThrowError(`Unsupported file descriptor: "2"`); await expect(bufferResult( - `cat 3<<< "hello world"`, + `${catTool} 3<<< "hello world"`, )).rejects.toThrowError(`Unsupported file descriptor: "3"`); }); });