• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var join = require('path').join
2var statSync = require('graceful-fs').statSync
3var writeFileSync = require('graceful-fs').writeFileSync
4
5var mr = require('npm-registry-mock')
6var rimraf = require('rimraf')
7var test = require('tap').test
8
9var common = require('../common-tap')
10
11var pkg = common.pkg
12var installed = join(pkg, 'node_modules', 'underscore', 'package.json')
13
14var json = {
15  name: 'npm-it-test',
16  dependencies: {
17    underscore: '1.5.1'
18  },
19  scripts: {
20    test: 'echo hax'
21  }
22}
23
24test('run up the mock registry', function (t) {
25  mr({ port: common.port }, function (err, s) {
26    if (err) throw err
27    t.parent.teardown(() => s.close())
28    t.end()
29  })
30})
31
32const check = args => t =>
33  common.npm(args.concat('--registry=' + common.registry), { cwd: pkg })
34    .then(([code, stdout, stderr]) => {
35      t.equal(code, 0, 'command ran without error')
36      t.ok(statSync(installed), 'package was installed')
37      t.equal(require(installed).version, '1.5.1', 'underscore got installed as expected')
38      t.match(stdout, /hax/, 'found expected test output')
39      t.notOk(stderr, 'stderr should be empty')
40    })
41
42test('npm install-test', function (t) {
43  t.plan(2)
44  t.test('setup', setup)
45  t.test('check', check(['install-test', '--no-shrinkwrap']))
46})
47
48test('npm it (the form most people will use)', function (t) {
49  t.plan(2)
50  t.test('setup', setup)
51  t.test('check', check(['it']))
52})
53
54function setup (t) {
55  t.test('destroy', t => {
56    t.plan(2)
57    rimraf(join(pkg, 'node_modules'), () => t.pass('node_modules'))
58    rimraf(join(pkg, 'package-lock.json'), () => t.pass('lock file'))
59  })
60  t.test('create', t => {
61    writeFileSync(join(pkg, 'package.json'), JSON.stringify(json, null, 2))
62    t.end()
63  })
64  t.end()
65}
66