• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var path = require('path')
3var test = require('tap').test
4var mr = require('npm-registry-mock')
5var Tacks = require('tacks')
6var File = Tacks.File
7var Dir = Tacks.Dir
8var common = require('../common-tap.js')
9
10var basedir = common.pkg
11var testdir = path.join(basedir, 'testdir')
12var cachedir = common.cache
13var globaldir = path.join(basedir, 'global')
14var tmpdir = path.join(basedir, 'tmp')
15
16var conf = {
17  cwd: testdir,
18  env: Object.assign({
19    npm_config_cache: cachedir,
20    npm_config_tmp: tmpdir,
21    npm_config_prefix: globaldir,
22    npm_config_registry: common.registry,
23    npm_config_loglevel: 'warn'
24  }, process.env)
25}
26
27var server
28var fixture = new Tacks(Dir({
29  cache: Dir(),
30  global: Dir(),
31  tmp: Dir(),
32  testdir: Dir({
33    node_modules: Dir({}),
34    'package.json': File({
35      name: '13252',
36      version: '1.0.0',
37      scripts: {
38        // add this to the end of the command to preserve the debug log:
39        // || mv npm-debug.log real-debug.log
40        // removed for windows compat reasons
41        abc: 'node ' + JSON.stringify(common.bin) + ' shrinkwrap',
42        shrinkwrap: 'node scripts/shrinkwrap.js'
43      }
44    }),
45    scripts: Dir({
46      'shrinkwrap.js': File(
47        'console.log("OK " + process.cwd())'
48      )
49    })
50  })
51}))
52
53function setup () {
54  cleanup()
55  fixture.create(basedir)
56}
57
58function cleanup () {
59  fixture.remove(basedir)
60}
61
62test('setup', function (t) {
63  setup()
64  mr({port: common.port, throwOnUnmatched: true}, function (err, s) {
65    if (err) throw err
66    server = s
67    t.done()
68  })
69})
70
71test('shrinkwrap-lifecycle-cwd', function (t) {
72  common.npm(['run', 'abc'], conf, function (err, code, stdout, stderr) {
73    if (err) throw err
74    t.is(code, 0, 'command ran ok')
75    t.comment(stdout.trim())
76    t.comment(stderr.trim())
77    t.match(stdout.trim(), 'OK ' + testdir, 'got output from lifecycle script')
78    t.is(stderr.trim().length, 0, 'no errors')
79    t.done()
80  })
81})
82
83test('cleanup', function (t) {
84  server.close()
85  cleanup()
86  t.done()
87})
88