7
7
} from '@nrwl/devkit' ;
8
8
import {
9
9
DepConstraint ,
10
+ findConstraintsFor ,
10
11
findTransitiveExternalDependencies ,
11
12
hasBannedDependencies ,
12
13
hasBannedImport ,
@@ -19,6 +20,68 @@ jest.mock('nx/src/utils/workspace-root', () => ({
19
20
workspaceRoot : '/root' ,
20
21
} ) ) ;
21
22
23
+ describe ( 'findConstraintsFor' , ( ) => {
24
+ it ( 'should find constraints matching tag' , ( ) => {
25
+ const constriants : DepConstraint [ ] = [
26
+ { sourceTag : 'a' , onlyDependOnLibsWithTags : [ 'b' ] } ,
27
+ { sourceTag : 'b' , onlyDependOnLibsWithTags : [ 'c' ] } ,
28
+ { sourceTag : 'c' , onlyDependOnLibsWithTags : [ 'a' ] } ,
29
+ ] ;
30
+
31
+ expect (
32
+ findConstraintsFor ( constriants , {
33
+ type : 'lib' ,
34
+ name : 'someLib' ,
35
+ data : { root : '.' , files : [ ] , tags : [ 'b' ] } ,
36
+ } )
37
+ ) . toEqual ( [ { sourceTag : 'b' , onlyDependOnLibsWithTags : [ 'c' ] } ] ) ;
38
+ } ) ;
39
+
40
+ it ( 'should find constraints matching *' , ( ) => {
41
+ const constriants : DepConstraint [ ] = [
42
+ { sourceTag : 'a' , onlyDependOnLibsWithTags : [ 'b' ] } ,
43
+ { sourceTag : 'b' , onlyDependOnLibsWithTags : [ 'c' ] } ,
44
+ { sourceTag : '*' , onlyDependOnLibsWithTags : [ 'a' ] } ,
45
+ ] ;
46
+
47
+ expect (
48
+ findConstraintsFor ( constriants , {
49
+ type : 'lib' ,
50
+ name : 'someLib' ,
51
+ data : { root : '.' , files : [ ] , tags : [ 'b' ] } ,
52
+ } )
53
+ ) . toEqual ( [
54
+ { sourceTag : 'b' , onlyDependOnLibsWithTags : [ 'c' ] } ,
55
+ { sourceTag : '*' , onlyDependOnLibsWithTags : [ 'a' ] } ,
56
+ ] ) ;
57
+ } ) ;
58
+
59
+ it ( 'should find constraints matching regex' , ( ) => {
60
+ const constriants : DepConstraint [ ] = [
61
+ { sourceTag : 'a' , onlyDependOnLibsWithTags : [ 'a' ] } ,
62
+ { sourceTag : '/^b$/' , onlyDependOnLibsWithTags : [ 'c' ] } ,
63
+ { sourceTag : '/a|b/' , onlyDependOnLibsWithTags : [ 'c' ] } ,
64
+ ] ;
65
+ expect (
66
+ findConstraintsFor ( constriants , {
67
+ type : 'lib' ,
68
+ name : 'someLib' ,
69
+ data : { root : '.' , files : [ ] , tags : [ 'b' ] } ,
70
+ } )
71
+ ) . toEqual ( [
72
+ { sourceTag : '/^b$/' , onlyDependOnLibsWithTags : [ 'c' ] } ,
73
+ { sourceTag : '/a|b/' , onlyDependOnLibsWithTags : [ 'c' ] } ,
74
+ ] ) ;
75
+ expect (
76
+ findConstraintsFor ( constriants , {
77
+ type : 'lib' ,
78
+ name : 'someLib' ,
79
+ data : { root : '.' , files : [ ] , tags : [ 'baz' ] } ,
80
+ } )
81
+ ) . toEqual ( [ { sourceTag : '/a|b/' , onlyDependOnLibsWithTags : [ 'c' ] } ] ) ;
82
+ } ) ;
83
+ } ) ;
84
+
22
85
describe ( 'hasBannedImport' , ( ) => {
23
86
const source : ProjectGraphProjectNode = {
24
87
type : 'lib' ,
0 commit comments