@@ -61,11 +61,15 @@ describe('util', () => {
6161 } ) ;
6262
6363 describe ( 'When parsing circular' , ( ) => {
64- function dependencyFactory ( id : string ) : Dependency {
64+ function dependencyFactory (
65+ id : string ,
66+ issuer : string = '' ,
67+ kind = DependencyKind . StaticImport ,
68+ ) : Dependency {
6569 return {
66- issuer : '' ,
70+ issuer,
6771 request : '' ,
68- kind : DependencyKind . StaticImport ,
72+ kind,
6973 id,
7074 } ;
7175 }
@@ -225,5 +229,62 @@ describe('util', () => {
225229 expect ( actual [ 1 ] ) . toMatchObject ( [ 'start' , 'mid' , 'right' ] ) ;
226230 } ) ;
227231 } ) ;
232+
233+ describe ( 'When skip imports are specified' , ( ) => {
234+ it ( 'Should not skip imports when the skip list is empty' , ( ) => {
235+ const tree = {
236+ a : [ dependencyFactory ( 'b' , 'a' ) ] ,
237+ b : [ dependencyFactory ( 'a' , 'b' ) ] ,
238+ } ;
239+
240+ expect ( parseCircular ( tree , false , [ ] ) ) . toEqual ( [ [ 'a' , 'b' ] ] ) ;
241+ } ) ;
242+
243+ it ( 'Should ignore a matching import edge when parsing circulars' , ( ) => {
244+ const tree = {
245+ a : [ dependencyFactory ( 'b' , 'a' ) ] ,
246+ b : [ dependencyFactory ( 'a' , 'b' ) ] ,
247+ } ;
248+
249+ expect ( parseCircular ( tree , false , [ [ 'b' , 'a' ] ] ) ) . toEqual ( [ ] ) ;
250+ } ) ;
251+
252+ it ( 'Should only ignore the specified import edge' , ( ) => {
253+ const tree = {
254+ start : [
255+ dependencyFactory ( 'left' , 'start' ) ,
256+ dependencyFactory ( 'right' , 'start' ) ,
257+ ] ,
258+ left : [ dependencyFactory ( 'start' , 'left' ) ] ,
259+ right : [ dependencyFactory ( 'start' , 'right' ) ] ,
260+ } ;
261+
262+ const actual = parseCircular ( tree , false , [ [ 'left' , 'start' ] ] ) ;
263+ expect ( actual ) . toHaveLength ( 1 ) ;
264+ expect ( actual [ 0 ] ) . toMatchObject ( [ 'start' , 'right' ] ) ;
265+ } ) ;
266+
267+ it ( 'Should support regexp patterns for skipped imports' , ( ) => {
268+ const tree = {
269+ 'src/a.js' : [
270+ dependencyFactory ( 'src/b.js' , 'src/a.js' ) ,
271+ dependencyFactory ( 'src/c.js' , 'src/a.js' ) ,
272+ ] ,
273+ 'src/b.js' : [ dependencyFactory ( 'src/a.js' , 'src/b.js' ) ] ,
274+ 'src/c.js' : [ dependencyFactory ( 'src/a.js' , 'src/c.js' ) ] ,
275+ } ;
276+
277+ expect ( parseCircular ( tree , false , [ [ 'src/a.js' , '.*' ] ] ) ) . toEqual ( [ ] ) ;
278+ } ) ;
279+
280+ it ( 'Should not match skipped imports by prefix' , ( ) => {
281+ const tree = {
282+ a : [ dependencyFactory ( 'bc' , 'a' ) ] ,
283+ bc : [ dependencyFactory ( 'a' , 'bc' ) ] ,
284+ } ;
285+
286+ expect ( parseCircular ( tree , false , [ [ 'a' , 'b' ] ] ) ) . toEqual ( [ [ 'a' , 'bc' ] ] ) ;
287+ } ) ;
288+ } ) ;
228289 } ) ;
229290} ) ;
0 commit comments