From ba5472c7e250fb7c17ff3e25061da8b275a31e70 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 26 Nov 2020 19:25:23 +0100 Subject: [PATCH] chore(cli-repl): use separate tmpdir for userId persistence test With a similar purpose like https://github.com/mongodb-js/mongosh/pull/449. --- packages/cli-repl/src/cli-repl.spec.ts | 3 --- packages/cli-repl/test/repl-helpers.ts | 8 +++++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/cli-repl/src/cli-repl.spec.ts b/packages/cli-repl/src/cli-repl.spec.ts index 71dcdecaab..789d861af6 100644 --- a/packages/cli-repl/src/cli-repl.spec.ts +++ b/packages/cli-repl/src/cli-repl.spec.ts @@ -1,9 +1,7 @@ import { PassThrough, Duplex } from 'stream'; -import { promisify } from 'util'; import path from 'path'; import { promises as fs } from 'fs'; import { once } from 'events'; -import rimraf from 'rimraf'; import CliRepl, { CliReplOptions } from './cli-repl'; import { startTestServer } from '../../../testing/integration-testing-hooks'; import { expect, useTmpdir, waitEval, fakeTTYProps } from '../test/repl-helpers'; @@ -75,7 +73,6 @@ describe('CliRepl', () => { context('during startup', () => { it('persists userId', async() => { const userIds: string[] = []; - await promisify(rimraf)(tmpdir.path); for (let i = 0; i < 2; i++) { cliRepl = new CliRepl(cliReplOptions); cliRepl.bus.on('mongosh:new-user', userId => userIds.push(userId)); diff --git a/packages/cli-repl/test/repl-helpers.ts b/packages/cli-repl/test/repl-helpers.ts index 87e8ff51ca..44aaffbdbf 100644 --- a/packages/cli-repl/test/repl-helpers.ts +++ b/packages/cli-repl/test/repl-helpers.ts @@ -22,7 +22,13 @@ function useTmpdir(): { readonly path: string } { }); afterEach(async() => { - promisify(rimraf)(tmpdir); + try { + await promisify(rimraf)(tmpdir); + } catch (err) { + // On Windows in CI, this can fail with EPERM for some reason. + // If it does, just log the error instead of failing all tests. + console.error('Could not remove fake home directory:', err); + } }); return {