Skip to content

Commit

Permalink
test: make tests pass on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Aug 22, 2019
1 parent 6cc4cc6 commit 291aba7
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 25 deletions.
8 changes: 7 additions & 1 deletion test/common-tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(/-.*$/, '')
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions test/tap/aliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion test/tap/anon-cli-metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)"'
}
})
}),
Expand Down
8 changes: 7 additions & 1 deletion test/tap/correct-mkdir.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/tap/ignore-install-link.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
4 changes: 4 additions & 0 deletions test/tap/install-link-scripts.js
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
2 changes: 1 addition & 1 deletion test/tap/lifecycle-INIT_CWD.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"'
}
}

Expand Down
8 changes: 5 additions & 3 deletions test/tap/ls-l-depth-0.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)

Expand Down
1 change: 1 addition & 0 deletions test/tap/outdated-long.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 0 additions & 7 deletions test/tap/prepublish-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion test/tap/prune.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/tap/shared-linked.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' +
Expand Down
5 changes: 2 additions & 3 deletions test/tap/shrinkwrap-lifecycle-cwd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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({
Expand Down
8 changes: 7 additions & 1 deletion test/tap/shrinkwrap-save-with-existing-dev-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion test/tap/whoami.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 291aba7

Please sign in to comment.