-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathpackage-json-bin-single.js
77 lines (62 loc) · 1.29 KB
/
package-json-bin-single.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
'use strict'
const fs = require('fs')
const path = require('path')
const mkdirp = require('mkdirp')
const rimraf = require('rimraf')
const t = require('tap')
const pack = require('../')
const pkg = path.join(__dirname, path.basename(__filename, '.js'))
t.teardown(_ => rimraf.sync(pkg))
const bin = `
#!/usr/bin/env node
require("../lib/elf")()
`
const elfJS = `
module.exports = elf =>
console.log("i'm angry about elves")
`
const json = {
name: 'test-package',
version: '1.6.2',
bin: '__bin',
files: [
'lib'
]
}
const expect = [
'package.json',
'__bin',
'lib/elf.js'
]
t.test('setup', t => {
rimraf.sync(pkg)
mkdirp.sync(pkg)
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
)
fs.writeFileSync(
path.join(pkg, '__bin'),
bin
)
const libDir = path.join(pkg, 'lib')
mkdirp.sync(libDir)
fs.writeFileSync(
path.join(libDir, 'elf.js'),
elfJS
)
fs.writeFileSync(
path.join(pkg, 'dummy'),
'needs to be ignored'
)
t.end()
})
t.test('follows npm package ignoring rules', t => {
const check = (files, t) => {
t.same(files, expect)
t.end()
}
t.test('sync', t => check(pack.sync({ path: pkg }), t))
t.test('async', t => pack({ path: pkg }).then(files => check(files, t)))
t.end()
})