summaryrefslogtreecommitdiff
path: root/deps/node/deps/npm/node_modules/read-cmd-shim/test/integration.js
blob: 269f964727cd6ba8cde1473cf951b30e6244e659 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
'use strict'
var path = require('path')
var fs = require('graceful-fs')
var test = require('tap').test
var rimraf = require('rimraf')
var cmdShim = require('cmd-shim')
var readCmdShim = require('../index.js')
var workDir = path.join(__dirname, path.basename(__filename, '.js'))
var testShbang = path.join(workDir, 'test-shbang')
var testShbangCmd = testShbang + '.cmd'
var testShim = path.join(workDir, 'test')
var testShimCmd = testShim + '.cmd'

test('setup', function (t) {
  rimraf.sync(workDir)
  fs.mkdirSync(workDir)
  fs.writeFileSync(testShbang + '.js', '#!/usr/bin/env node\ntrue')
  cmdShim(__filename, testShim, function (er) {
    t.error(er)
    cmdShim(testShbang + '.js', testShbang, function (er) {
      t.error(er)
      t.done()
    })
  })
})

test('async-read-no-shbang', function (t) {
  t.plan(2)
  readCmdShim(testShimCmd, function (er, dest) {
    t.error(er)
    t.is(dest, '..\\basic.js')
    t.done()
  })
})

test('sync-read-no-shbang', function (t) {
  t.plan(1)
  var dest = readCmdShim.sync(testShimCmd)
  t.is(dest, '..\\basic.js')
  t.done()
})

test('async-read-shbang', function (t) {
  t.plan(2)
  readCmdShim(testShbangCmd, function (er, dest) {
    t.error(er)
    t.is(dest, 'test-shbang.js')
    t.done()
  })
})

test('sync-read-shbang', function (t) {
  t.plan(1)
  var dest = readCmdShim.sync(testShbangCmd)
  t.is(dest, 'test-shbang.js')
  t.done()
})

test('async-read-no-shbang-cygwin', function (t) {
  t.plan(2)
  readCmdShim(testShim, function (er, dest) {
    t.error(er)
    t.is(dest, '../basic.js')
    t.done()
  })
})

test('sync-read-no-shbang-cygwin', function (t) {
  t.plan(1)
  var dest = readCmdShim.sync(testShim)
  t.is(dest, '../basic.js')
  t.done()
})

test('async-read-shbang-cygwin', function (t) {
  t.plan(2)
  readCmdShim(testShbang, function (er, dest) {
    t.error(er)
    t.is(dest, 'test-shbang.js')
    t.done()
  })
})

test('sync-read-shbang-cygwin', function (t) {
  t.plan(1)
  var dest = readCmdShim.sync(testShbang)
  t.is(dest, 'test-shbang.js')
  t.done()
})

test('async-read-dir', function (t) {
  t.plan(2)
  readCmdShim(workDir, function (er) {
    t.ok(er)
    t.is(er.code, 'EISDIR', "cmd-shims can't be directories")
    t.done()
  })
})

test('sync-read-dir', function (t) {
  t.plan(1)
  t.throws(function () { readCmdShim.sync(workDir) }, "cmd-shims can't be directories")
  t.done()
})

test('async-read-not-there', function (t) {
  t.plan(2)
  readCmdShim('/path/to/nowhere', function (er, dest) {
    t.ok(er, 'missing files throw errors')
    t.is(er.code, 'ENOENT', "cmd-shim file doesn't exist")
    t.done()
  })
})

test('sync-read-not-there', function (t) {
  t.plan(1)
  t.throws(function () { readCmdShim.sync('/path/to/nowhere') }, "cmd-shim file doesn't exist")
  t.done()
})

test('async-read-not-shim', function (t) {
  t.plan(2)
  readCmdShim(__filename, function (er, dest) {
    t.ok(er)
    t.is(er.code, 'ENOTASHIM', 'shim file specified is not a shim')
    t.done()
  })
})

test('sync-read-not-shim', function (t) {
  t.plan(1)
  t.throws(function () { readCmdShim.sync(__filename) }, 'shim file specified is not a shim')
  t.done()
})

test('cleanup', function (t) {
  rimraf.sync(workDir)
  t.done()
})