Skip to content

Commit 291aba7

Browse files
committed
test: make tests pass on Windows
1 parent 6cc4cc6 commit 291aba7

15 files changed

+42
-25
lines changed

test/common-tap.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ var readCmdShim = require('read-cmd-shim')
77
var isWindows = require('../lib/utils/is-windows.js')
88
var Bluebird = require('bluebird')
99

10+
if (isWindows) {
11+
var PATH = process.env.PATH ? 'PATH' : 'Path'
12+
process.env[PATH] += ';C:\\Program Files\\Git\\mingw64\\libexec\\git-core'
13+
}
14+
1015
// remove any git envs so that we don't mess with the main repo
1116
// when running git subprocesses in tests
1217
Object.keys(process.env).filter(k => /^GIT/.test(k)).forEach(
@@ -103,6 +108,7 @@ ourenv.npm_config_globalconfig = exports.npm_config_globalconfig = configCommon.
103108
ourenv.npm_config_global_style = 'false'
104109
ourenv.npm_config_legacy_bundling = 'false'
105110
ourenv.npm_config_fetch_retries = '0'
111+
ourenv.npm_config_update_notifier = 'false'
106112
ourenv.random_env_var = 'foo'
107113
// suppress warnings about using a prerelease version of node
108114
ourenv.npm_config_node_version = process.version.replace(/-.*$/, '')
@@ -179,7 +185,7 @@ exports.makeGitRepo = function (params, cb) {
179185
var added = params.added || ['package.json']
180186
var message = params.message || 'stub repo'
181187

182-
var opts = { cwd: root, env: { PATH: process.env.PATH } }
188+
var opts = { cwd: root, env: { PATH: process.env.PATH || process.env.Path } }
183189
var commands = [
184190
git.chainableExec(['init'], opts),
185191
git.chainableExec(['config', 'user.name', user], opts),

test/tap/aliases.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,18 @@ test('installs an npm: protocol alias package', t => {
116116
t.comment(stdout)
117117
t.comment(stderr)
118118
const parsed = JSON.parse(stdout)
119-
t.deepEqual(parsed, {
119+
t.match(parsed, {
120120
foo: {
121121
current: '1.2.3',
122122
wanted: '1.2.4',
123123
latest: '1.2.4',
124-
location: 'node_modules/foo'
124+
location: /node_modules[/\\]foo/
125125
},
126126
bar: {
127127
current: 'npm:foo@1.2.3',
128128
wanted: 'npm:foo@1.2.4',
129129
latest: 'npm:foo@1.2.4',
130-
location: 'node_modules/bar'
130+
location: /node_modules[/\\]bar/
131131
}
132132
}, 'both regular and aliased dependency reported')
133133
return common.npm([

test/tap/anon-cli-metrics.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var fixture = new Tacks(Dir({
5454
name: 'slow',
5555
version: '1.0.0',
5656
scripts: {
57-
preinstall: "node -e 'setTimeout(function(){}, 500)'"
57+
preinstall: 'node -e "setTimeout(function(){}, 500)"'
5858
}
5959
})
6060
}),

test/tap/correct-mkdir.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
/* eslint-disable camelcase */
2-
var test = require('tap').test
2+
var t = require('tap')
3+
var test = t.test
34
var assert = require('assert')
45
var requireInject = require('require-inject')
56
const common = require('../common-tap.js')
67
var cache_dir = common.pkg
78

9+
if (process.platform === 'win32') {
10+
t.plan(0, 'windows does not use correct-mkdir behavior')
11+
process.exit(0)
12+
}
13+
814
test('correct-mkdir: no race conditions', function (t) {
915
var mock_fs = {}
1016
var did_hook = false

test/tap/ignore-install-link.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if (process.platform === 'win32') {
2-
console.log('ok - symlinks are weird on windows, skip this test')
2+
require('tap').plan(0, 'symlinks are weird on windows, skip this test')
33
process.exit(0)
44
}
55
var common = require('../common-tap.js')

test/tap/install-link-scripts.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
if (process.platform === 'win32') {
2+
require('tap').plan(0, 'links are weird on windows, skip this')
3+
process.exit(0)
4+
}
15
var fs = require('graceful-fs')
26
var path = require('path')
37

test/tap/lifecycle-INIT_CWD.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var json = {
1515
name: 'init-cwd',
1616
version: '1.0.0',
1717
scripts: {
18-
initcwd: 'echo "$INIT_CWD"'
18+
initcwd: process.platform === 'win32' ? 'echo %INIT_CWD%' : 'echo "$INIT_CWD"'
1919
}
2020
}
2121

test/tap/ls-l-depth-0.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ test('#6311: npm ll --depth=0 duplicates listing', function (t) {
6767
if (err) throw err
6868
t.notOk(code, 'npm install exited cleanly')
6969
t.is(stderr, '', 'npm install ran silently')
70-
t.equal(
70+
t.match(
7171
stdout.trim(),
72-
'add\tunderscore\t1.5.1\tnode_modules/underscore\t\t\n' +
73-
'add\tglock\t1.8.7\tnode_modules/glock',
72+
new RegExp(
73+
'^add\tunderscore\t1[.]5[.]1\tnode_modules[\\\\/]underscore\t\t[\n]' +
74+
'add\tglock\t1[.]8[.]7\tnode_modules[\\\\/]glock$'
75+
),
7476
'got expected install output'
7577
)
7678

test/tap/outdated-long.js

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ test('it should not throw', function (t) {
7979
t.is(process.exitCode, 1, 'exit code set to 1')
8080
process.exitCode = 0
8181
console.log = originalLog
82+
output[0] = output[0].replace(/\\/g, '/')
8283
t.same(output, expOut)
8384
t.same(d, expData)
8485

test/tap/prepublish-only.js

-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ var tmpdir = join(pkg, 'tmp')
1717
var env = {
1818
'npm_config_cache': cachedir,
1919
'npm_config_tmp': tmpdir,
20-
'npm_config_prefix': pkg,
2120
'npm_config_global': 'false'
2221
}
2322

@@ -64,7 +63,6 @@ var fixture = new Tacks(Dir({
6463
}))
6564

6665
test('setup', function (t) {
67-
cleanup()
6866
fixture.create(pkg)
6967
mr({port: common.port, throwOnUnmatched: true}, function (err, s) {
7068
t.ifError(err, 'registry mocked successfully')
@@ -131,12 +129,7 @@ test('test', function (t) {
131129
})
132130

133131
test('cleanup', function (t) {
134-
cleanup()
135132
server.close()
136133
t.pass('cleaned up')
137134
t.end()
138135
})
139-
140-
function cleanup () {
141-
fixture.remove(pkg)
142-
}

test/tap/prune.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ test('production: npm prune', function (t) {
104104
], EXEC_OPTS, function (err, code, stdout) {
105105
if (err) throw err
106106
t.notOk(code, 'exit ok')
107-
t.equal(stdout.trim(), 'remove\tmkdirp\t0.3.5\tnode_modules/mkdirp')
107+
t.equal(stdout.trim().replace(/\\/g, '/'), 'remove\tmkdirp\t0.3.5\tnode_modules/mkdirp')
108108
t.end()
109109
})
110110
})

test/tap/shared-linked.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ test('shared-linked', function (t) {
133133
common.npm(config.concat(['install', '--dry-run', '--parseable']), options, function (err, code, stdout, stderr) {
134134
if (err) throw err
135135
t.is(code, 0)
136-
var got = stdout.trim().replace(/\s+\n/g, '\n')
136+
var got = stdout.trim().replace(/\s+\n/g, '\n').replace(/\\/g, '/')
137137
var expected =
138138
'add\tminimist\t0.0.5\tnode_modules/minimist\n' +
139139
'add\twordwrap\t0.0.2\tnode_modules/wordwrap\n' +

test/tap/shrinkwrap-lifecycle-cwd.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ var testdir = path.join(basedir, 'testdir')
1212
var cachedir = common.cache
1313
var globaldir = path.join(basedir, 'global')
1414
var tmpdir = path.join(basedir, 'tmp')
15-
var escapeArg = require('../../lib/utils/escape-arg.js')
1615

1716
var conf = {
1817
cwd: testdir,
@@ -39,8 +38,8 @@ var fixture = new Tacks(Dir({
3938
// add this to the end of the command to preserve the debug log:
4039
// || mv npm-debug.log real-debug.log
4140
// removed for windows compat reasons
42-
abc: escapeArg(common.nodeBin) + ' ' + escapeArg(common.bin) + ' shrinkwrap',
43-
shrinkwrap: escapeArg(common.nodeBin) + ' scripts/shrinkwrap.js'
41+
abc: 'node ' + JSON.stringify(common.bin) + ' shrinkwrap',
42+
shrinkwrap: 'node scripts/shrinkwrap.js'
4443
}
4544
}),
4645
scripts: Dir({

test/tap/shrinkwrap-save-with-existing-dev-deps.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ var example_pkg = path.join(example, 'package.json')
1818
var installed = path.join(example, 'node_modules', 'installed')
1919
var installed_pkg = path.join(installed, 'package.json')
2020

21-
var EXEC_OPTS = { cwd: example }
21+
// Ignore max listeners warnings until that gets fixed
22+
var env = Object.keys(process.env).reduce((set, key) => {
23+
if (!set[key]) set[key] = process.env[key]
24+
return set
25+
}, { NODE_NO_WARNINGS: '1' })
26+
27+
var EXEC_OPTS = { cwd: example, env: env }
2228

2329
var installme_pkg_json = {
2430
name: 'installme',

test/tap/whoami.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test('npm whoami with basic auth', function (t) {
3636
)
3737
})
3838

39-
test('npm whoami with bearer auth', { timeout: 2 * 1000 }, function (t) {
39+
test('npm whoami with bearer auth', { timeout: 6000 }, function (t) {
4040
var s = '//localhost:' + common.port +
4141
'/:_authToken = wombat-developers-union\n'
4242
fs.writeFileSync(FIXTURE_PATH, s, 'ascii')

0 commit comments

Comments
 (0)