@@ -129,6 +129,86 @@ describe('Typechain x Hardhat', function () {
129
129
expect ( consoleLogMock ) . toHaveBeenCalledWith ( [ 'Successfully generated 14 typings for external artifacts!' ] )
130
130
} )
131
131
} )
132
+
133
+ describe ( 'when setting custom artifact glob' , ( ) => {
134
+ let oldArtifactGlob : string [ ] | undefined
135
+ beforeEach ( function ( ) {
136
+ oldArtifactGlob = this . hre . config . typechain . artifacts
137
+ } )
138
+ afterEach ( function ( ) {
139
+ this . hre . config . typechain . artifacts = oldArtifactGlob
140
+ } )
141
+ ; [ true , false ] . forEach ( ( forcedCompilation ) => {
142
+ describe ( `when type generation is ${ forcedCompilation ? '' : 'not' } forced` , ( ) => {
143
+ let subject : ( ) => Promise < void >
144
+ beforeEach ( async function ( ) {
145
+ if ( forcedCompilation ) {
146
+ await this . hre . run ( 'compile' , { noTypechain : true } )
147
+ }
148
+ subject = ( ) => {
149
+ if ( forcedCompilation ) {
150
+ return this . hre . run ( 'typechain' )
151
+ } else {
152
+ return this . hre . run ( 'compile' )
153
+ }
154
+ }
155
+ } )
156
+
157
+ describe ( 'when glob matches some files' , ( ) => {
158
+ beforeEach ( function ( ) {
159
+ this . hre . config . typechain . artifacts = [ '**/EdgeCases.json' ]
160
+ } )
161
+
162
+ it ( 'includes build artifacts that match the glob' , async function ( ) {
163
+ const exists = existsSync ( this . hre . config . typechain . outDir )
164
+ expect ( exists ) . toEqual ( false )
165
+
166
+ await subject ( )
167
+
168
+ const dir = await readdir ( this . hre . config . typechain . outDir )
169
+ expect ( dir . includes ( 'EdgeCases.ts' ) ) . toEqual ( true )
170
+ } )
171
+
172
+ it ( 'excludes build artifacts that do not match the glob' , async function ( ) {
173
+ const exists = existsSync ( this . hre . config . typechain . outDir )
174
+ expect ( exists ) . toEqual ( false )
175
+
176
+ await subject ( )
177
+
178
+ const dir = await readdir ( this . hre . config . typechain . outDir )
179
+ expect ( dir . includes ( 'TestContract.ts' ) ) . toEqual ( false )
180
+ expect ( dir . includes ( 'TestContract1.ts' ) ) . toEqual ( false )
181
+ } )
182
+ } )
183
+ describe ( 'when glob matches no files' , ( ) => {
184
+ beforeEach ( function ( ) {
185
+ this . hre . config . typechain . artifacts = [ '**/THISDOESNTMATCHANYTHING.json' ]
186
+ } )
187
+
188
+ describe ( 'when no external artifacts are specified' , ( ) => {
189
+ it ( 'does not generate any types' , async function ( ) {
190
+ const exists = existsSync ( this . hre . config . typechain . outDir )
191
+ expect ( exists ) . toEqual ( false )
192
+
193
+ await subject ( )
194
+ expect ( existsSync ( this . hre . config . typechain . outDir ) ) . toEqual ( false )
195
+ } )
196
+ } )
197
+
198
+ describe ( 'when external artifacts are specified' , ( ) => {
199
+ it ( 'only generates types for external artifacts' , async function ( ) {
200
+ const exists = existsSync ( this . hre . config . typechain . outDir )
201
+ expect ( exists ) . toEqual ( false )
202
+
203
+ this . hre . config . typechain . externalArtifacts = [ 'externalArtifacts/*.json' ]
204
+ await subject ( )
205
+ expect ( existsSync ( this . hre . config . typechain . outDir ) ) . toEqual ( true )
206
+ } )
207
+ } )
208
+ } )
209
+ } )
210
+ } )
211
+ } )
132
212
} )
133
213
134
214
describe ( 'dontOverrideCompile' , function ( ) {
0 commit comments