From ac375e49509c713559a433abd89af8b392d7527b Mon Sep 17 00:00:00 2001 From: peaceiris <30958501+peaceiris@users.noreply.github.com> Date: Fri, 17 Jan 2020 22:07:19 +0000 Subject: [PATCH] refactor: Fix lint errors --- __tests__/main.test.ts | 17 +++++++---------- src/main.ts | 31 +++++++++++++++---------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 9ac851a..fdc40fb 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -1,11 +1,11 @@ import * as main from '../src/main'; -const nock = require('nock'); +import nock from 'nock'; // import {FetchError} from 'node-fetch'; import jsonTestBrew from './data/brew.json'; // import jsonTestGithub from './data/github.json'; jest.setTimeout(30000); -const repo: string = 'hugo'; +const repo = 'hugo'; beforeEach(() => { jest.resetModules(); @@ -18,7 +18,7 @@ afterEach(() => { describe('Integration testing run()', () => { test('succeed in installing a custom version', async () => { - const testVersion: string = '0.61.0'; + const testVersion = '0.61.0'; process.env['INPUT_HUGO-VERSION'] = testVersion; const result: main.ActionResult = await main.run(); expect(result.exitcode).toBe(0); @@ -26,7 +26,7 @@ describe('Integration testing run()', () => { }); test('succeed in installing the latest version', async () => { - const testVersion: string = 'latest'; + const testVersion = 'latest'; process.env['INPUT_HUGO-VERSION'] = testVersion; nock('https://formulae.brew.sh') .get(`/api/formula/${repo}.json`) @@ -49,11 +49,8 @@ describe('showVersion()', () => { expect(result.output).toMatch(/git version/); }); - test('return exception', async () => { - try { - result = await main.showVersion('gitgit', ['--version']); - } catch (e) { - expect(e).toThrow(Error); - } + test('return not found', async () => { + result = await main.showVersion('gitgit', ['--version']); + expect(result.exitcode).not.toBe(0); }); }); diff --git a/src/main.ts b/src/main.ts index 13b31de..20dd72d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -13,29 +13,28 @@ export async function showVersion( cmd: string, args: string[] ): Promise { - try { - const result: ActionResult = { - exitcode: 0, - output: '' - }; + const result: ActionResult = { + exitcode: 0, + output: '' + }; - const options = { - listeners: { - stdout: (data: Buffer): void => { - result.output += data.toString(); - } + const options = { + listeners: { + stdout: (data: Buffer): void => { + result.output += data.toString(); } - }; + } + }; + try { result.exitcode = await exec.exec(cmd, args, options); - core.debug(` - exit code: ${result.exitcode} - stdout: ${result.output} - `); - return result; } catch (e) { return e; } + core.debug(`command: ${cmd} ${args}`); + core.debug(`exit code: ${result.exitcode}`); + core.debug(`stdout: ${result.output}`); + return result; } export async function run(): Promise {