Skip to content

Commit

Permalink
tests: pass tests on Windows without Admin privs
Browse files Browse the repository at this point in the history
1. Skip testing Cygwin bash shim when coverage is enabled, since this
   doesn't work, and probably never will.
2. Create symbolic links to directories rather than files, so that
   Administrative privileges are not required.
  • Loading branch information
isaacs committed Mar 1, 2021
1 parent 1d44ac2 commit 03eb195
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
5 changes: 5 additions & 0 deletions test/bin/windows-shims.js
Expand Up @@ -85,6 +85,11 @@ for (const [name, bash] of bashes) {
continue
}

if (bash === cygwinBash && process.env.NYC_CONFIG) {
t.skip('Cygwin does not play nicely with NYC, run without coverage')
continue
}

t.test(name, async t => {
t.plan(2)
t.test('npm', async t => {
Expand Down
4 changes: 4 additions & 0 deletions test/coverage-map.js
Expand Up @@ -7,6 +7,10 @@ const coverageMap = (filename) => {
return glob.sync(`${dir}/**/*.js`)
.map(f => relative(process.cwd(), f))
}
if (/windows-shims\.js$/.test(filename)) {
// this one doesn't provide any coverage nyc can track
return []
}
if (/^test\/(lib|bin)\//.test(filename))
return filename.replace(/^test\//, '')
return []
Expand Down
2 changes: 1 addition & 1 deletion test/lib/doctor.js
Expand Up @@ -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: {},
},
Expand Down
13 changes: 5 additions & 8 deletions 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'
Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -294,7 +291,7 @@ t.test('npm.load', t => {
[
'verbose',
'node symlink',
resolve(dir, node),
resolve(dir, 'bin', node),
],
[
'timing',
Expand All @@ -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) => {
Expand Down

0 comments on commit 03eb195

Please sign in to comment.