From f31f1822afab896ba077fe07da245c3e267f0b47 Mon Sep 17 00:00:00 2001 From: Thai Pangsakulyanont Date: Wed, 17 Jul 2019 23:25:56 +0700 Subject: [PATCH] Fix mock file not saved --- src/TodoActionsMain.test.ts | 5 +++++ src/__mocks__/CodeRepository.ts | 13 +++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/TodoActionsMain.test.ts b/src/TodoActionsMain.test.ts index 8e35994..2b409fc 100644 --- a/src/TodoActionsMain.test.ts +++ b/src/TodoActionsMain.test.ts @@ -45,6 +45,11 @@ it('works', async () => { 'Somebody once told me', ]) + // Idempotent check + await runMain() + expect(world.commits.length).toEqual(2) + expect(world.tasks.length).toEqual(2) + // Round 2: Arrange const task1 = world.tasks.find(t => t.title === 'Hello world')! const task2 = world.tasks.find(t => t.title === 'Somebody once told me')! diff --git a/src/__mocks__/CodeRepository.ts b/src/__mocks__/CodeRepository.ts index d619f3e..7f8e450 100644 --- a/src/__mocks__/CodeRepository.ts +++ b/src/__mocks__/CodeRepository.ts @@ -10,19 +10,16 @@ export const repoContext: Real['repoContext'] = { } export const scanCodeRepository: Real['scanCodeRepository'] = async () => { + const files = [...mockWorld.files.values()] return { - files: [...mockWorld.files.values()], + files: files, isOnDefaultBranch: mockWorld.branch === repoContext.defaultBranch, async saveChanges(commitMessage) { - if (![...mockWorld.files.values()].some(f => f.contents.changed)) return + if (!files.some(f => f.contents.changed)) return + files.forEach(f => f.save()) mockWorld.commits.push({ message: commitMessage, - files: new Map( - [...mockWorld.files.values()].map(f => [ - f.fileName, - f.contents.toString(), - ]), - ), + files: new Map(files.map(f => [f.fileName, f.contents.toString()])), }) }, }