diff --git a/packages/amplify-dynamodb-simulator/__test__/index.test.js b/packages/amplify-dynamodb-simulator/__test__/index.test.js index 26a264c375a..3dba263cbdd 100644 --- a/packages/amplify-dynamodb-simulator/__test__/index.test.js +++ b/packages/amplify-dynamodb-simulator/__test__/index.test.js @@ -39,19 +39,26 @@ describe('emulator operations', () => { const ensureNoDbPath = () => { if (fs.existsSync(dbPath)) { - fs.removeSync(dbPath); + try { + fs.removeSync(dbPath); + } + catch(err) { + console.log(err); + } } }; - beforeEach(ensureNoDbPath); - afterEach(ensureNoDbPath); - let emulators; - beforeEach(() => { + beforeEach(async () => { + ensureNoDbPath(); emulators = []; jest.setTimeout(40 * 1000); }); - afterEach(async () => await Promise.all(emulators.map(emu => emu.terminate()))); + + afterEach(async () => { + await Promise.all(emulators.map(emu => emu.terminate())); + ensureNoDbPath(); + }); it('should support in memory operations', async () => { const emu = await ddbSimulator.launch(); @@ -73,7 +80,7 @@ describe('emulator operations', () => { }) .promise(); await emuOne.terminate(); - + emulators = []; const emuTwo = await ddbSimulator.launch({ dbPath }); emulators.push(emuTwo); const dynamoTwo = await ddbSimulator.getClient(emuTwo); @@ -81,7 +88,6 @@ describe('emulator operations', () => { expect(t).toEqual({ TableNames: ['foo'], }); - emuTwo.terminate(); }); it('should start on specific port', async () => {