diff options
author | isaacs <i@izs.me> | 2014-09-13 22:07:30 +0400 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2017-01-25 01:09:06 +0300 |
commit | 04fca223a0f704b69340c5f81b26907238fad878 (patch) | |
tree | e0360515dc452ba52160cf158b56c36ab875d969 /test | |
parent | 98df212a91fd6ff4a02b9cd247f4166f93d3977a (diff) |
npm: Put the npm-debug logs in the cache folder, not cwd.
We also are storing a configurable number of previous log files.
PR-URL: https://github.com/npm/npm/pull/11439
Fixes: #5252
Fixes: #6350
Fixes: #1548
Fixes: #7614
Credit: @KenanY
Credit: @othiym23
Credit: @isaacs
Credit: @iarna
Diffstat (limited to 'test')
-rw-r--r-- | test/tap/debug-logs.js | 102 | ||||
-rw-r--r-- | test/tap/gently-rm-overeager.js | 13 |
2 files changed, 108 insertions, 7 deletions
diff --git a/test/tap/debug-logs.js b/test/tap/debug-logs.js new file mode 100644 index 000000000..852ac90a9 --- /dev/null +++ b/test/tap/debug-logs.js @@ -0,0 +1,102 @@ +'use strict' +var path = require('path') +var test = require('tap').test +var Tacks = require('tacks') +var glob = require('glob') +var asyncMap = require('slide').asyncMap +var File = Tacks.File +var Dir = Tacks.Dir +var extend = Object.assign || require('util')._extend +var common = require('../common-tap.js') + +var basedir = path.join(__dirname, path.basename(__filename, '.js')) +var testdir = path.join(basedir, 'testdir') +var cachedir = path.join(basedir, 'cache') +var globaldir = path.join(basedir, 'global') +var tmpdir = path.join(basedir, 'tmp') + +var conf = { + cwd: testdir, + env: extend(extend({}, process.env), { + npm_config_cache: cachedir, + npm_config_tmp: tmpdir, + npm_config_prefix: globaldir, + npm_config_registry: common.registry, + npm_config_loglevel: 'warn' + }) +} + +var fixture = new Tacks(Dir({ + cache: Dir(), + global: Dir(), + tmp: Dir(), + testdir: Dir({ + 'package.json': File({ + name: 'debug-logs', + version: '1.0.0', + scripts: { + true: 'node -e "process.exit(0)"', + false: 'node -e "process.exit(1)"' + } + }) + }) +})) + +function setup () { + cleanup() + fixture.create(basedir) +} + +function cleanup () { + fixture.remove(basedir) +} + +test('setup', function (t) { + setup() + t.done() +}) + +test('example', function (t) { + common.npm(['run', 'false'], conf, function (err, code, stdout, stderr) { + if (err) throw err + t.is(code, 1, 'command errored') + var matches = stderr.match(/Please include the following file with any support request:.*\nnpm ERR! {5,5}(.*)/) + t.ok(matches, 'debug log mentioned in error message') + if (matches) { + var logfile = matches[1] + t.matches(path.relative(cachedir, logfile), /^_logs/, 'debug log is inside the cache in _logs') + } + + // we run a bunch concurrently, this will actually create > than our limit as the check is done + // when the command starts + var todo = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] + asyncMap(todo, function (num, next) { + common.npm(['run', '--logs-max=10', 'false'], conf, function (err, code) { + if (err) throw err + t.is(code, 1, 'run #' + num + ' errored as expected') + next() + }) + }, function () { + // now we do one more and that should clean up the list + common.npm(['run', '--logs-max=10', 'false'], conf, function (err, code) { + if (err) throw err + t.is(code, 1, 'final run errored as expected') + var files = glob.sync(path.join(cachedir, '_logs', '*')) + t.is(files.length, 10, 'there should never be more than 10 log files') + common.npm(['run', '--logs-max=5', 'true'], conf, function (err, code) { + if (err) throw err + t.is(code, 0, 'success run is ok') + var files = glob.sync(path.join(cachedir, '_logs', '*')) + t.is(files.length, 4, 'after success there should be logs-max - 1 log files') + t.done() + }) + }) + }) + }) +}) + +test('cleanup', function (t) { + cleanup() + t.done() +}) + diff --git a/test/tap/gently-rm-overeager.js b/test/tap/gently-rm-overeager.js index c266f1c4d..08fa72bc7 100644 --- a/test/tap/gently-rm-overeager.js +++ b/test/tap/gently-rm-overeager.js @@ -1,4 +1,4 @@ -var resolve = require('path').resolve +var path = require('path') var fs = require('graceful-fs') var test = require('tap').test var mkdirp = require('mkdirp') @@ -6,8 +6,8 @@ var rimraf = require('rimraf') var common = require('../common-tap.js') -var pkg = resolve(__dirname, 'gently-rm-overeager') -var dep = resolve(__dirname, 'test-whoops') +var pkg = path.join(__dirname, 'gently-rm-overeager') +var dep = path.join(__dirname, 'test-whoops') var EXEC_OPTS = { cwd: pkg } @@ -32,8 +32,7 @@ test('cache add', function (t) { t.ok(c, 'test-whoops install also failed') fs.readdir(pkg, function (er, files) { t.ifError(er, 'package directory is still there') - t.deepEqual(files, ['npm-debug.log'], 'only debug log remains') - + t.deepEqual(files, [], 'no files remain') t.end() }) }) @@ -53,7 +52,7 @@ function cleanup () { function setup () { mkdirp.sync(pkg) // so it doesn't try to install into npm's own node_modules - mkdirp.sync(resolve(pkg, 'node_modules')) + mkdirp.sync(path.join(pkg, 'node_modules')) mkdirp.sync(dep) - fs.writeFileSync(resolve(dep, 'package.json'), JSON.stringify(fixture)) + fs.writeFileSync(path.join(dep, 'package.json'), JSON.stringify(fixture)) } |