summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/fstream-npm/test/scoped.js
blob: db0c3d4c062b5d3202470764e1f7f72ac702f067 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var fs = require('graceful-fs')
var join = require('path').join

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

var Packer = require('..')

var pkg = join(__dirname, 'test-package-scoped')

var elfJS = function () {/*
module.exports = function () {
  console.log("i'm a elf")
}
*/}.toString().split('\n').slice(1, -1).join()

var json = {
  'name': 'test-package-scoped',
  'version': '3.1.4',
  'main': 'elf.js',
  'bundledDependencies': [
    '@npmwombat/scoped'
  ]
}

test('setup', function (t) {
  setup()
  t.end()
})

var expected = [
  'package.json',
  'elf.js',
  join('node_modules', '@npmwombat', 'scoped', 'index.js'),
  join('node_modules', '@npmwombat', 'scoped', 'node_modules', 'example', 'index.js')
]

test('includes bundledDependencies', function (t) {
  var subject = new Packer({ path: pkg, type: 'Directory', isDirectory: true })
  var actual = []
  subject.on('entry', function (entry) {
    t.equal(entry.type, 'File', 'only files in this package')
    // include relative path in filename
    var filename = entry._path.slice(entry.root._path.length + 1)
    actual.push(filename)
  })
  // need to do this so fstream doesn't explode when files are removed from
  // under it
  subject.on('end', function () {
    // ensure we get *exactly* the results we expect by comparing in both
    // directions
    actual.forEach(function (filename) {
      t.ok(
        expected.indexOf(filename) > -1,
        filename + ' is included'
      )
    })
    expected.forEach(function (filename) {
      t.ok(
        actual.indexOf(filename) > -1,
        filename + ' is not included'
      )
    })
    t.end()
  })
})

test('cleanup', function (t) {
  // rimraf.sync chokes here for some reason
  rimraf(pkg, function () { t.end() })
})

function setup () {
  rimraf.sync(pkg)
  mkdirp.sync(pkg)
  fs.writeFileSync(
    join(pkg, 'package.json'),
    JSON.stringify(json, null, 2)
  )

  fs.writeFileSync(
    join(pkg, 'elf.js'),
    elfJS
  )

  var scopedDir = join(pkg, 'node_modules', '@npmwombat', 'scoped')
  mkdirp.sync(scopedDir)
  fs.writeFileSync(
    join(scopedDir, 'index.js'),
    "console.log('hello wombat')"
  )
  var scopedContent = join(scopedDir, 'node_modules', 'example')
  mkdirp.sync(scopedContent)
  fs.writeFileSync(
    join(scopedContent, 'index.js'),
    "console.log('hello example')"
  )
}