-
Notifications
You must be signed in to change notification settings - Fork 32
/
bin.js
92 lines (84 loc) · 2.64 KB
/
bin.js
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
// disabling the no-sparse-arrays rule because we use them for assertions
/* eslint-disable no-sparse-arrays */
'use strict'
const t = require('tap')
const { spawnSync } = require('child_process')
const nodePath = process.execPath
const binPath = require.resolve('./utils/bin.js')
const cwd = t.testdir({
'package.json': JSON.stringify({
files: ['index.js', 'lib'],
}),
'README.md': 'hello',
'LICENSE.txt': 'you can use it but you gotta pay me',
'index.js': 'console.log(/xss/)',
lib: {
'index.js': 'console.log(/xss/)',
'cat.js': 'console.log("meow")',
'dog.js': 'console.log("woof")',
'chai.js': 'console.log("blub")',
},
'ignore.js': 'throw new Error("dont look at me!")',
})
t.test('no args', async (t) => {
const result = spawnSync(nodePath, [binPath], { cwd, encoding: 'utf8' })
t.equal(result.status, 0, 'completed successfully')
t.same(result.stdout, [
'lib/cat.js',
'lib/chai.js',
'lib/dog.js',
'index.js',
'lib/index.js',
'package.json',
'README.md',
'LICENSE.txt',, // empty element at the end so we get a trailing \n
].join('\n'))
})
t.test('--sort', async (t) => {
const result = spawnSync(nodePath, [binPath, '--sort'], { cwd, encoding: 'utf8' })
t.equal(result.status, 0, 'completed successfully')
t.same(result.stdout, [
'index.js',
'lib/cat.js',
'lib/chai.js',
'lib/dog.js',
'lib/index.js',
'LICENSE.txt',
'package.json',
'README.md',, // empty element at the end so we get a trailing \n
].join('\n'))
})
t.test('-s', async (t) => {
const result = spawnSync(nodePath, [binPath, '-s'], { cwd, encoding: 'utf8' })
t.equal(result.status, 0, 'completed successfully')
t.same(result.stdout, [
'index.js',
'lib/cat.js',
'lib/chai.js',
'lib/dog.js',
'lib/index.js',
'LICENSE.txt',
'package.json',
'README.md',, // empty element at the end so we get a trailing \n
].join('\n'))
})
t.test('dir argument', async (t) => {
const result = spawnSync(nodePath, [binPath, '.'], { cwd, encoding: 'utf8' })
t.equal(result.status, 0, 'completed successfully')
t.same(result.stdout, [
'> .', // the directory name prefixed with "> "
' lib/cat.js', // the files will all be indented
' lib/chai.js',
' lib/dog.js',
' index.js',
' lib/index.js',
' package.json',
' README.md',
' LICENSE.txt',, // empty element at the end so we get a trailing \n
].join('\n'))
})
t.test('-h', async (t) => {
const result = spawnSync(nodePath, [binPath, '-h'], { cwd, encoding: 'utf8' })
t.equal(result.status, 0, 'completed successfully')
t.match(result.stdout, /^usage: npm-packlist/, 'printed help')
})