Skip to content

Commit

Permalink
test: fix NODE_PATH test on Windows (#5257)
Browse files Browse the repository at this point in the history
* test: fix NODE_PATH test on Windows

* fix: test
  • Loading branch information
zkochan committed Aug 24, 2022
1 parent 5c8e272 commit 9e0a9f4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
37 changes: 0 additions & 37 deletions packages/plugin-commands-script-runners/test/index.ts
Expand Up @@ -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`)
})
39 changes: 39 additions & 0 deletions packages/pnpm/test/run.ts
Expand Up @@ -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([{
Expand Down Expand Up @@ -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`)
})

0 comments on commit 9e0a9f4

Please sign in to comment.