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:
authorGar <gar+gh@danger.computer>2022-03-24 17:44:01 +0300
committerLuke Karrys <luke@lukekarrys.com>2022-03-28 23:21:36 +0300
commitf76d4f2f661bcc2534f541ee0e7d683155372baf (patch)
treeb4edbfc7306780aac35f7aa727f604944a8cc4c4 /test/lib
parentd8dcc02cfd354c1314c45d6530ec926cd138210c (diff)
fix: consolidate is-windows code
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/commands/completion.js2
-rw-r--r--test/lib/commands/explore.js1
-rw-r--r--test/lib/commands/run-script.js6
-rw-r--r--test/lib/utils/config/definitions.js18
-rw-r--r--test/lib/utils/is-windows-bash.js30
-rw-r--r--test/lib/utils/is-windows-shell.js8
-rw-r--r--test/lib/utils/is-windows.js43
-rw-r--r--test/lib/utils/path.js3
8 files changed, 52 insertions, 59 deletions
diff --git a/test/lib/commands/completion.js b/test/lib/commands/completion.js
index 045054b74..d4e6f1199 100644
--- a/test/lib/commands/completion.js
+++ b/test/lib/commands/completion.js
@@ -17,7 +17,7 @@ const loadMockCompletion = async (t, o = {}) => {
}
const res = await _loadMockNpm(t, {
mocks: {
- '../../lib/utils/is-windows-shell.js': !!windows,
+ '../../lib/utils/is-windows.js': { isWindowsShell: !!windows },
...options.mocks,
},
...options,
diff --git a/test/lib/commands/explore.js b/test/lib/commands/explore.js
index d1355d767..5bb211e45 100644
--- a/test/lib/commands/explore.js
+++ b/test/lib/commands/explore.js
@@ -47,7 +47,6 @@ const output = []
const logs = []
const getExplore = (windows) => {
const Explore = t.mock('../../../lib/commands/explore.js', {
- '../../../lib/utils/is-windows.js': windows,
path: require('path')[windows ? 'win32' : 'posix'],
'read-package-json-fast': mockRPJ,
'@npmcli/run-script': mockRunScript,
diff --git a/test/lib/commands/run-script.js b/test/lib/commands/run-script.js
index 834b61e74..440c8dbad 100644
--- a/test/lib/commands/run-script.js
+++ b/test/lib/commands/run-script.js
@@ -62,7 +62,7 @@ const getRS = windows => {
}
),
'proc-log': log,
- '../../../lib/utils/is-windows-shell.js': windows,
+ '../../../lib/utils/is-windows.js': { isWindowsShell: windows },
})
return new RunScript(npm)
}
@@ -859,7 +859,7 @@ t.test('workspaces', t => {
throw new Error('err')
},
'proc-log': log,
- '../../../lib/utils/is-windows-shell.js': false,
+ '../../../lib/utils/is-windows.js': { isWindowsShell: false },
})
const runScript = new RunScript(npm)
@@ -877,7 +877,7 @@ t.test('workspaces', t => {
RUN_SCRIPTS.push(opts)
},
'proc-log': log,
- '../../../lib/utils/is-windows-shell.js': false,
+ '../../../lib/utils/is-windows.js': { isWindowsShell: false },
})
const runScript = new RunScript(npm)
diff --git a/test/lib/utils/config/definitions.js b/test/lib/utils/config/definitions.js
index a5b34a749..b387835df 100644
--- a/test/lib/utils/config/definitions.js
+++ b/test/lib/utils/config/definitions.js
@@ -53,11 +53,11 @@ t.test('editor', t => {
t.test('has neither EDITOR nor VISUAL, system specific', t => {
mockGlobals(t, { 'process.env': { EDITOR: undefined, VISUAL: undefined } })
const defsWin = t.mock(defpath, {
- [isWin]: true,
+ [isWin]: { isWindows: true },
})
t.equal(defsWin.editor.default, 'notepad.exe')
const defsNix = t.mock(defpath, {
- [isWin]: false,
+ [isWin]: { isWindows: false },
})
t.equal(defsNix.editor.default, 'vi')
t.end()
@@ -69,12 +69,12 @@ t.test('shell', t => {
t.test('windows, env.ComSpec then cmd.exe', t => {
mockGlobals(t, { 'process.env.ComSpec': 'command.com' })
const defsComSpec = t.mock(defpath, {
- [isWin]: true,
+ [isWin]: { isWindows: true },
})
t.equal(defsComSpec.shell.default, 'command.com')
mockGlobals(t, { 'process.env.ComSpec': undefined })
const defsNoComSpec = t.mock(defpath, {
- [isWin]: true,
+ [isWin]: { isWindows: true },
})
t.equal(defsNoComSpec.shell.default, 'cmd')
t.end()
@@ -83,12 +83,12 @@ t.test('shell', t => {
t.test('nix, SHELL then sh', t => {
mockGlobals(t, { 'process.env.SHELL': '/usr/local/bin/bash' })
const defsShell = t.mock(defpath, {
- [isWin]: false,
+ [isWin]: { isWindows: false },
})
t.equal(defsShell.shell.default, '/usr/local/bin/bash')
mockGlobals(t, { 'process.env.SHELL': undefined })
const defsNoShell = t.mock(defpath, {
- [isWin]: false,
+ [isWin]: { isWindows: false },
})
t.equal(defsNoShell.shell.default, 'sh')
t.end()
@@ -158,18 +158,18 @@ t.test('unicode allowed?', t => {
t.test('cache', t => {
mockGlobals(t, { 'process.env.LOCALAPPDATA': 'app/data/local' })
const defsWinLocalAppData = t.mock(defpath, {
- [isWin]: true,
+ [isWin]: { isWindows: true },
})
t.equal(defsWinLocalAppData.cache.default, 'app/data/local/npm-cache')
mockGlobals(t, { 'process.env.LOCALAPPDATA': undefined })
const defsWinNoLocalAppData = t.mock(defpath, {
- [isWin]: true,
+ [isWin]: { isWindows: true },
})
t.equal(defsWinNoLocalAppData.cache.default, '~/npm-cache')
const defsNix = t.mock(defpath, {
- [isWin]: false,
+ [isWin]: { isWindows: false },
})
t.equal(defsNix.cache.default, '~/.npm')
diff --git a/test/lib/utils/is-windows-bash.js b/test/lib/utils/is-windows-bash.js
deleted file mode 100644
index 0fbebdf8e..000000000
--- a/test/lib/utils/is-windows-bash.js
+++ /dev/null
@@ -1,30 +0,0 @@
-const t = require('tap')
-const mockGlobal = require('../../fixtures/mock-globals.js')
-
-const isWindowsBash = () => {
- delete require.cache[require.resolve('../../../lib/utils/is-windows-bash.js')]
- delete require.cache[require.resolve('../../../lib/utils/is-windows.js')]
- return require('../../../lib/utils/is-windows-bash.js')
-}
-
-t.test('posix', (t) => {
- mockGlobal(t, { 'process.platform': 'posix' })
- t.equal(isWindowsBash(), false, 'false when not windows')
-
- t.end()
-})
-
-t.test('win32', (t) => {
- mockGlobal(t, { 'process.platform': 'win32' })
-
- mockGlobal(t, { 'process.env': { TERM: 'dumb', MSYSTEM: undefined } })
- t.equal(isWindowsBash(), false, 'false when not mingw or cygwin')
-
- mockGlobal(t, { 'process.env.TERM': 'cygwin' })
- t.equal(isWindowsBash(), true, 'true when cygwin')
-
- mockGlobal(t, { 'process.env': { TERM: 'dumb', MSYSTEM: 'MINGW64' } })
- t.equal(isWindowsBash(), true, 'true when mingw')
-
- t.end()
-})
diff --git a/test/lib/utils/is-windows-shell.js b/test/lib/utils/is-windows-shell.js
deleted file mode 100644
index 95519925c..000000000
--- a/test/lib/utils/is-windows-shell.js
+++ /dev/null
@@ -1,8 +0,0 @@
-const t = require('tap')
-Object.defineProperty(process, 'platform', {
- value: 'win32',
-})
-const isWindows = require('../../../lib/utils/is-windows.js')
-const isWindowsBash = require('../../../lib/utils/is-windows-bash.js')
-const isWindowsShell = require('../../../lib/utils/is-windows-shell.js')
-t.equal(isWindowsShell, isWindows && !isWindowsBash)
diff --git a/test/lib/utils/is-windows.js b/test/lib/utils/is-windows.js
index f8f2999c9..a1d520f06 100644
--- a/test/lib/utils/is-windows.js
+++ b/test/lib/utils/is-windows.js
@@ -1,8 +1,39 @@
const t = require('tap')
-const actuallyWindows = process.platform === 'win32'
-t.equal(actuallyWindows, require('../../../lib/utils/is-windows.js'))
-Object.defineProperty(process, 'platform', {
- value: actuallyWindows ? 'posix' : 'win32',
+
+const mockGlobals = require('../../fixtures/mock-globals')
+
+t.test('is not windows', async t => {
+ mockGlobals(t, { 'process.platform': 'posix' })
+ t.match({
+ isWindows: false,
+ isWindowsShell: false,
+ }, t.mock('../../../lib/utils/is-windows.js'))
+})
+
+t.test('is windows, shell', async t => {
+ mockGlobals(t, {
+ 'process.platform': 'win32',
+ 'process.env': {
+ MSYSTEM: 'notmingw',
+ TERM: 'notcygwin',
+ },
+ })
+ t.match({
+ isWindows: true,
+ isWindowsShell: true,
+ }, t.mock('../../../lib/utils/is-windows.js'))
+})
+
+t.test('is windows, not shell', async t => {
+ mockGlobals(t, {
+ 'process.platform': 'win32',
+ 'process.env': {
+ MSYSTEM: 'MINGW32',
+ TERM: 'cygwin',
+ },
+ })
+ t.match({
+ isWindows: true,
+ isWindowsShell: false,
+ }, t.mock('../../../lib/utils/is-windows.js'))
})
-delete require.cache[require.resolve('../../../lib/utils/is-windows.js')]
-t.equal(!actuallyWindows, require('../../../lib/utils/is-windows.js'))
diff --git a/test/lib/utils/path.js b/test/lib/utils/path.js
index 0a7846d94..b3bb269f3 100644
--- a/test/lib/utils/path.js
+++ b/test/lib/utils/path.js
@@ -1,6 +1,7 @@
const t = require('tap')
const mod = '../../../lib/utils/path.js'
-const delim = require('../../../lib/utils/is-windows.js') ? ';' : ':'
+const { isWindows } = require('../../../lib/utils/is-windows.js')
+const delim = isWindows ? ';' : ':'
Object.defineProperty(process, 'env', {
value: {},
})