@@ -5,13 +5,11 @@ import { suite, type BaseTest } from '../suite';
5
5
import { read_file } from '../helpers.js' ;
6
6
7
7
interface CompilerErrorTest extends BaseTest {
8
- error :
9
- | {
10
- code : string ;
11
- message : string ;
12
- position ?: [ number , number ] ;
13
- }
14
- | false ;
8
+ error : {
9
+ code : string ;
10
+ message : string ;
11
+ position ?: [ number , number ] ;
12
+ } ;
15
13
}
16
14
17
15
const { test, run } = suite < CompilerErrorTest > ( ( config , cwd ) => {
@@ -20,56 +18,52 @@ const { test, run } = suite<CompilerErrorTest>((config, cwd) => {
20
18
}
21
19
22
20
if ( fs . existsSync ( `${ cwd } /main.svelte` ) ) {
23
- let caught_error : CompileError | null = null ;
21
+ let caught_error = false ;
24
22
25
23
try {
26
24
compile ( read_file ( `${ cwd } /main.svelte` ) , {
27
25
generate : 'client'
28
26
} ) ;
29
27
} catch ( e ) {
30
- caught_error = e as CompileError ;
28
+ const error = e as CompileError ;
31
29
32
- if ( config . error ) {
33
- expect ( caught_error . code ) . toBe ( config . error . code ) ;
34
- expect ( caught_error . message ) . toBe ( config . error . message ) ;
30
+ caught_error = true ;
35
31
36
- if ( config . error . position ) {
37
- expect ( caught_error . position ) . toEqual ( config . error . position ) ;
38
- }
32
+ expect ( error . code ) . toBe ( config . error . code ) ;
33
+ expect ( error . message ) . toBe ( config . error . message ) ;
34
+
35
+ if ( config . error . position ) {
36
+ expect ( error . position ) . toEqual ( config . error . position ) ;
39
37
}
40
38
}
41
39
42
- if ( config . error && caught_error == null ) {
40
+ if ( ! caught_error ) {
43
41
assert . fail ( 'Expected an error' ) ;
44
- } else if ( ! config . error && caught_error != null ) {
45
- assert . fail ( `Unexpected error: ${ caught_error . code } ` ) ;
46
42
}
47
43
}
48
44
49
45
if ( fs . existsSync ( `${ cwd } /main.svelte.js` ) ) {
50
- let caught_error : CompileError | null = null ;
46
+ let caught_error = false ;
51
47
52
48
try {
53
49
compileModule ( read_file ( `${ cwd } /main.svelte.js` ) , {
54
50
generate : 'client'
55
51
} ) ;
56
52
} catch ( e ) {
57
- caught_error = e as CompileError ;
53
+ const error = e as CompileError ;
54
+
55
+ caught_error = true ;
58
56
59
- if ( config . error ) {
60
- expect ( caught_error . code ) . toEqual ( config . error . code ) ;
61
- expect ( caught_error . message ) . toEqual ( config . error . message ) ;
57
+ expect ( error . code ) . toEqual ( config . error . code ) ;
58
+ expect ( error . message ) . toEqual ( config . error . message ) ;
62
59
63
- if ( config . error . position ) {
64
- expect ( caught_error . position ) . toEqual ( config . error . position ) ;
65
- }
60
+ if ( config . error . position ) {
61
+ expect ( error . position ) . toEqual ( config . error . position ) ;
66
62
}
67
63
}
68
64
69
- if ( config . error && caught_error == null ) {
65
+ if ( ! caught_error ) {
70
66
assert . fail ( 'Expected an error' ) ;
71
- } else if ( ! config . error && caught_error != null ) {
72
- assert . fail ( `Unexpected error: ${ caught_error . code } ` ) ;
73
67
}
74
68
}
75
69
} ) ;
0 commit comments