From 291aba7b821e247b96240b1ec037310ead69a594 Mon Sep 17 00:00:00 2001 From: isaacs Date: Wed, 21 Aug 2019 16:29:00 -0700 Subject: [PATCH] test: make tests pass on Windows --- test/common-tap.js | 8 +++++++- test/tap/aliases.js | 6 +++--- test/tap/anon-cli-metrics.js | 2 +- test/tap/correct-mkdir.js | 8 +++++++- test/tap/ignore-install-link.js | 2 +- test/tap/install-link-scripts.js | 4 ++++ test/tap/lifecycle-INIT_CWD.js | 2 +- test/tap/ls-l-depth-0.js | 8 +++++--- test/tap/outdated-long.js | 1 + test/tap/prepublish-only.js | 7 ------- test/tap/prune.js | 2 +- test/tap/shared-linked.js | 2 +- test/tap/shrinkwrap-lifecycle-cwd.js | 5 ++--- test/tap/shrinkwrap-save-with-existing-dev-deps.js | 8 +++++++- test/tap/whoami.js | 2 +- 15 files changed, 42 insertions(+), 25 deletions(-) diff --git a/test/common-tap.js b/test/common-tap.js index 44b68d719de1a..83a61f4bdbefa 100644 --- a/test/common-tap.js +++ b/test/common-tap.js @@ -7,6 +7,11 @@ var readCmdShim = require('read-cmd-shim') var isWindows = require('../lib/utils/is-windows.js') var Bluebird = require('bluebird') +if (isWindows) { + var PATH = process.env.PATH ? 'PATH' : 'Path' + process.env[PATH] += ';C:\\Program Files\\Git\\mingw64\\libexec\\git-core' +} + // remove any git envs so that we don't mess with the main repo // when running git subprocesses in tests Object.keys(process.env).filter(k => /^GIT/.test(k)).forEach( @@ -103,6 +108,7 @@ ourenv.npm_config_globalconfig = exports.npm_config_globalconfig = configCommon. ourenv.npm_config_global_style = 'false' ourenv.npm_config_legacy_bundling = 'false' ourenv.npm_config_fetch_retries = '0' +ourenv.npm_config_update_notifier = 'false' ourenv.random_env_var = 'foo' // suppress warnings about using a prerelease version of node ourenv.npm_config_node_version = process.version.replace(/-.*$/, '') @@ -179,7 +185,7 @@ exports.makeGitRepo = function (params, cb) { var added = params.added || ['package.json'] var message = params.message || 'stub repo' - var opts = { cwd: root, env: { PATH: process.env.PATH } } + var opts = { cwd: root, env: { PATH: process.env.PATH || process.env.Path } } var commands = [ git.chainableExec(['init'], opts), git.chainableExec(['config', 'user.name', user], opts), diff --git a/test/tap/aliases.js b/test/tap/aliases.js index 0a0a9dfd953b1..21a68ac50f7a5 100644 --- a/test/tap/aliases.js +++ b/test/tap/aliases.js @@ -116,18 +116,18 @@ test('installs an npm: protocol alias package', t => { t.comment(stdout) t.comment(stderr) const parsed = JSON.parse(stdout) - t.deepEqual(parsed, { + t.match(parsed, { foo: { current: '1.2.3', wanted: '1.2.4', latest: '1.2.4', - location: 'node_modules/foo' + location: /node_modules[/\\]foo/ }, bar: { current: 'npm:foo@1.2.3', wanted: 'npm:foo@1.2.4', latest: 'npm:foo@1.2.4', - location: 'node_modules/bar' + location: /node_modules[/\\]bar/ } }, 'both regular and aliased dependency reported') return common.npm([ diff --git a/test/tap/anon-cli-metrics.js b/test/tap/anon-cli-metrics.js index cb1f878a4cb0a..729d9e607a4a0 100644 --- a/test/tap/anon-cli-metrics.js +++ b/test/tap/anon-cli-metrics.js @@ -54,7 +54,7 @@ var fixture = new Tacks(Dir({ name: 'slow', version: '1.0.0', scripts: { - preinstall: "node -e 'setTimeout(function(){}, 500)'" + preinstall: 'node -e "setTimeout(function(){}, 500)"' } }) }), diff --git a/test/tap/correct-mkdir.js b/test/tap/correct-mkdir.js index 5c2e9771dfc08..30907d725ca08 100644 --- a/test/tap/correct-mkdir.js +++ b/test/tap/correct-mkdir.js @@ -1,10 +1,16 @@ /* eslint-disable camelcase */ -var test = require('tap').test +var t = require('tap') +var test = t.test var assert = require('assert') var requireInject = require('require-inject') const common = require('../common-tap.js') var cache_dir = common.pkg +if (process.platform === 'win32') { + t.plan(0, 'windows does not use correct-mkdir behavior') + process.exit(0) +} + test('correct-mkdir: no race conditions', function (t) { var mock_fs = {} var did_hook = false diff --git a/test/tap/ignore-install-link.js b/test/tap/ignore-install-link.js index 7b3b1be3b9d5e..a2caa23dfdb56 100644 --- a/test/tap/ignore-install-link.js +++ b/test/tap/ignore-install-link.js @@ -1,5 +1,5 @@ if (process.platform === 'win32') { - console.log('ok - symlinks are weird on windows, skip this test') + require('tap').plan(0, 'symlinks are weird on windows, skip this test') process.exit(0) } var common = require('../common-tap.js') diff --git a/test/tap/install-link-scripts.js b/test/tap/install-link-scripts.js index bff4dd5ef0106..3553e6377370a 100644 --- a/test/tap/install-link-scripts.js +++ b/test/tap/install-link-scripts.js @@ -1,3 +1,7 @@ +if (process.platform === 'win32') { + require('tap').plan(0, 'links are weird on windows, skip this') + process.exit(0) +} var fs = require('graceful-fs') var path = require('path') diff --git a/test/tap/lifecycle-INIT_CWD.js b/test/tap/lifecycle-INIT_CWD.js index e035cf86d4033..3e9c1c8257f46 100644 --- a/test/tap/lifecycle-INIT_CWD.js +++ b/test/tap/lifecycle-INIT_CWD.js @@ -15,7 +15,7 @@ var json = { name: 'init-cwd', version: '1.0.0', scripts: { - initcwd: 'echo "$INIT_CWD"' + initcwd: process.platform === 'win32' ? 'echo %INIT_CWD%' : 'echo "$INIT_CWD"' } } diff --git a/test/tap/ls-l-depth-0.js b/test/tap/ls-l-depth-0.js index 8459bd52032cb..b2516c9fa2449 100644 --- a/test/tap/ls-l-depth-0.js +++ b/test/tap/ls-l-depth-0.js @@ -67,10 +67,12 @@ test('#6311: npm ll --depth=0 duplicates listing', function (t) { if (err) throw err t.notOk(code, 'npm install exited cleanly') t.is(stderr, '', 'npm install ran silently') - t.equal( + t.match( stdout.trim(), - 'add\tunderscore\t1.5.1\tnode_modules/underscore\t\t\n' + - 'add\tglock\t1.8.7\tnode_modules/glock', + new RegExp( + '^add\tunderscore\t1[.]5[.]1\tnode_modules[\\\\/]underscore\t\t[\n]' + + 'add\tglock\t1[.]8[.]7\tnode_modules[\\\\/]glock$' + ), 'got expected install output' ) diff --git a/test/tap/outdated-long.js b/test/tap/outdated-long.js index 0a338815983eb..8cd2ceadb96fc 100644 --- a/test/tap/outdated-long.js +++ b/test/tap/outdated-long.js @@ -79,6 +79,7 @@ test('it should not throw', function (t) { t.is(process.exitCode, 1, 'exit code set to 1') process.exitCode = 0 console.log = originalLog + output[0] = output[0].replace(/\\/g, '/') t.same(output, expOut) t.same(d, expData) diff --git a/test/tap/prepublish-only.js b/test/tap/prepublish-only.js index 57af26038a7bd..56881494d2381 100644 --- a/test/tap/prepublish-only.js +++ b/test/tap/prepublish-only.js @@ -17,7 +17,6 @@ var tmpdir = join(pkg, 'tmp') var env = { 'npm_config_cache': cachedir, 'npm_config_tmp': tmpdir, - 'npm_config_prefix': pkg, 'npm_config_global': 'false' } @@ -64,7 +63,6 @@ var fixture = new Tacks(Dir({ })) test('setup', function (t) { - cleanup() fixture.create(pkg) mr({port: common.port, throwOnUnmatched: true}, function (err, s) { t.ifError(err, 'registry mocked successfully') @@ -131,12 +129,7 @@ test('test', function (t) { }) test('cleanup', function (t) { - cleanup() server.close() t.pass('cleaned up') t.end() }) - -function cleanup () { - fixture.remove(pkg) -} diff --git a/test/tap/prune.js b/test/tap/prune.js index 936ee3a91b6b8..ce2a300b1a537 100644 --- a/test/tap/prune.js +++ b/test/tap/prune.js @@ -104,7 +104,7 @@ test('production: npm prune', function (t) { ], EXEC_OPTS, function (err, code, stdout) { if (err) throw err t.notOk(code, 'exit ok') - t.equal(stdout.trim(), 'remove\tmkdirp\t0.3.5\tnode_modules/mkdirp') + t.equal(stdout.trim().replace(/\\/g, '/'), 'remove\tmkdirp\t0.3.5\tnode_modules/mkdirp') t.end() }) }) diff --git a/test/tap/shared-linked.js b/test/tap/shared-linked.js index cbdbcf66c1612..517be4699d973 100644 --- a/test/tap/shared-linked.js +++ b/test/tap/shared-linked.js @@ -133,7 +133,7 @@ test('shared-linked', function (t) { common.npm(config.concat(['install', '--dry-run', '--parseable']), options, function (err, code, stdout, stderr) { if (err) throw err t.is(code, 0) - var got = stdout.trim().replace(/\s+\n/g, '\n') + var got = stdout.trim().replace(/\s+\n/g, '\n').replace(/\\/g, '/') var expected = 'add\tminimist\t0.0.5\tnode_modules/minimist\n' + 'add\twordwrap\t0.0.2\tnode_modules/wordwrap\n' + diff --git a/test/tap/shrinkwrap-lifecycle-cwd.js b/test/tap/shrinkwrap-lifecycle-cwd.js index f8927df5a2969..78f40f5297628 100644 --- a/test/tap/shrinkwrap-lifecycle-cwd.js +++ b/test/tap/shrinkwrap-lifecycle-cwd.js @@ -12,7 +12,6 @@ var testdir = path.join(basedir, 'testdir') var cachedir = common.cache var globaldir = path.join(basedir, 'global') var tmpdir = path.join(basedir, 'tmp') -var escapeArg = require('../../lib/utils/escape-arg.js') var conf = { cwd: testdir, @@ -39,8 +38,8 @@ var fixture = new Tacks(Dir({ // add this to the end of the command to preserve the debug log: // || mv npm-debug.log real-debug.log // removed for windows compat reasons - abc: escapeArg(common.nodeBin) + ' ' + escapeArg(common.bin) + ' shrinkwrap', - shrinkwrap: escapeArg(common.nodeBin) + ' scripts/shrinkwrap.js' + abc: 'node ' + JSON.stringify(common.bin) + ' shrinkwrap', + shrinkwrap: 'node scripts/shrinkwrap.js' } }), scripts: Dir({ diff --git a/test/tap/shrinkwrap-save-with-existing-dev-deps.js b/test/tap/shrinkwrap-save-with-existing-dev-deps.js index fcbbeeffddf4d..8a3f449fa8865 100644 --- a/test/tap/shrinkwrap-save-with-existing-dev-deps.js +++ b/test/tap/shrinkwrap-save-with-existing-dev-deps.js @@ -18,7 +18,13 @@ var example_pkg = path.join(example, 'package.json') var installed = path.join(example, 'node_modules', 'installed') var installed_pkg = path.join(installed, 'package.json') -var EXEC_OPTS = { cwd: example } +// Ignore max listeners warnings until that gets fixed +var env = Object.keys(process.env).reduce((set, key) => { + if (!set[key]) set[key] = process.env[key] + return set +}, { NODE_NO_WARNINGS: '1' }) + +var EXEC_OPTS = { cwd: example, env: env } var installme_pkg_json = { name: 'installme', diff --git a/test/tap/whoami.js b/test/tap/whoami.js index 4e4b3da282ade..9f4bf4266b74c 100644 --- a/test/tap/whoami.js +++ b/test/tap/whoami.js @@ -36,7 +36,7 @@ test('npm whoami with basic auth', function (t) { ) }) -test('npm whoami with bearer auth', { timeout: 2 * 1000 }, function (t) { +test('npm whoami with bearer auth', { timeout: 6000 }, function (t) { var s = '//localhost:' + common.port + '/:_authToken = wombat-developers-union\n' fs.writeFileSync(FIXTURE_PATH, s, 'ascii')