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