From 7e28c861a8e3d117df4626473757424ae095673d Mon Sep 17 00:00:00 2001 From: Webber Date: Sun, 27 Mar 2022 01:31:06 +0100 Subject: [PATCH] fix: early restore call --- src/model/system.integration.test.ts | 46 ++++++++++++++++++++++++++++ src/model/system.test.ts | 31 ------------------- 2 files changed, 46 insertions(+), 31 deletions(-) create mode 100644 src/model/system.integration.test.ts diff --git a/src/model/system.integration.test.ts b/src/model/system.integration.test.ts new file mode 100644 index 00000000..4d452fd1 --- /dev/null +++ b/src/model/system.integration.test.ts @@ -0,0 +1,46 @@ +import * as core from '@actions/core'; +import System from './system'; + +jest.spyOn(core, 'debug').mockImplementation(() => {}); +jest.spyOn(core, 'info').mockImplementation(() => {}); +jest.spyOn(core, 'warning').mockImplementation(() => {}); +jest.spyOn(core, 'error').mockImplementation(() => {}); + +afterEach(() => jest.clearAllMocks()); + +describe('System', () => { + describe('run', () => { + /** + * Not all shells (e.g. Powershell, sh) have a reference to `echo` binary (absent or alias). + * To ensure our integration with '@actions/exec' works as expected we run some specific tests in CI only + */ + describe('integration', () => { + if (!process.env.CI) { + it("doesn't run locally", () => { + expect(true).toBe(true); + }); + } else { + it('runs a command successfully', async () => { + await expect(System.run('true')).resolves.not.toBeNull(); + }); + + it('outputs results', async () => { + await expect(System.run('echo test')).resolves.toStrictEqual('test\n'); + }); + + it('throws on when error code is not 0', async () => { + await expect(System.run('false')).rejects.toThrowError(); + }); + + it('allows pipes using buffer', async () => { + await expect( + System.run('sh', undefined, { + input: Buffer.from('git tag --list --merged HEAD | grep v[0-9]* | wc -l'), + // eslint-disable-next-line github/no-then + }).then((result) => Number(result)), + ).resolves.not.toBeNaN(); + }); + } + }); + }); +}); diff --git a/src/model/system.test.ts b/src/model/system.test.ts index 2d2c2b84..b65ca6df 100644 --- a/src/model/system.test.ts +++ b/src/model/system.test.ts @@ -42,36 +42,5 @@ describe('System', () => { expect(info).toHaveBeenLastCalledWith('foo-bar'); }); }); - - /** - * Not all shells (e.g. Powershell, sh) have a reference to `echo` binary (absent or alias). - * To ensure our integration with '@actions/exec' works as expected we run some specific tests in CI only - */ - if (process.env.CI) { - describe('integration', () => { - execSpy.mockRestore(); - - it('runs a command successfully', async () => { - await expect(System.run('true')).resolves.not.toBeNull(); - }); - - it('outputs results', async () => { - await expect(System.run('echo test')).resolves.toStrictEqual('test\n'); - }); - - it('throws on when error code is not 0', async () => { - await expect(System.run('false')).rejects.toThrowError(); - }); - - it('allows pipes using buffer', async () => { - await expect( - System.run('sh', undefined, { - input: Buffer.from('git tag --list --merged HEAD | grep v[0-9]* | wc -l'), - // eslint-disable-next-line github/no-then - }).then((result) => Number(result)), - ).resolves.not.toBeNaN(); - }); - }); - } }); });