Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix NODE_PATH test on Windows #5257

Merged
merged 2 commits into from Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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`)
})