summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/unpack-foreign-tarball.js
blob: d128e94d8c37df1669596303d0726daa042e4437 (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
var fs = require('graceful-fs')
var path = require('path')

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

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

var fixtures = path.resolve(__dirname, '..', 'fixtures')

var pkg = path.resolve(__dirname, 'unpack-foreign-tarball')
var nm = path.resolve(pkg, 'node_modules')
var target = path.resolve(nm, 'npm-test-gitignore')
var cache = path.resolve(pkg, 'cache')
var tmp = path.resolve(pkg, 'tmp')

var EXEC_OPTS = {
  env: {
    'npm_config_cache': cache,
    'npm_config_tmp': tmp
  },
  cwd: pkg
}

function verify (t, files, err, code) {
  if (code) {
    t.fail('exited with failure: ' + code)
    return t.end()
  }
  var actual = fs.readdirSync(target).sort()
  var expect = files.concat(['.npmignore', 'package.json']).sort()
  t.same(actual, expect)
  t.end()
}

test('setup', function (t) {
  setup()
  t.comment('test for https://github.com/npm/npm/issues/5658')
  t.end()
})

test('npmignore only', function (t) {
  var file = path.resolve(fixtures, 'npmignore.tgz')
  common.npm(['install', file], EXEC_OPTS, verify.bind(null, t, ['foo']))
})

test('gitignore only', function (t) {
  setup()
  var file = path.resolve(fixtures, 'gitignore.tgz')
  common.npm(['install', file], EXEC_OPTS, verify.bind(null, t, ['foo']))
})

test('gitignore and npmignore', function (t) {
  setup()
  var file = path.resolve(fixtures, 'gitignore-and-npmignore.tgz')
  common.npm(['install', file], EXEC_OPTS, verify.bind(null, t, ['foo', 'bar']))
})

test('gitignore and npmignore, not gzipped 1/2', function (t) {
  setup()
  var file = path.resolve(fixtures, 'gitignore-and-npmignore.tar')
  common.npm(['install', file], EXEC_OPTS, verify.bind(null, t, ['foo', 'bar']))
})

test('gitignore and npmignore, not gzipped 2/2', function (t) {
  setup()
  var file = path.resolve(fixtures, 'gitignore-and-npmignore-2.tar')
  common.npm(['install', file], EXEC_OPTS, verify.bind(null, t, ['foo', 'bar']))
})

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

function setup () {
  cleanup()
  mkdirp.sync(nm)
  mkdirp.sync(tmp)
}

function cleanup () {
  process.chdir(osenv.tmpdir())
  rimraf.sync(pkg)
}