From 03eb19508fa22e4c1cb48017abffa7e64761dff5 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 1 Mar 2021 14:32:49 -0800 Subject: [PATCH] tests: pass tests on Windows without Admin privs 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. --- test/bin/windows-shims.js | 5 +++++ test/coverage-map.js | 4 ++++ test/lib/doctor.js | 2 +- test/lib/npm.js | 13 +++++-------- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/test/bin/windows-shims.js b/test/bin/windows-shims.js index 500a5e3c2d25b..8d73e39f2c4d1 100644 --- a/test/bin/windows-shims.js +++ b/test/bin/windows-shims.js @@ -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 => { diff --git a/test/coverage-map.js b/test/coverage-map.js index f247c051f0a2d..63f2a608e0ee3 100644 --- a/test/coverage-map.js +++ b/test/coverage-map.js @@ -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 [] diff --git a/test/lib/doctor.js b/test/lib/doctor.js index f5e6fd062a331..48f95df755bff 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 9fd9888b97b75..18d49ba6776eb 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) => {