• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var path = require('path')
2var fs = require('graceful-fs')
3var test = require('tap').test
4var mkdirp = require('mkdirp')
5var rimraf = require('rimraf')
6
7var common = require('../common-tap.js')
8
9var testdir = common.pkg
10var pkg = path.join(testdir, 'gently-rm-overeager')
11var dep = path.join(testdir, 'test-whoops')
12
13var EXEC_OPTS = { cwd: pkg }
14
15var fixture = {
16  name: '@test/whoops',
17  version: '1.0.0',
18  scripts: {
19    postinstall: 'echo \'nope\' && exit 1'
20  }
21}
22
23test('setup', function (t) {
24  cleanup()
25  setup()
26
27  return common.npm(['pack', 'file:test-whoops'], {cwd: testdir, stdio: 'inherit'}).spread((code) => {
28    t.is(code, 0, 'pack')
29  })
30})
31
32test('cache add', function (t) {
33  common.npm(['install', '--no-save', '../test-whoops-1.0.0.tgz'], EXEC_OPTS, function (er, c) {
34    t.ifError(er, "test-whoops install didn't explode")
35    t.ok(c, 'test-whoops install also failed')
36    fs.readdir(pkg, function (er, files) {
37      t.ifError(er, 'package directory is still there')
38      t.deepEqual(files, [], 'no files remain')
39      t.end()
40    })
41  })
42})
43
44test('cleanup', function (t) {
45  cleanup()
46
47  t.end()
48})
49
50function cleanup () {
51  rimraf.sync(testdir)
52}
53
54function setup () {
55  mkdirp.sync(pkg)
56  // so it doesn't try to install into npm's own node_modules
57  mkdirp.sync(path.join(pkg, 'node_modules'))
58  mkdirp.sync(dep)
59  fs.writeFileSync(path.join(dep, 'package.json'), JSON.stringify(fixture))
60}
61