@@ -14,7 +14,8 @@ describe('astgen basic functionality', () => {
1414 type : "js" ,
1515 output : path . join ( tmpDir , "ast_out" ) ,
1616 recurse : true ,
17- tsTypes : true
17+ tsTypes : true ,
18+ "exclude-file" : [ ]
1819 } ) ;
1920 const resultAst = fs . readFileSync ( path . join ( tmpDir , "ast_out" , "main.js.json" ) ) . toString ( ) ;
2021 expect ( resultAst ) . toContain ( "\"fullName\":\"" + testFile . replaceAll ( "\\" , "\\\\" ) + "\"" ) ;
@@ -24,4 +25,111 @@ describe('astgen basic functionality', () => {
2425
2526 fs . rmSync ( tmpDir , { recursive : true } ) ;
2627 } ) ;
28+
29+ it ( 'should exclude files by relative file path correctly' , async ( ) => {
30+ const tmpDir : string = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "astgen-tests" ) ) ;
31+ const testFile = path . join ( tmpDir , "main.js" ) ;
32+ fs . writeFileSync ( testFile , "console.log(\"Hello, world!\");" ) ;
33+ await start ( {
34+ src : tmpDir ,
35+ type : "js" ,
36+ output : path . join ( tmpDir , "ast_out" ) ,
37+ recurse : true ,
38+ tsTypes : false ,
39+ "exclude-file" : [ "main.js" ]
40+ } ) ;
41+ expect ( fs . existsSync ( path . join ( tmpDir , "ast_out" , "main.js.json" ) ) ) . toBeFalsy ( )
42+
43+ fs . rmSync ( tmpDir , { recursive : true } ) ;
44+ } ) ;
45+
46+ it ( 'should exclude files by absolute file path correctly' , async ( ) => {
47+ const tmpDir : string = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "astgen-tests" ) ) ;
48+ const testFile = path . join ( tmpDir , "main.js" ) ;
49+ fs . writeFileSync ( testFile , "console.log(\"Hello, world!\");" ) ;
50+ await start ( {
51+ src : tmpDir ,
52+ type : "js" ,
53+ output : path . join ( tmpDir , "ast_out" ) ,
54+ recurse : true ,
55+ tsTypes : false ,
56+ "exclude-file" : [ testFile ]
57+ } ) ;
58+ expect ( fs . existsSync ( path . join ( tmpDir , "ast_out" , "main.js.json" ) ) ) . toBeFalsy ( )
59+
60+ fs . rmSync ( tmpDir , { recursive : true } ) ;
61+ } ) ;
62+
63+ it ( 'should exclude files by relative file path with dir correctly' , async ( ) => {
64+ const tmpDir : string = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "astgen-tests" ) ) ;
65+ const testFile = path . join ( tmpDir , "src" , "main.js" ) ;
66+ fs . mkdirSync ( path . join ( tmpDir , "src" ) )
67+ fs . writeFileSync ( testFile , "console.log(\"Hello, world!\");" ) ;
68+ await start ( {
69+ src : tmpDir ,
70+ type : "js" ,
71+ output : path . join ( tmpDir , "ast_out" ) ,
72+ recurse : true ,
73+ tsTypes : false ,
74+ "exclude-file" : [ path . join ( "src" , "main.js" ) ]
75+ } ) ;
76+ expect ( fs . existsSync ( path . join ( tmpDir , "ast_out" , "src" , "main.js.json" ) ) ) . toBeFalsy ( )
77+
78+ fs . rmSync ( tmpDir , { recursive : true } ) ;
79+ } ) ;
80+
81+ it ( 'should exclude files by relative dir path correctly' , async ( ) => {
82+ const tmpDir : string = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "astgen-tests" ) ) ;
83+ const testFile = path . join ( tmpDir , "src" , "main.js" ) ;
84+ fs . mkdirSync ( path . join ( tmpDir , "src" ) )
85+ fs . writeFileSync ( testFile , "console.log(\"Hello, world!\");" ) ;
86+ await start ( {
87+ src : tmpDir ,
88+ type : "js" ,
89+ output : path . join ( tmpDir , "ast_out" ) ,
90+ recurse : true ,
91+ tsTypes : false ,
92+ "exclude-file" : [ "src" ]
93+ } ) ;
94+ expect ( fs . existsSync ( path . join ( tmpDir , "ast_out" , "src" , "main.js.json" ) ) ) . toBeFalsy ( )
95+
96+ fs . rmSync ( tmpDir , { recursive : true } ) ;
97+ } ) ;
98+
99+ it ( 'should exclude files by absolute dir path correctly' , async ( ) => {
100+ const tmpDir : string = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "astgen-tests" ) ) ;
101+ const testFile = path . join ( tmpDir , "src" , "main.js" ) ;
102+ fs . mkdirSync ( path . join ( tmpDir , "src" ) )
103+ fs . writeFileSync ( testFile , "console.log(\"Hello, world!\");" ) ;
104+ await start ( {
105+ src : tmpDir ,
106+ type : "js" ,
107+ output : path . join ( tmpDir , "ast_out" ) ,
108+ recurse : true ,
109+ tsTypes : false ,
110+ "exclude-file" : [ path . join ( tmpDir , "src" ) ]
111+ } ) ;
112+ expect ( fs . existsSync ( path . join ( tmpDir , "ast_out" , "main.js.json" ) ) ) . toBeFalsy ( )
113+
114+ fs . rmSync ( tmpDir , { recursive : true } ) ;
115+ } ) ;
116+
117+ it ( 'should exclude files by regex correctly' , async ( ) => {
118+ const tmpDir : string = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "astgen-tests" ) ) ;
119+ const testFile = path . join ( tmpDir , "main.js" ) ;
120+ fs . writeFileSync ( testFile , "console.log(\"Hello, world!\");" ) ;
121+ await start ( {
122+ src : tmpDir ,
123+ type : "js" ,
124+ output : path . join ( tmpDir , "ast_out" ) ,
125+ recurse : true ,
126+ tsTypes : false ,
127+ "exclude-file" : [ ] ,
128+ "exclude-regex" : new RegExp ( ".*main.*" , "i" )
129+ } ) ;
130+ expect ( fs . existsSync ( path . join ( tmpDir , "ast_out" , "main.js.json" ) ) ) . toBeFalsy ( )
131+
132+ fs . rmSync ( tmpDir , { recursive : true } ) ;
133+ } ) ;
134+
27135} ) ;
0 commit comments