summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/gently-rm-overeager.js
blob: 08fa72bc71c7cacd07862363dcd3d0d94937e2f3 (plain)
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
var path = require('path')
var fs = require('graceful-fs')
var test = require('tap').test
var mkdirp = require('mkdirp')
var rimraf = require('rimraf')

var common = require('../common-tap.js')

var pkg = path.join(__dirname, 'gently-rm-overeager')
var dep = path.join(__dirname, 'test-whoops')

var EXEC_OPTS = { cwd: pkg }

var fixture = {
  name: '@test/whoops',
  version: '1.0.0',
  scripts: {
    postinstall: 'echo \'nope\' && exit 1'
  }
}

test('setup', function (t) {
  cleanup()
  setup()

  t.end()
})

test('cache add', function (t) {
  common.npm(['install', '../test-whoops'], EXEC_OPTS, function (er, c) {
    t.ifError(er, "test-whoops install didn't explode")
    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, [], 'no files remain')
      t.end()
    })
  })
})

test('cleanup', function (t) {
  cleanup()

  t.end()
})

function cleanup () {
  rimraf.sync(pkg)
  rimraf.sync(dep)
}

function setup () {
  mkdirp.sync(pkg)
  // so it doesn't try to install into npm's own node_modules
  mkdirp.sync(path.join(pkg, 'node_modules'))
  mkdirp.sync(dep)
  fs.writeFileSync(path.join(dep, 'package.json'), JSON.stringify(fixture))
}