1
1
use std:: path:: PathBuf ;
2
2
3
3
use swc_ecma_parser:: TsSyntax ;
4
- use swc_fast_ts_strip:: { operate, Options } ;
4
+ use swc_fast_ts_strip:: { operate, Mode , Options } ;
5
5
use testing:: NormalizedOutput ;
6
6
7
7
#[ testing:: fixture( "tests/fixture/**/*.ts" ) ]
8
8
fn test ( input : PathBuf ) {
9
9
let input_code = std:: fs:: read_to_string ( & input) . unwrap ( ) ;
10
10
let output_file = input. with_extension ( "js" ) ;
11
+ let transform_output_file = input. with_file_name ( "output.transform.js" ) ;
11
12
12
13
testing:: run_test ( false , |cm, handler| {
13
- let code = operate ( & cm, handler, input_code, opts ( ) )
14
+ let code = operate ( & cm, handler, input_code. clone ( ) , opts ( Mode :: StripOnly ) )
14
15
. expect ( "should not return Err()" )
15
16
. code ;
16
17
@@ -21,6 +22,19 @@ fn test(input: PathBuf) {
21
22
Ok ( ( ) )
22
23
} )
23
24
. expect ( "should not fail" ) ;
25
+
26
+ testing:: run_test ( false , |cm, handler| {
27
+ let code = operate ( & cm, handler, input_code, opts ( Mode :: Transform ) )
28
+ . expect ( "should not return Err()" )
29
+ . code ;
30
+
31
+ NormalizedOutput :: new_raw ( code)
32
+ . compare_to_file ( transform_output_file)
33
+ . unwrap ( ) ;
34
+
35
+ Ok ( ( ) )
36
+ } )
37
+ . expect ( "should not fail" ) ;
24
38
}
25
39
26
40
#[ testing:: fixture( "tests/errors/**/*.ts" ) ]
@@ -29,7 +43,7 @@ fn error(input: PathBuf) {
29
43
let output_file = input. with_extension ( "swc-stderr" ) ;
30
44
31
45
testing:: run_test ( false , |cm, handler| {
32
- operate ( & cm, handler, input_code, opts ( ) ) . expect ( "should not return Err()" ) ;
46
+ operate ( & cm, handler, input_code, opts ( Mode :: StripOnly ) ) . expect ( "should not return Err()" ) ;
33
47
34
48
Err :: < ( ) , _ > ( ( ) )
35
49
} )
@@ -38,14 +52,15 @@ fn error(input: PathBuf) {
38
52
. unwrap ( ) ;
39
53
}
40
54
41
- fn opts ( ) -> Options {
55
+ fn opts ( mode : Mode ) -> Options {
42
56
Options {
43
57
module : None ,
44
58
filename : None ,
45
59
parser : TsSyntax {
46
60
decorators : true ,
47
61
..Default :: default ( )
48
62
} ,
63
+ mode,
49
64
..Default :: default ( )
50
65
}
51
66
}
0 commit comments