From 9e0a9f49cb8267647e0306ffa72c3631929bd879 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Wed, 24 Aug 2022 22:50:39 +0300 Subject: [PATCH] test: fix NODE_PATH test on Windows (#5257) * test: fix NODE_PATH test on Windows * fix: test --- .../test/index.ts | 37 ------------------ packages/pnpm/test/run.ts | 39 +++++++++++++++++++ 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/packages/plugin-commands-script-runners/test/index.ts b/packages/plugin-commands-script-runners/test/index.ts index e8b139861a8..20155509c65 100644 --- a/packages/plugin-commands-script-runners/test/index.ts +++ b/packages/plugin-commands-script-runners/test/index.ts @@ -465,40 +465,3 @@ test('pnpm run with custom shell', async () => { expect((await import(path.resolve('shell-input.json'))).default).toStrictEqual(['-c', 'foo bar']) }) - -test('pnpm run with preferSymlinkedExecutables true', async () => { - prepare({ - scripts: { - build: 'node -e "console.log(process.env.NODE_PATH)"', - }, - }) - - const npmrc = ` - prefer-symlinked-executables=true=true - ` - - await fs.writeFile('.npmrc', npmrc, 'utf8') - - const result = await execa(pnpmBin, ['run', 'build']) - - expect(result.stdout).toContain(`project${path.sep}node_modules${path.sep}.pnpm${path.sep}node_modules`) -}) - -test('pnpm run with preferSymlinkedExecutables and custom virtualStoreDir', async () => { - prepare({ - scripts: { - build: 'node -e "console.log(process.env.NODE_PATH)"', - }, - }) - - const npmrc = ` - virtual-store-dir=/foo/bar - prefer-symlinked-executables=true=true - ` - - await fs.writeFile('.npmrc', npmrc, 'utf8') - - const result = await execa(pnpmBin, ['run', 'build']) - - expect(result.stdout).toContain(`${path.sep}foo${path.sep}bar${path.sep}node_modules`) -}) diff --git a/packages/pnpm/test/run.ts b/packages/pnpm/test/run.ts index 692fb1f74a4..46bc6baf829 100644 --- a/packages/pnpm/test/run.ts +++ b/packages/pnpm/test/run.ts @@ -2,9 +2,11 @@ import { promises as fs, mkdirSync } from 'fs' import path from 'path' import PATH_NAME from 'path-name' import prepare, { preparePackages } from '@pnpm/prepare' +import isWindows from 'is-windows' import { execPnpm, execPnpmSync } from './utils' const RECORD_ARGS_FILE = 'require(\'fs\').writeFileSync(\'args.json\', JSON.stringify(require(\'./args.json\').concat([process.argv.slice(2)])), \'utf8\')' +const testOnPosix = isWindows() ? test.skip : test test('run -r: pass the args to the command that is specified in the build script', async () => { preparePackages([{ @@ -138,3 +140,40 @@ test('silent dlx prints the output of the child process only', async () => { expect(result.stdout.toString().trim()).toBe('hi') }) + +testOnPosix('pnpm run with preferSymlinkedExecutables true', async () => { + prepare({ + scripts: { + build: 'node -e "console.log(process.env.NODE_PATH)"', + }, + }) + + const npmrc = ` + prefer-symlinked-executables=true=true + ` + + await fs.writeFile('.npmrc', npmrc, 'utf8') + + const result = execPnpmSync(['run', 'build']) + + expect(result.stdout).toContain(`project${path.sep}node_modules${path.sep}.pnpm${path.sep}node_modules`) +}) + +testOnPosix('pnpm run with preferSymlinkedExecutables and custom virtualStoreDir', async () => { + prepare({ + scripts: { + build: 'node -e "console.log(process.env.NODE_PATH)"', + }, + }) + + const npmrc = ` + virtual-store-dir=/foo/bar + prefer-symlinked-executables=true=true + ` + + await fs.writeFile('.npmrc', npmrc, 'utf8') + + const result = execPnpmSync(['run', 'build']) + + expect(result.stdout).toContain(`${path.sep}foo${path.sep}bar${path.sep}node_modules`) +})