Skip to content

Commit 6cb6791

Browse files
authored
Merge pull request #389 from DevCycleHQ/use-rootdir
use rootDir instead of cwd for globalConfig location
2 parents 5e662af + 7ce2da0 commit 6cb6791

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/environment.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ const uuid = require('uuid');
1111
// eslint-disable-next-line import/order
1212
const debug = require('debug')('jest-mongodb:environment');
1313

14-
const cwd = process.cwd();
15-
16-
const globalConfigPath = pathJoin(cwd, 'globalConfig.json');
1714
const options = getMongodbMemoryOptions();
1815
const isReplSet = Boolean(options.replSet);
1916

@@ -22,14 +19,16 @@ debug(`isReplSet`, isReplSet);
2219
const mongo = isReplSet ? new MongoMemoryReplSet(options) : new MongoMemoryServer(options);
2320

2421
module.exports = class MongoEnvironment extends TestEnvironment {
22+
globalConfigPath: string
2523
constructor(config: JestEnvironmentConfig, context: EnvironmentContext) {
2624
super(config, context);
25+
this.globalConfigPath = pathJoin(config.projectConfig.rootDir, 'globalConfig.json');
2726
}
2827

2928
async setup() {
3029
debug('Setup MongoDB Test Environment');
3130

32-
const globalConfig = JSON.parse(readFileSync(globalConfigPath, 'utf-8'));
31+
const globalConfig = JSON.parse(readFileSync(this.globalConfigPath, 'utf-8'));
3332

3433
if (globalConfig.mongoUri) {
3534
this.global.__MONGO_URI__ = globalConfig.mongoUri;

src/setup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
shouldUseSharedDBForAllJestWorkers,
99
} from './helpers';
1010
import type {Mongo} from './types';
11+
import type { JestEnvironmentConfig } from '@jest/environment'
1112

1213
const debug = require('debug')('jest-mongodb:setup');
1314
const mongoMemoryServerOptions = getMongodbMemoryOptions();
@@ -20,10 +21,9 @@ const mongo: Mongo = isReplSet
2021
? new MongoMemoryReplSet(mongoMemoryServerOptions)
2122
: new MongoMemoryServer(mongoMemoryServerOptions);
2223

23-
const cwd = process.cwd();
24-
const globalConfigPath = join(cwd, 'globalConfig.json');
24+
module.exports = async (config: JestEnvironmentConfig['projectConfig']) => {
25+
const globalConfigPath = join(config.rootDir, 'globalConfig.json');
2526

26-
module.exports = async () => {
2727
const options = getMongodbMemoryOptions();
2828
const mongoConfig: {mongoUri?: string; mongoDBName?: string} = {};
2929

src/teardown.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {join} from 'path';
22
import {unlink} from 'fs';
3+
import type { JestEnvironmentConfig } from '@jest/environment'
34

45
const debug = require('debug')('jest-mongodb:teardown');
56

6-
const cwd = process.cwd();
7-
const globalConfigPath = join(cwd, 'globalConfig.json');
7+
module.exports = async function (config: JestEnvironmentConfig['projectConfig']) {
8+
const globalConfigPath = join(config.rootDir, 'globalConfig.json');
89

9-
module.exports = async function () {
1010
debug('Teardown mongod');
1111
if (global.__MONGOD__) {
1212
await global.__MONGOD__.stop();

0 commit comments

Comments
 (0)