1- const { TestEnvironment} = require ( 'jest-environment-node' ) ;
2- const path = require ( 'path' ) ;
3- const fs = require ( 'fs' ) ;
1+ import { TestEnvironment } from 'jest-environment-node' ;
2+ import { join as pathJoin } from 'path' ;
3+ import { readFileSync } from 'fs' ;
4+ import type { EnvironmentContext } from '@jest/environment' ;
5+ import type { JestEnvironmentConfig } from '@jest/environment' ;
6+ import { MongoMemoryReplSet , MongoMemoryServer } from 'mongodb-memory-server' ;
7+ import { getMongodbMemoryOptions } from './helpers' ;
8+
49const uuid = require ( 'uuid' ) ;
5- const { MongoMemoryServer, MongoMemoryReplSet} = require ( 'mongodb-memory-server' ) ;
6- const { getMongodbMemoryOptions} = require ( './helpers' ) ;
710
11+ // eslint-disable-next-line import/order
812const debug = require ( 'debug' ) ( 'jest-mongodb:environment' ) ;
913
1014const cwd = process . cwd ( ) ;
1115
12- const globalConfigPath = path . join ( cwd , 'globalConfig.json' ) ;
16+ const globalConfigPath = pathJoin ( cwd , 'globalConfig.json' ) ;
1317const options = getMongodbMemoryOptions ( ) ;
1418const isReplSet = Boolean ( options . replSet ) ;
1519
1620debug ( `isReplSet` , isReplSet ) ;
1721
18- let mongo = isReplSet ? new MongoMemoryReplSet ( options ) : new MongoMemoryServer ( options ) ;
22+ const mongo = isReplSet ? new MongoMemoryReplSet ( options ) : new MongoMemoryServer ( options ) ;
1923
2024module . exports = class MongoEnvironment extends TestEnvironment {
21- constructor ( config , context ) {
25+ constructor ( config : JestEnvironmentConfig , context : EnvironmentContext ) {
2226 super ( config , context ) ;
2327 }
2428
2529 async setup ( ) {
2630 debug ( 'Setup MongoDB Test Environment' ) ;
2731
28- const globalConfig = JSON . parse ( fs . readFileSync ( globalConfigPath , 'utf-8' ) ) ;
32+ const globalConfig = JSON . parse ( readFileSync ( globalConfigPath , 'utf-8' ) ) ;
2933
3034 if ( globalConfig . mongoUri ) {
3135 this . global . __MONGO_URI__ = globalConfig . mongoUri ;
@@ -48,7 +52,9 @@ module.exports = class MongoEnvironment extends TestEnvironment {
4852 await super . teardown ( ) ;
4953 }
5054
55+ // @ts -ignore
5156 runScript ( script ) {
57+ // @ts -ignore
5258 return super . runScript ( script ) ;
5359 }
5460} ;
0 commit comments