File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ const { createStrapi, compileStrapi } = require ( "@strapi/strapi" ) ;
2+ const fs = require ( "fs" ) ;
3+
4+ let instance ;
5+
6+ /**
7+ * Setups strapi for futher testing
8+ */
9+ async function setupStrapi ( ) {
10+ if ( ! instance ) {
11+ const app = await createStrapi ( {
12+ appDir : "./playground" ,
13+ distDir : "./playground/dist" ,
14+ } ) . load ( ) ;
15+
16+ instance = app ; // strapi is global now
17+
18+ await instance . server . mount ( ) ;
19+ }
20+ return instance ;
21+ }
22+
23+ /**
24+ * Closes strapi after testing
25+ */
26+ async function stopStrapi ( ) {
27+ if ( instance ) {
28+ await instance . server . httpServer . close ( ) ;
29+ await instance . db . connection . destroy ( ) ;
30+ instance . destroy ( ) ;
31+ const tmpDbFile = strapi . config . get (
32+ "database.connection.connection.filename"
33+ ) ;
34+
35+ if ( fs . existsSync ( tmpDbFile ) ) {
36+ fs . unlinkSync ( tmpDbFile ) ;
37+ }
38+
39+ }
40+ return instance ;
41+ }
42+
43+ module . exports = {
44+ setupStrapi,
45+ stopStrapi,
46+ } ;
You can’t perform that action at this time.
0 commit comments