1
+ import fs from 'node:fs' ;
2
+ import assert from 'node:assert' ;
1
3
import { createStrapi } from '@strapi/strapi' ;
2
- import fs , { PathLike } from 'fs ' ;
4
+ import type { Core } from '@strapi/types ' ;
3
5
4
- let instance ;
6
+ let instance : Core . Strapi | undefined ;
5
7
6
8
/**
7
9
* Setups strapi for futher testing
@@ -12,29 +14,31 @@ export async function setupStrapi() {
12
14
appDir : './playground' ,
13
15
distDir : './playground/dist' ,
14
16
} ) . load ( ) ;
17
+ strapi . server . mount ( ) ;
15
18
16
19
instance = strapi ; // strapi is global now
17
-
18
- await instance . server . mount ( ) ;
19
20
}
20
- return instance ;
21
21
}
22
22
23
23
/**
24
24
* Closes strapi after testing
25
25
*/
26
26
export async function stopStrapi ( ) {
27
27
if ( instance ) {
28
- await instance . server . httpServer . close ( ) ;
29
- await instance . db . connection . destroy ( ) ;
30
- instance . destroy ( ) ;
31
- const tmpDbFile = strapi . config . get (
28
+ const tmpDbFile = instance . config . get (
32
29
'database.connection.connection.filename' ,
33
30
) ;
34
31
35
- if ( fs . existsSync ( tmpDbFile as PathLike ) ) {
36
- fs . unlinkSync ( tmpDbFile as PathLike ) ;
32
+ assert ( typeof tmpDbFile === 'string' ) ;
33
+
34
+ instance . server . httpServer . close ( ) ;
35
+ await instance . db . connection . destroy ( ) ;
36
+ await instance . destroy ( ) ;
37
+
38
+ if ( fs . existsSync ( tmpDbFile ) ) {
39
+ fs . unlinkSync ( tmpDbFile ) ;
37
40
}
41
+
42
+ instance = undefined ;
38
43
}
39
- return instance ;
40
44
}
0 commit comments