Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test/lib
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2021-02-26 02:38:28 +0300
committerRuy Adorno <ruyadorno@hotmail.com>2021-03-05 00:07:14 +0300
commite69be2ac5c35e985732e2baa00b70d39332e4b9f (patch)
tree302f7bf48708fafc31ff0ced070609c4e183474c /test/lib
parent4a5dd3a5a200b3f4f7b47168497d8e03dca3a2ca (diff)
Get correct npm prefix on all Windows unix shellsisaacs/fix-windows-shell-bins
1. Set the shebang to /usr/bin/env bash instead of /bin/sh (which might be dash or some other shell) 2. Use Unix-style line endings, not Windows-style (Cygwin accepts either, but mingw bash sometimes objects, and WSL bash always does) 3. Test against paths using wslpath if available, but still pass win32 paths to node.exe, since it is a Windows binary that only knows how to handle Windows paths. This makes npm as installed by the Node.js Windows MSI installer behave properly under WSL, Cygwin, MINGW Git Bash, and the internal MINGW Git Bash when posix CLI utilities are exposed to the cmd.exe shell. The test is not quite as comprehensive as I'd like. It runs on the various Windows bash implementations if they are found in their expected locations, skipping any that are not installed. Short of shipping mingw, cygwin, and wsl as test fixtures, I'm not sure how we could do much better, however. At least, we can use this test to assist debug and catch issues on Windows machines (ours or users who report problems). PR-URL: https://github.com/npm/cli/pull/2789 Credit: @isaacs Close: #2789 Reviewed-by: @nlf
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/doctor.js2
-rw-r--r--test/lib/npm.js13
2 files changed, 6 insertions, 9 deletions
diff --git a/test/lib/doctor.js b/test/lib/doctor.js
index 820049347..eaa7ad72d 100644
--- a/test/lib/doctor.js
+++ b/test/lib/doctor.js
@@ -487,7 +487,7 @@ test('node versions', t => {
const dir = st.testdir({
cache: {
one: 'one',
- link: st.fixture('symlink', './one'),
+ link: st.fixture('symlink', './baddir'),
unreadable: 'unreadable',
baddir: {},
},
diff --git a/test/lib/npm.js b/test/lib/npm.js
index 18bed36de..1f7a54e22 100644
--- a/test/lib/npm.js
+++ b/test/lib/npm.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const fs = require('fs')
// delete this so that we don't have configs from the fact that it
// is being run by 'npm test'
@@ -21,7 +20,7 @@ for (const env of Object.keys(process.env).filter(e => /^npm_/.test(e))) {
delete process.env[env]
}
-const { resolve } = require('path')
+const { resolve, dirname } = require('path')
const actualPlatform = process.platform
@@ -249,13 +248,11 @@ t.test('npm.load', t => {
const node = actualPlatform === 'win32' ? 'node.exe' : 'node'
const dir = t.testdir({
'.npmrc': 'foo = bar',
+ bin: t.fixture('symlink', dirname(process.execPath)),
})
- // create manually to set the 'file' option in windows
- fs.symlinkSync(process.execPath, resolve(dir, node), 'file')
-
const PATH = process.env.PATH || process.env.Path
- process.env.PATH = dir
+ process.env.PATH = resolve(dir, 'bin')
const { execPath, argv: processArgv } = process
process.argv = [
node,
@@ -294,7 +291,7 @@ t.test('npm.load', t => {
[
'verbose',
'node symlink',
- resolve(dir, node),
+ resolve(dir, 'bin', node),
],
[
'timing',
@@ -303,7 +300,7 @@ t.test('npm.load', t => {
],
])
logs.length = 0
- t.equal(process.execPath, resolve(dir, node))
+ t.equal(process.execPath, resolve(dir, 'bin', node))
})
await npm.commands.ll([], (er) => {