summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/shrinkwrap-lifecycle.js
blob: 5ed35e186843b2cced74995e3da436822f38b760 (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
var fs = require('graceful-fs')
var path = require('path')

var mkdirp = require('mkdirp')
var osenv = require('osenv')
var rimraf = require('rimraf')
var test = require('tap').test

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

test('npm shrinkwrap execution order', function (t) {
  setup()
  fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({
    author: 'Simen Bekkhus',
    name: 'shrinkwrap-lifecycle',
    shrinkwrap: '0.0.0',
    description: 'Test for npm shrinkwrap execution order',
    scripts: {
      preshrinkwrap: 'echo this happens first',
      shrinkwrap: 'echo this happens second',
      postshrinkwrap: 'echo this happens third'
    }
  }), 'utf8')
  common.npm(['shrinkwrap', '--loglevel=error'], [], function (err, code, stdout, stderr) {
    if (err) throw err

    t.comment(stdout)
    t.comment(stderr)
    var indexOfFirst = stdout.indexOf('echo this happens first')
    var indexOfSecond = stdout.indexOf('echo this happens second')
    var indexOfThird = stdout.indexOf('echo this happens third')

    t.ok(indexOfFirst >= 0)
    t.ok(indexOfSecond >= 0)
    t.ok(indexOfThird >= 0)

    t.ok(indexOfFirst < indexOfSecond)
    t.ok(indexOfSecond < indexOfThird)

    t.end()
  })
})

test('cleanup', function (t) {
  process.chdir(osenv.tmpdir())
  rimraf.sync(pkg)
  t.end()
})

function setup () {
  mkdirp.sync(pkg)
  process.chdir(pkg)
}