@@ -14,6 +14,7 @@ import {
14
14
versionBump ,
15
15
VSIX ,
16
16
LicenseProcessor ,
17
+ printAndValidatePackagedFiles ,
17
18
} from '../package' ;
18
19
import { ManifestPackage } from '../manifest' ;
19
20
import * as path from 'path' ;
@@ -88,6 +89,36 @@ function createManifest(extra: Partial<ManifestPackage> = {}): ManifestPackage {
88
89
} ;
89
90
}
90
91
92
+ async function testPrintAndValidatePackagedFiles ( files : IFile [ ] , cwd : string , manifest : ManifestPackage , options : IPackageOptions , errorExpected : boolean , warningExpected : boolean ) : Promise < void > {
93
+ const originalLogError = log . error ;
94
+ const originalLogWarn = log . warn ;
95
+ const originalProcessExit = process . exit ;
96
+ const warns : string [ ] = [ ] ;
97
+ const errors : string [ ] = [ ] ;
98
+ log . error = ( message : string ) => errors . push ( message ) ;
99
+ log . warn = ( message : string ) => warns . push ( message ) ;
100
+ process . exit = ( ( ) => { throw Error ( 'Error' ) ; } ) as ( ) => never ;
101
+
102
+ let exitedOrErrorThrown = false ;
103
+ try {
104
+ await printAndValidatePackagedFiles ( files , cwd , manifest , options ) ;
105
+ } catch ( e ) {
106
+ exitedOrErrorThrown = true ;
107
+ } finally {
108
+ process . exit = originalProcessExit ;
109
+ log . error = originalLogError ;
110
+ log . warn = originalLogWarn ;
111
+ }
112
+
113
+ if ( errorExpected !== ! ! errors . length || exitedOrErrorThrown !== errorExpected ) {
114
+ throw new Error ( errors . length ? errors . join ( '\n' ) : 'Expected error' ) ;
115
+ }
116
+
117
+ if ( warningExpected !== ! ! warns . length ) {
118
+ throw new Error ( warns . length ? warns . join ( '\n' ) : 'Expected warning' ) ;
119
+ }
120
+ }
121
+
91
122
describe ( 'collect' , function ( ) {
92
123
this . timeout ( 60000 ) ;
93
124
@@ -133,22 +164,55 @@ describe('collect', function () {
133
164
] ) ;
134
165
} ) ;
135
166
136
- it ( 'should include content of manifest.files' , async ( ) => {
167
+ it ( 'manifest.files' , async ( ) => {
137
168
const cwd = fixture ( 'manifestFiles' ) ;
138
169
const manifest = await readManifest ( cwd ) ;
139
170
const files = await collect ( manifest , { cwd } ) ;
140
171
const names = files . map ( f => f . path ) . sort ( ) ;
141
172
173
+ await testPrintAndValidatePackagedFiles ( files , cwd , manifest , { } , false , false ) ;
174
+
142
175
assert . deepStrictEqual ( names , [
143
176
'[Content_Types].xml' ,
144
177
'extension.vsixmanifest' ,
178
+ 'extension/LICENSE.txt' ,
145
179
'extension/foo/bar/hello.txt' ,
146
180
'extension/foo2/bar2/include.me' ,
147
181
'extension/foo3/bar3/hello.txt' ,
148
182
'extension/package.json' ,
149
183
] ) ;
150
184
} ) ;
151
185
186
+ it ( 'manifest.files unused-files-patterns check 1' , async ( ) => {
187
+ const cwd = fixture ( 'manifestFiles' ) ;
188
+ const manifest = await readManifest ( cwd ) ;
189
+
190
+ const manifestCopy = { ...manifest , files : [ ...manifest . files ?? [ ] , 'extension/foo/bar/bye.txt' ] } ;
191
+ const files = await collect ( manifestCopy , { cwd } ) ;
192
+
193
+ await testPrintAndValidatePackagedFiles ( files , cwd , manifestCopy , { } , true , false ) ;
194
+ } ) ;
195
+
196
+ it ( 'manifest.files unused-files-patterns check 2' , async ( ) => {
197
+ const cwd = fixture ( 'manifestFiles' ) ;
198
+ const manifest = await readManifest ( cwd ) ;
199
+
200
+ const manifestCopy = { ...manifest , files : [ ...manifest . files ?? [ ] , 'extension/fo' ] } ;
201
+ const files = await collect ( manifestCopy , { cwd } ) ;
202
+
203
+ await testPrintAndValidatePackagedFiles ( files , cwd , manifestCopy , { } , true , false ) ;
204
+ } ) ;
205
+
206
+ it ( 'manifest.files unused-files-patterns check 3' , async ( ) => {
207
+ const cwd = fixture ( 'manifestFiles' ) ;
208
+ const manifest = await readManifest ( cwd ) ;
209
+
210
+ const manifestCopy = { ...manifest , files : [ '**' ] } ;
211
+ const files = await collect ( manifestCopy , { cwd } ) ;
212
+
213
+ await testPrintAndValidatePackagedFiles ( files , cwd , manifestCopy , { } , false , false ) ;
214
+ } ) ;
215
+
152
216
it ( 'should ignore devDependencies' , ( ) => {
153
217
const cwd = fixture ( 'devDependencies' ) ;
154
218
return readManifest ( cwd )
0 commit comments