refactor: main and installer (#133)

* refactor: installer
* test: Fix workDir cleanup
This commit is contained in:
Shohei Ueda
2020-01-18 12:07:13 +09:00
committed by GitHub
parent 442aa4dbd4
commit 283bc47636
3 changed files with 69 additions and 47 deletions

View File

@@ -2,12 +2,12 @@ import * as main from '../src/main';
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 jsonTestBrew from './data/brew.json';
// import jsonTestGithub from './data/github.json';
jest.setTimeout(30000);
const repo = 'hugo';
beforeEach(() => {
jest.resetModules();
@@ -20,11 +20,12 @@ afterEach(() => {
describe('Integration testing run()', () => {
afterEach(async () => {
await io.rmRF(path.join(`${process.env.HOME}`, 'tmp'));
const workDir = path.join(`${process.env.HOME}`, Action.WorkDirName);
await io.rmRF(workDir);
});
test('succeed in installing a custom version', async () => {
const testVersion = '0.61.0';
const testVersion = Tool.TestVersionSpec;
process.env['INPUT_HUGO-VERSION'] = testVersion;
const result: main.ActionResult = await main.run();
expect(result.exitcode).toBe(0);
@@ -35,11 +36,13 @@ describe('Integration testing run()', () => {
const testVersion = 'latest';
process.env['INPUT_HUGO-VERSION'] = testVersion;
nock('https://formulae.brew.sh')
.get(`/api/formula/${repo}.json`)
.get(`/api/formula/${Tool.Repo}.json`)
.reply(200, jsonTestBrew);
const result: main.ActionResult = await main.run();
expect(result.exitcode).toBe(0);
expect(result.output).toMatch('Hugo Static Site Generator v0.62.2');
expect(result.output).toMatch(
`Hugo Static Site Generator v${Tool.TestVersionLatest}`
);
});
});