-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
131 lines (95 loc) · 3.17 KB
/
test.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
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
'use strict'
const test = require('ava')
const LicensesFetch = require('./dist/index')
test('initializing the constructor with no parameters uses defaults', t => {
let myLicenses = new LicensesFetch()
t.is(myLicenses.filesPattern, 'node_modules/**/package.json')
})
test('initializing the constructor with a parameter is set successfully', t => {
const filesPattern = '/tmp/something/node_modules/**/*.js'
let myLicenses = new LicensesFetch(filesPattern)
t.is(myLicenses.filesPattern, filesPattern)
})
test('listing files should return an array of all matched files', async t => {
t.plan(2)
let myLicenses = new LicensesFetch('node_modules/**/package.json')
myLicenses.fetch()
await new Promise((resolve, reject) => {
myLicenses.on('files', (licenseFiles) => {
t.true(Array.isArray(licenseFiles))
t.true(licenseFiles.length > 0)
resolve(licenseFiles)
})
})
})
test('listing files should not break on malformed json', async t => {
t.plan(2)
let myLicenses = new LicensesFetch('fixtures-malformed/**/package.json')
myLicenses.fetch()
await new Promise((resolve, reject) => {
myLicenses.on('files', (licenseFiles) => {
t.true(Array.isArray(licenseFiles))
t.true(licenseFiles.length > 0)
resolve(licenseFiles)
})
})
})
test('listing files fail if the filespattern is not a string', async t => {
t.plan(1)
let myLicenses = new LicensesFetch(['somepattern'])
myLicenses.fetch()
await new Promise((resolve, reject) => {
myLicenses.on('error', (error) => {
t.is(error.message.indexOf('glob pattern string required') !== false, true)
resolve(error)
})
})
})
test('listing files fail if the filespattern is empty', async t => {
t.plan(2)
let myLicenses = new LicensesFetch('')
const filesObj = await myLicenses.fetch()
t.true(typeof filesObj === 'object')
t.true(Object.keys(filesObj).length === 0)
})
test('normalize function fails if not given an array', t => {
t.plan(1)
let myLicenses = new LicensesFetch('')
const filesObj = myLicenses.normalize('')
t.false(filesObj)
})
test('getting a single license event is successful', async t => {
t.plan(1)
let myLicenses = new LicensesFetch('node_modules/**/package.json')
myLicenses.fetch()
await new Promise((resolve, reject) => {
myLicenses.once('license', (license) => {
t.true(typeof license === 'string')
resolve(license)
})
})
})
test('getting all licenses as a bulk array is successful', async t => {
t.plan(1)
let myLicenses = new LicensesFetch('node_modules/**/package.json')
myLicenses.fetch()
await new Promise((resolve, reject) => {
myLicenses.on('licenses', (licenses) => {
t.true(Array.isArray(licenses))
resolve(licenses)
})
})
})
test('getting an aggregated list of licenses as a hashmap object', async t => {
t.plan(2)
let myLicenses = new LicensesFetch('node_modules/**/package.json')
myLicenses.fetch()
await new Promise((resolve, reject) => {
myLicenses.on('licensesSummary', (data) => {
const licenses = data.licenses
t.true(typeof licenses === 'object')
t.true(Object.keys(licenses).length > 0)
resolve(licenses)
})
})
})