refactor: Fix lint errors

This commit is contained in:
peaceiris 2020-01-17 22:07:19 +00:00
parent 86d998acdc
commit ac375e4950
2 changed files with 22 additions and 26 deletions

View file

@ -1,11 +1,11 @@
import * as main from '../src/main'; import * as main from '../src/main';
const nock = require('nock'); import nock from 'nock';
// import {FetchError} from 'node-fetch'; // import {FetchError} from 'node-fetch';
import jsonTestBrew from './data/brew.json'; import jsonTestBrew from './data/brew.json';
// import jsonTestGithub from './data/github.json'; // import jsonTestGithub from './data/github.json';
jest.setTimeout(30000); jest.setTimeout(30000);
const repo: string = 'hugo'; const repo = 'hugo';
beforeEach(() => { beforeEach(() => {
jest.resetModules(); jest.resetModules();
@ -18,7 +18,7 @@ afterEach(() => {
describe('Integration testing run()', () => { describe('Integration testing run()', () => {
test('succeed in installing a custom version', async () => { 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; process.env['INPUT_HUGO-VERSION'] = testVersion;
const result: main.ActionResult = await main.run(); const result: main.ActionResult = await main.run();
expect(result.exitcode).toBe(0); expect(result.exitcode).toBe(0);
@ -26,7 +26,7 @@ describe('Integration testing run()', () => {
}); });
test('succeed in installing the latest version', async () => { test('succeed in installing the latest version', async () => {
const testVersion: string = 'latest'; const testVersion = 'latest';
process.env['INPUT_HUGO-VERSION'] = testVersion; process.env['INPUT_HUGO-VERSION'] = testVersion;
nock('https://formulae.brew.sh') nock('https://formulae.brew.sh')
.get(`/api/formula/${repo}.json`) .get(`/api/formula/${repo}.json`)
@ -49,11 +49,8 @@ describe('showVersion()', () => {
expect(result.output).toMatch(/git version/); expect(result.output).toMatch(/git version/);
}); });
test('return exception', async () => { test('return not found', async () => {
try { result = await main.showVersion('gitgit', ['--version']);
result = await main.showVersion('gitgit', ['--version']); expect(result.exitcode).not.toBe(0);
} catch (e) {
expect(e).toThrow(Error);
}
}); });
}); });

View file

@ -13,29 +13,28 @@ export async function showVersion(
cmd: string, cmd: string,
args: string[] args: string[]
): Promise<ActionResult> { ): Promise<ActionResult> {
try { const result: ActionResult = {
const result: ActionResult = { exitcode: 0,
exitcode: 0, output: ''
output: '' };
};
const options = { const options = {
listeners: { listeners: {
stdout: (data: Buffer): void => { stdout: (data: Buffer): void => {
result.output += data.toString(); result.output += data.toString();
}
} }
}; }
};
try {
result.exitcode = await exec.exec(cmd, args, options); result.exitcode = await exec.exec(cmd, args, options);
core.debug(`
exit code: ${result.exitcode}
stdout: ${result.output}
`);
return result;
} catch (e) { } catch (e) {
return 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<ActionResult> { export async function run(): Promise<ActionResult> {