Skip to content

Commit bec8272

Browse files
committed
tests: parallel tests
Several changes to the test suite to support running tests in parallel, bringing the overall test time down considerably. - Replace all literal 1337 and 1234 ports with a custom per-process port assignment based on the TAP_CHILD_ID environment variable. - Add common.pkg as a per-test working directory instead of polluting __dirname or accidentally reusing the same working directory for multiple tests. - Rework test config handling so that tests don't rely on config setup being run in a particular order. - Remove the npm-registry-couchapp tests, since it (a) relies on CouchDB, (b) is no longer a reliable indicator of registry compatibility, and (c) is already superceded in most cases by tests that use npm-registry-mock. (A test suite that runs against a reference implementation is a thing that should exist, but not here.) - Remove the fake-registry logging when TAP_CHILD_ID is set, since this is extremely hard to make sense of when running multiple tests in parallel. When Node v6 compatibility is dropped in npm v7, we can upgrade to the latest version of tap for a bit more speed, dropping Domains (and the associated deprecation warnings), and a fancier test reporter.
1 parent d4a76a2 commit bec8272

File tree

266 files changed

+553
-440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

266 files changed

+553
-440
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ npm-debug.log
2121
.jshintrc
2222
.eslintrc
2323
.nyc_output
24+
/test/npm_cache*
25+
/node_modules/.cache

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "6.9.1-next.0",
2+
"version": "6.9.0",
33
"name": "npm",
44
"description": "a package manager for JavaScript",
55
"keywords": [
@@ -108,7 +108,7 @@
108108
"path-is-inside": "~1.0.2",
109109
"promise-inflight": "~1.0.1",
110110
"qrcode-terminal": "^0.12.0",
111-
"query-string": "^6.4.0",
111+
"query-string": "^6.2.0",
112112
"qw": "~1.0.1",
113113
"read": "~1.0.7",
114114
"read-cmd-shim": "~1.0.1",
@@ -121,7 +121,7 @@
121121
"rimraf": "^2.6.3",
122122
"safe-buffer": "^5.1.2",
123123
"semver": "^5.6.0",
124-
"sha": "^3.0.0",
124+
"sha": "~2.0.1",
125125
"slide": "~1.1.6",
126126
"sorted-object": "~2.0.1",
127127
"sorted-union-stream": "~2.1.3",
@@ -276,17 +276,17 @@
276276
"require-inject": "^1.4.4",
277277
"sprintf-js": "^1.1.2",
278278
"standard": "^11.0.1",
279-
"tacks": "^1.3.0",
280-
"tap": "^12.7.0",
281-
"tar-stream": "^2.0.1"
279+
"tacks": "^1.2.7",
280+
"tap": "~12.7.0",
281+
"tar-stream": "^2.0.0"
282282
},
283283
"scripts": {
284284
"dumpconf": "env | grep npm | sort | uniq",
285285
"prepare": "node bin/npm-cli.js rebuild && node bin/npm-cli.js --no-audit --no-timing prune --prefix=. --no-global && rimraf test/*/*/node_modules && make -j4 doc",
286286
"preversion": "bash scripts/update-authors.sh && git add AUTHORS && git commit -m \"update AUTHORS\" || true",
287287
"licenses": "licensee --production --errors-only",
288-
"tap": "tap --reporter=classic --timeout 300",
289-
"tap-cover": "tap --reporter=classic --nyc-arg='--cache' --coverage --timeout 600",
288+
"tap": "tap -J --timeout 300",
289+
"tap-cover": "tap -J --nyc-arg=--cache --coverage --timeout 600",
290290
"test": "standard && npm run test-tap",
291291
"test-coverage": "npm run tap-cover -- \"test/tap/*.js\" \"test/network/*.js\" \"test/broken-under-*/*.js\"",
292292
"test-tap": "npm run tap -- \"test/tap/*.js\" \"test/network/*.js\" \"test/broken-under-*/*.js\"",

test/common-config.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
if (module === require.main) {
2+
console.log('1..1')
3+
console.log('ok 1 setup done')
4+
process.exit(0)
5+
}
6+
7+
var fs = require('graceful-fs')
8+
var path = require('path')
9+
var userconfigSrc = path.resolve(__dirname, 'fixtures', 'config', 'userconfig')
10+
exports.userconfig = userconfigSrc + '-with-gc'
11+
exports.globalconfig = path.resolve(__dirname, 'fixtures', 'config', 'globalconfig')
12+
13+
// if this hasn't been written yet, then do it now.
14+
try {
15+
fs.statSync(exports.userconfig)
16+
} catch (er) {
17+
var uc = fs.readFileSync(userconfigSrc)
18+
var gcini = 'globalconfig = ' + exports.globalconfig + '\n'
19+
// atomic!
20+
fs.writeFileSync(exports.userconfig + '.' + process.pid, gcini + uc)
21+
fs.renameSync(exports.userconfig + '.' + process.pid, exports.userconfig)
22+
}
23+
24+
exports.builtin = path.resolve(__dirname, 'fixtures', 'config', 'builtin')
25+
exports.malformed = path.resolve(__dirname, 'fixtures', 'config', 'malformed')
26+
exports.ucData =
27+
{ globalconfig: exports.globalconfig,
28+
email: 'i@izs.me',
29+
'env-thing': 'asdf',
30+
'init.author.name': 'Isaac Z. Schlueter',
31+
'init.author.email': 'i@izs.me',
32+
'init.author.url': 'http://blog.izs.me/',
33+
'init.version': '1.2.3',
34+
'npm:publishtest': true,
35+
'_npmjs.org:couch': 'https://admin:password@localhost:5984/registry',
36+
'npm-www:nocache': '1',
37+
nodedir: '/Users/isaacs/dev/js/node-v0.8',
38+
'sign-git-tag': true,
39+
message: 'v%s',
40+
'strict-ssl': false,
41+
'tmp': path.normalize(process.env.HOME + '/.tmp'),
42+
_auth: 'dXNlcm5hbWU6cGFzc3dvcmQ=',
43+
_token:
44+
{ AuthSession: 'yabba-dabba-doodle',
45+
version: '1',
46+
expires: '1345001053415',
47+
path: '/',
48+
httponly: true } }
49+
50+
// set the userconfig in the env
51+
// unset anything else that npm might be trying to foist on us
52+
Object.keys(process.env).forEach(function (k) {
53+
if (k.match(/^npm_config_/i)) {
54+
delete process.env[k]
55+
}
56+
})
57+
process.env.npm_config_userconfig = exports.userconfig
58+
process.env.npm_config_other_env_thing = '1000'
59+
process.env.random_env_var = 'asdf'
60+
process.env.npm_config__underbar_env_thing = 'underful'
61+
process.env.NPM_CONFIG_UPPERCASE_ENV_THING = '42'
62+
63+
exports.envData = {
64+
userconfig: exports.userconfig,
65+
'_underbar-env-thing': 'underful',
66+
'uppercase-env-thing': '42',
67+
'other-env-thing': '1000'
68+
}
69+
exports.envDataFix = {
70+
userconfig: exports.userconfig,
71+
'_underbar-env-thing': 'underful',
72+
'uppercase-env-thing': 42,
73+
'other-env-thing': 1000
74+
}
75+
76+
var projectConf = path.resolve(__dirname, '..', '.npmrc')
77+
try {
78+
fs.statSync(projectConf)
79+
} catch (er) {
80+
// project conf not found, probably working with packed npm
81+
fs.writeFileSync(projectConf, '')
82+
}
83+
84+
var projectRc = path.join(__dirname, 'fixtures', 'config', '.npmrc')
85+
try {
86+
fs.statSync(projectRc)
87+
} catch (er) {
88+
// project conf not found, probably working with packed npm
89+
fs.writeFileSync(projectRc, 'just = testing')
90+
}

test/common-tap.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22
/* eslint-disable camelcase */
33

4+
const configCommon = require('./common-config.js')
45
var fs = require('graceful-fs')
56
var readCmdShim = require('read-cmd-shim')
67
var isWindows = require('../lib/utils/is-windows.js')
@@ -17,9 +18,32 @@ if (!global.setImmediate || !require('timers').setImmediate) {
1718
var spawn = require('child_process').spawn
1819
var path = require('path')
1920

20-
var port = exports.port = 1337
21+
// provide a working dir unique to each test
22+
const main = require.main.filename
23+
exports.pkg = path.resolve(path.dirname(main), path.basename(main, '.js'))
24+
const mkdirp = require('mkdirp')
25+
const rimraf = require('rimraf')
26+
mkdirp.sync(exports.pkg)
27+
require('tap').teardown(() => {
28+
try {
29+
rimraf.sync(exports.pkg)
30+
} catch (e) {
31+
if (process.platform !== 'win32') {
32+
throw e
33+
}
34+
}
35+
})
36+
37+
// space these out to help prevent collisions
38+
const testId = 3 * (+process.env.TAP_CHILD_ID || 0)
39+
40+
var port = exports.port = 15443 + testId
2141
exports.registry = 'http://localhost:' + port
2242

43+
exports.altPort = 7331 + testId
44+
45+
exports.gitPort = 4321 + testId
46+
2347
var fakeRegistry = require('./fake-registry.js')
2448
exports.fakeRegistry = fakeRegistry
2549

@@ -29,10 +53,10 @@ ourenv.npm_config_progress = 'false'
2953
ourenv.npm_config_metrics = 'false'
3054
ourenv.npm_config_audit = 'false'
3155

32-
var npm_config_cache = path.resolve(__dirname, 'npm_cache')
56+
var npm_config_cache = path.resolve(__dirname, 'npm_cache_' + testId)
3357
ourenv.npm_config_cache = exports.npm_config_cache = npm_config_cache
34-
ourenv.npm_config_userconfig = exports.npm_config_userconfig = path.join(__dirname, 'fixtures', 'config', 'userconfig')
35-
ourenv.npm_config_globalconfig = exports.npm_config_globalconfig = path.join(__dirname, 'fixtures', 'config', 'globalconfig')
58+
ourenv.npm_config_userconfig = exports.npm_config_userconfig = configCommon.userconfig
59+
ourenv.npm_config_globalconfig = exports.npm_config_globalconfig = configCommon.globalconfig
3660
ourenv.npm_config_global_style = 'false'
3761
ourenv.npm_config_legacy_bundling = 'false'
3862
ourenv.npm_config_fetch_retries = '0'

test/fake-registry.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
'use strict'
22
const common = require('./common-tap.js')
33
const Bluebird = require('bluebird')
4-
const log = require('npmlog')
4+
const silentLogger = {
5+
http: () => {},
6+
silly: () => {}
7+
}
8+
9+
const log = process.env.TAP_CHILD_ID
10+
? silentLogger
11+
: require('npmlog')
512

613
const http = require('http')
714
const EventEmitter = require('events')

test/need-npm5-update/ignore-shrinkwrap.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var json = {
2424
name: 'ignore-shrinkwrap',
2525
version: '0.0.0',
2626
dependencies: {
27-
'npm-test-ignore-shrinkwrap-file': 'http://localhost:1337/package.js'
27+
'npm-test-ignore-shrinkwrap-file': 'http://localhost:' + common.port + '/package.js'
2828
}
2929
}
3030

@@ -34,8 +34,8 @@ var shrinkwrap = {
3434
dependencies: {
3535
'npm-test-ignore-shrinkwrap-file': {
3636
version: '1.2.3',
37-
from: 'http://localhost:1337/shrinkwrap.js',
38-
resolved: 'http://localhost:1337/shrinkwrap.js',
37+
from: 'http://localhost:' + common.port + '/shrinkwrap.js',
38+
resolved: 'http://localhost:' + common.port + '/shrinkwrap.js',
3939
dependencies: {
4040
opener: {
4141
version: '1.3.0',

test/need-npm5-update/peer-deps-invalid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ var json = {
1818
name: 'peer-deps-invalid',
1919
version: '0.0.0',
2020
dependencies: {
21-
'npm-test-peer-deps-file': 'http://localhost:1337/ok.js',
22-
'npm-test-peer-deps-file-invalid': 'http://localhost:1337/invalid.js'
21+
'npm-test-peer-deps-file': 'http://localhost:' + common.port + '/ok.js',
22+
'npm-test-peer-deps-file-invalid': 'http://localhost:' + common.port + '/invalid.js'
2323
}
2424
}
2525

test/tap/404-parent.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var path = require('path')
66
var fs = require('fs')
77
var rimraf = require('rimraf')
88
var mkdirp = require('mkdirp')
9-
var pkg = path.resolve(__dirname, '404-parent')
9+
const pkg = common.pkg
1010
var mr = require('npm-registry-mock')
1111

1212
test('404-parent: if parent exists, specify parent in error message', function (t) {
@@ -42,6 +42,9 @@ function setup () {
4242

4343
function performInstall (cb) {
4444
mr({port: common.port}, function (er, s) { // create mock registry.
45+
if (er) {
46+
return cb(er)
47+
}
4548
s.get('/test-npm-404-parent-test')
4649
.many().reply(404, {'error': 'version not found'})
4750
npm.load({

test/tap/404-private-registry-scoped.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
var test = require('tap').test
2-
var path = require('path')
32
var mkdirp = require('mkdirp')
43
var rimraf = require('rimraf')
54
var common = require('../common-tap.js')
65
var mr = common.fakeRegistry.compat
76
var server
87

9-
var testdir = path.join(__dirname, path.basename(__filename, '.js'))
8+
var testdir = common.pkg
109

1110
function setup () {
1211
cleanup()

test/tap/404-private-registry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var mr = common.fakeRegistry.compat
77
var server
88

99
var packageName = path.basename(__filename, '.js')
10-
var testdir = path.join(__dirname, packageName)
10+
var testdir = common.pkg
1111

1212
function setup () {
1313
cleanup()

0 commit comments

Comments
 (0)