• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fs = require('graceful-fs')
2var path = require('path')
3var test = require('tap').test
4var common = require('../common-tap.js')
5var pkg = common.pkg
6
7var json = {
8  name: 'lifecycle-order',
9  version: '1.0.0',
10  scripts: {
11    preinstall: 'node -e "var fs = require(\'fs\'); fs.openSync(\'preinstall-step\', \'w+\'); if (fs.existsSync(\'node_modules\')) { throw \'node_modules exists on preinstall\' }"',
12    install: 'node -e "var fs = require(\'fs\'); if (fs.existsSync(\'preinstall-step\')) { fs.openSync(\'install-step\', \'w+\') } else { throw \'Out of order\' }"',
13    postinstall: 'node -e "var fs = require(\'fs\'); if (fs.existsSync(\'install-step\')) { fs.openSync(\'postinstall-step\', \'w+\') } else { throw \'Out of order\' }"'
14  }
15}
16
17test('setup', function (t) {
18  fs.writeFileSync(
19    path.join(pkg, 'package.json'),
20    JSON.stringify(json, null, 2)
21  )
22  t.end()
23})
24
25test('lifecycle scripts execute in the proper order', t =>
26  common.npm('install', {cwd: pkg}).then(([code, stdout, stderr]) => {
27    t.is(code, 0, 'no error')
28
29    // All three files should exist
30    t.ok(fs.existsSync(path.join(pkg, 'preinstall-step')), 'preinstall ok')
31    t.ok(fs.existsSync(path.join(pkg, 'install-step')), 'install ok')
32    t.ok(fs.existsSync(path.join(pkg, 'postinstall-step')), 'postinstall ok')
33  }))
34