Skip to content

Commit

Permalink
fix(DryMongoBinary): use "INIT_CWD" when available
Browse files Browse the repository at this point in the history
fixes #478
  • Loading branch information
hasezoey committed Jun 2, 2021
1 parent 1d7d304 commit cc2da32
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ export class DryMongoBinary {
// Assign "node_modules/.cache" to modulesCache

// if we're in postinstall script, npm will set the cwd too deep
let nodeModulesDLDir = process.cwd();
while (nodeModulesDLDir.endsWith(`node_modules${path.sep}mongodb-memory-server`)) {
// when in postinstall, npm will provide an "INIT_CWD" env variable
let nodeModulesDLDir = process.env['INIT_CWD'] || process.cwd();
// as long as "node_modules/mongodb-memory-server*" is included in the path, go the paths up
while (nodeModulesDLDir.includes(`node_modules${path.sep}mongodb-memory-server`)) {
nodeModulesDLDir = path.resolve(nodeModulesDLDir, '..', '..');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('DryBinary', () => {
let binaryName: string;
beforeAll(async () => {
delete process.env[envName(ResolveConfigVariables.DOWNLOAD_DIR)]; // i dont know where this comes from, but without it, this property exists
process.env['INIT_CWD'] = undefined; // removing this, because it would mess with stuff - but still should be used when available (postinstall)
tmpDir = tmp.dirSync({ prefix: 'mongo-mem-drybinGP-', unsafeCleanup: true });
tmpDir2 = tmp.dirSync({ prefix: 'mongo-mem-drybinGP-', unsafeCleanup: true });
jest
Expand Down

0 comments on commit cc2da32

Please sign in to comment.