diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 4ca1956..86a556a 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -3,25 +3,23 @@ import * as io from '@actions/io'; import path from 'path'; import nock from 'nock'; import {Tool, Action} from '../src/constants'; -// import {FetchError} from 'node-fetch'; +import {FetchError} from 'node-fetch'; import jsonTestBrew from './data/brew.json'; // import jsonTestGithub from './data/github.json'; jest.setTimeout(30000); -beforeEach(() => { - jest.resetModules(); -}); - -afterEach(() => { - delete process.env['INPUT_HUGO-VERSION']; - nock.cleanAll(); -}); - describe('Integration testing run()', () => { + beforeEach(() => { + jest.resetModules(); + }); + afterEach(async () => { const workDir = path.join(`${process.env.HOME}`, Action.WorkDirName); await io.rmRF(workDir); + + delete process.env['INPUT_HUGO-VERSION']; + nock.cleanAll(); }); test('succeed in installing a custom version', async () => { @@ -69,6 +67,15 @@ describe('Integration testing run()', () => { ); expect(result.output).toMatch(`extended`); }); + + test('fail to install the latest version due to 404 of brew', async () => { + process.env['INPUT_HUGO-VERSION'] = 'latest'; + nock('https://formulae.brew.sh') + .get(`/api/formula/${Tool.Repo}.json`) + .reply(404); + + await expect(main.run()).rejects.toThrowError(FetchError); + }); }); describe('showVersion()', () => { diff --git a/src/main.ts b/src/main.ts index 50c5170..3504783 100644 --- a/src/main.ts +++ b/src/main.ts @@ -56,6 +56,6 @@ export async function run(): Promise { return result; } catch (e) { core.setFailed(`Action failed with error ${e}`); - return e; + throw e; } }