@@ -15,6 +15,70 @@ import {
1515chai . use ( chaiAsPromised )
1616chai . should ( )
1717
18+ // TODO: after #46 merged, use:
19+ // const globPatternsPromise = setupSdk(FREE_API_KEY)
20+ // .then(sdk => sdk.getReportSupportedFiles())
21+ // .then(res => {
22+ // if (!res.success) throw new Error('failed to get API supported files')
23+ // return res.data
24+ // })
25+
26+ const globPatternsPromise = Promise . resolve ( {
27+ general : {
28+ readme : {
29+ pattern : '*readme*'
30+ } ,
31+ notice : {
32+ pattern : '*notice*'
33+ } ,
34+ license : {
35+ pattern : '{licen{s,c}e{,-*},copying}'
36+ }
37+ } ,
38+ npm : {
39+ packagejson : {
40+ pattern : 'package.json'
41+ } ,
42+ packagelockjson : {
43+ pattern : 'package-lock.json'
44+ } ,
45+ npmshrinkwrap : {
46+ pattern : 'npm-shrinkwrap.json'
47+ } ,
48+ yarnlock : {
49+ pattern : 'yarn.lock'
50+ } ,
51+ pnpmlock : {
52+ pattern : 'pnpm-lock.yaml'
53+ } ,
54+ pnpmworkspace : {
55+ pattern : 'pnpm-workspace.yaml'
56+ }
57+ } ,
58+ pypi : {
59+ pipfile : {
60+ pattern : 'pipfile'
61+ } ,
62+ pyproject : {
63+ pattern : 'pyproject.toml'
64+ } ,
65+ requirements : {
66+ pattern :
67+ '{*requirements.txt,requirements/*.txt,requirements-*.txt,requirements.frozen}'
68+ } ,
69+ setuppy : {
70+ pattern : 'setup.py'
71+ }
72+ }
73+ } )
74+
75+ /**
76+ * @param {string } file
77+ * @returns {Promise<string[]> }
78+ */
79+ const mapGlobEntry = async ( file ) =>
80+ mapGlobEntryToFiles ( file , await globPatternsPromise )
81+
1882describe ( 'Path Resolve' , ( ) => {
1983 beforeEach ( ( ) => {
2084 nock . cleanAll ( )
@@ -56,14 +120,14 @@ describe('Path Resolve', () => {
56120 mockFs ( {
57121 '/foo.txt' : 'some content' ,
58122 } )
59- await mapGlobEntryToFiles ( '/foo.txt' ) . should . eventually . become ( [ ] )
123+ await mapGlobEntry ( '/foo.txt' ) . should . eventually . become ( [ ] )
60124 } )
61125
62126 it ( 'should throw on errors' , async ( ) => {
63127 mockFs ( {
64128 '/package.json' : { /* Empty directory */ } ,
65129 } )
66- await mapGlobEntryToFiles ( '/' )
130+ await mapGlobEntry ( '/' )
67131 . should . eventually . be . rejectedWith ( InputError , 'Expected \'/package.json\' to be a file' )
68132 } )
69133 } )
@@ -74,7 +138,7 @@ describe('Path Resolve', () => {
74138 '/package-lock.json' : '{}' ,
75139 '/package.json' : '{}' ,
76140 } )
77- await mapGlobEntryToFiles ( '/' ) . should . eventually . become ( [
141+ await mapGlobEntry ( '/' ) . should . eventually . become ( [
78142 '/package.json' ,
79143 '/package-lock.json'
80144 ] )
@@ -84,22 +148,22 @@ describe('Path Resolve', () => {
84148 mockFs ( {
85149 '/package.json' : '{}' ,
86150 } )
87- await mapGlobEntryToFiles ( '/' ) . should . eventually . become ( [ '/package.json' ] )
151+ await mapGlobEntry ( '/' ) . should . eventually . become ( [ '/package.json' ] )
88152 } )
89153
90154 it ( 'should not resolve lock file without package' , async ( ) => {
91155 mockFs ( {
92156 '/package-lock.json' : '{}' ,
93157 } )
94- await mapGlobEntryToFiles ( '/' ) . should . eventually . become ( [ ] )
158+ await mapGlobEntry ( '/' ) . should . eventually . become ( [ ] )
95159 } )
96160
97161 it ( 'should support alternative lock files' , async ( ) => {
98162 mockFs ( {
99163 '/yarn.lock' : '{}' ,
100164 '/package.json' : '{}' ,
101165 } )
102- await mapGlobEntryToFiles ( '/' ) . should . eventually . become ( [
166+ await mapGlobEntry ( '/' ) . should . eventually . become ( [
103167 '/package.json' ,
104168 '/yarn.lock'
105169 ] )
@@ -112,7 +176,7 @@ describe('Path Resolve', () => {
112176 '/package-lock.json' : '{}' ,
113177 '/package.json' : '{}' ,
114178 } )
115- await mapGlobEntryToFiles ( '/package.json' ) . should . eventually . become ( [
179+ await mapGlobEntry ( '/package.json' ) . should . eventually . become ( [
116180 '/package.json' ,
117181 '/package-lock.json'
118182 ] )
@@ -122,19 +186,19 @@ describe('Path Resolve', () => {
122186 mockFs ( {
123187 '/package.json' : '{}' ,
124188 } )
125- await mapGlobEntryToFiles ( '/package.json' ) . should . eventually . become ( [ '/package.json' ] )
189+ await mapGlobEntry ( '/package.json' ) . should . eventually . become ( [ '/package.json' ] )
126190 } )
127191
128192 it ( 'should not validate the input file' , async ( ) => {
129193 mockFs ( { } )
130- await mapGlobEntryToFiles ( '/package.json' ) . should . eventually . become ( [ '/package.json' ] )
194+ await mapGlobEntry ( '/package.json' ) . should . eventually . become ( [ '/package.json' ] )
131195 } )
132196
133197 it ( 'should not validate the input file, but still add a complementary lock file' , async ( ) => {
134198 mockFs ( {
135199 '/package-lock.json' : '{}' ,
136200 } )
137- await mapGlobEntryToFiles ( '/package.json' ) . should . eventually . become ( [
201+ await mapGlobEntry ( '/package.json' ) . should . eventually . become ( [
138202 '/package.json' ,
139203 '/package-lock.json'
140204 ] )
@@ -145,7 +209,7 @@ describe('Path Resolve', () => {
145209 '/yarn.lock' : '{}' ,
146210 '/package.json' : '{}' ,
147211 } )
148- await mapGlobEntryToFiles ( '/package.json' ) . should . eventually . become ( [
212+ await mapGlobEntry ( '/package.json' ) . should . eventually . become ( [
149213 '/package.json' ,
150214 '/yarn.lock'
151215 ] )
@@ -158,15 +222,15 @@ describe('Path Resolve', () => {
158222 '/package-lock.json' : '{}' ,
159223 '/package.json' : '{}' ,
160224 } )
161- await mapGlobEntryToFiles ( '/package-lock.json' ) . should . eventually . become ( [
225+ await mapGlobEntry ( '/package-lock.json' ) . should . eventually . become ( [
162226 '/package.json' ,
163227 '/package-lock.json'
164228 ] )
165229 } )
166230
167231 it ( 'should assume input is correct and paired with package file' , async ( ) => {
168232 mockFs ( { } )
169- await mapGlobEntryToFiles ( '/package-lock.json' ) . should . eventually . become ( [
233+ await mapGlobEntry ( '/package-lock.json' ) . should . eventually . become ( [
170234 '/package.json' ,
171235 '/package-lock.json'
172236 ] )
@@ -177,7 +241,7 @@ describe('Path Resolve', () => {
177241 '/yarn.lock' : '{}' ,
178242 '/package.json' : '{}' ,
179243 } )
180- await mapGlobEntryToFiles ( '/yarn.lock' ) . should . eventually . become ( [
244+ await mapGlobEntry ( '/yarn.lock' ) . should . eventually . become ( [
181245 '/package.json' ,
182246 '/yarn.lock'
183247 ] )
0 commit comments