From 1464a66be9f42faba1ef4c0609c1a11e6215b3e9 Mon Sep 17 00:00:00 2001 From: Jake Bentvelzen Date: Thu, 24 Jan 2019 15:39:46 +1100 Subject: [PATCH] fix: add test to check if stashing is skipped if no lint-staged files are changed (#570) --- test/__snapshots__/runAll.spec.js.snap | 2 ++ test/runAll.spec.js | 27 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/test/__snapshots__/runAll.spec.js.snap b/test/__snapshots__/runAll.spec.js.snap index 6f20b5ec5..2277b352d 100644 --- a/test/__snapshots__/runAll.spec.js.snap +++ b/test/__snapshots__/runAll.spec.js.snap @@ -83,6 +83,8 @@ LOG Running tasks for *.js [completed] LOG Running linters... [completed]" `; +exports[`runAll should skip stashing changes if no lint-staged files are changed 1`] = `""`; + exports[`runAll should skip updating stash if there are errors during linting 1`] = ` " LOG Stashing changes... [started] diff --git a/test/runAll.spec.js b/test/runAll.spec.js index 375f4426f..f1bf96103 100644 --- a/test/runAll.spec.js +++ b/test/runAll.spec.js @@ -161,4 +161,31 @@ describe('runAll', () => { expect(err).toEqual('test') } }) + + it.only('should skip stashing changes if no lint-staged files are changed', async () => { + expect.assertions(4) + hasPartiallyStagedFiles.mockImplementationOnce(() => Promise.resolve(true)) + sgfMock.mockImplementationOnce((params, callback) => { + callback(null, [{ filename: 'sample.java', status: 'Modified' }]) + }) + execa.mockImplementationOnce(() => + Promise.resolve({ + stdout: '', + stderr: 'Linter finished with error', + code: 1, + failed: true, + cmd: 'mock cmd' + }) + ) + + try { + await runAll(getConfig({ linters: { '*.js': ['echo "sample"'] } })) + } catch (err) { + console.log(err) + } + expect(console.printHistory()).toMatchSnapshot() + expect(gitStashSave).toHaveBeenCalledTimes(0) + expect(updateStash).toHaveBeenCalledTimes(0) + expect(gitStashPop).toHaveBeenCalledTimes(0) + }) })