• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var path = require('path')
3var fs = require('fs')
4var test = require('tap').test
5var common = require('../common-tap.js')
6var rimraf = require('rimraf')
7var mkdirp = require('mkdirp')
8var basepath = common.pkg
9var fixturepath = path.resolve(basepath, 'npm-test-missing-bindir')
10var modulepath = path.resolve(basepath, 'node_modules')
11var installedpath = path.resolve(modulepath, 'npm-test-missing-bindir')
12var Tacks = require('tacks')
13var File = Tacks.File
14var Dir = Tacks.Dir
15
16var fixture = new Tacks(
17  Dir({
18    README: File(
19      'just an npm test\n'
20    ),
21    'package.json': File({
22      name: 'npm-test-missing-bindir',
23      version: '0.0.0',
24      directories: {
25        bin: './not-found'
26      }
27    })
28  })
29)
30
31test('setup', function (t) {
32  setup()
33  t.done()
34})
35
36function installedExists (filename) {
37  try {
38    fs.statSync(path.resolve(installedpath, filename))
39    return true
40  } catch (ex) {
41    console.log(ex)
42    return false
43  }
44}
45
46test('missing-bindir', function (t) {
47  common.npm(['install', fixturepath], {cwd: basepath}, installCheckAndTest)
48
49  function installCheckAndTest (err, code, stdout, stderr) {
50    if (err) throw err
51    t.is(code, 0, 'install went ok')
52    t.is(installedExists('README'), true, 'README')
53    t.is(installedExists('package.json'), true, 'package.json')
54    common.npm(['rm', fixturepath], {cwd: basepath}, removeCheckAndDone)
55  }
56
57  function removeCheckAndDone (err, code, stdout, stderr) {
58    if (err) throw err
59    t.is(code, 0, 'remove went ok')
60    t.done()
61  }
62})
63
64test('cleanup', function (t) {
65  cleanup()
66  t.done()
67})
68
69function setup () {
70  cleanup()
71  fixture.create(fixturepath)
72  mkdirp.sync(modulepath)
73}
74
75function cleanup () {
76  fixture.remove(fixturepath)
77  rimraf.sync(basepath)
78}
79