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';
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);
});
});

View file

@ -13,29 +13,28 @@ export async function showVersion(
cmd: string,
args: string[]
): Promise<ActionResult> {
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<ActionResult> {