1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
// if "npm rebuild" is run with bundled dependencies,
// message "already built" should not be error
var test = require('tap').test
var path = require('path')
var osenv = require('osenv')
var rimraf = require('rimraf')
var npmlog = require('npmlog')
var mkdirp = require('mkdirp')
var requireInject = require('require-inject')
var npm = require('../../lib/npm.js')
const common = require('../common-tap.js')
var PKG_DIR = common.pkg
var fakePkg = 'foo'
test('setup', function (t) {
cleanup()
t.end()
})
test("issue #6735 build 'already built' message", function (t) {
npm.load({ loglevel: 'warn' }, function () {
// capture log messages with level
var log = ''
npmlog.on('log', function (chunk) {
log += chunk.level + ' ' + chunk.message + '\n'
})
mkdirp.sync(fakePkg)
var folder = path.resolve(fakePkg)
var global = npm.config.get('global')
var build = requireInject('../../lib/build', {
})
t.test('pin previous behavior', function (t) {
build([fakePkg], global, false, false, function (err) {
t.ok(err, 'build failed as expected')
t.similar(err.message, /package.json/, 'missing package.json as expected')
t.notSimilar(log, /already built/, 'no already built message written')
t.end()
})
})
t.test('simulate rebuild of bundledDependency', function (t) {
log = ''
build._didBuild[folder] = true
build([fakePkg], global, false, false, function (err) {
t.ok(err, 'build failed as expected')
t.similar(err.message, /package.json/, 'missing package.json as expected')
t.similar(log, /already built/, 'already built message written')
t.notSimilar(log, /ERR! already built/, 'already built message written is not error')
t.similar(log, /info already built/, 'already built message written is info')
t.end()
})
})
t.end()
})
})
test('cleanup', function (t) {
cleanup()
t.end()
})
function cleanup () {
process.chdir(osenv.tmpdir())
rimraf.sync(PKG_DIR)
}
|