Feat: Support macOS and Windows, migrate JavaScript to TypeScript (#32)

- Support macOS and Windows (Close #24 )
- Refactoring
  - Error handling
  - TypeScript
- Prettier (Close #29 )
- GHA: Add upload-artifact step for test coverage
- deps: Install husky
This commit is contained in:
Shohei Ueda
2019-09-21 10:41:21 +09:00
committed by GitHub
parent 4d54b90c0e
commit dc8541739a
24 changed files with 924 additions and 168 deletions

18
__tests__/get-os.test.ts Normal file
View File

@@ -0,0 +1,18 @@
import getOS from '../src/get-os';
describe('getOS', () => {
test('test', () => {
expect(getOS('linux')).toBe('Linux');
expect(getOS('darwin')).toBe('macOS');
expect(getOS('win32')).toBe('Windows');
});
test('test exception', () => {
// expect(() => {
// getOS("win32");
// }).toThrowError("Windows is not supported");
expect(() => {
getOS('centos');
}).toThrowError('centos is not supported');
});
});

22
__tests__/get-url.test.ts Normal file
View File

@@ -0,0 +1,22 @@
import getURL from '../src/get-url';
describe('getURL()', () => {
test('test', () => {
const baseURL =
'https://github.com/gohugoio/hugo/releases/download/v0.58.2';
const urlLinux = `${baseURL}/hugo_0.58.2_Linux-64bit.tar.gz`;
const urlLinuxExtended = `${baseURL}/hugo_extended_0.58.2_Linux-64bit.tar.gz`;
const urlMacOS = `${baseURL}/hugo_0.58.2_macOS-64bit.tar.gz`;
const urlWindows = `${baseURL}/hugo_0.58.2_Windows-64bit.zip`;
expect(getURL('Linux', 'false', '0.58.2')).toBe(urlLinux);
expect(getURL('Linux', 'true', '0.58.2')).toBe(urlLinuxExtended);
expect(getURL('macOS', 'false', '0.58.2')).toBe(urlMacOS);
expect(getURL('Windows', 'false', '0.58.2')).toBe(urlWindows);
});
// test("test exception", () => {
// expect(() => {
// getURL("Linux", "hoge", "0.58.2");
// }).toThrowError("Invalid input (extended): hoge");
// });
});

View File

@@ -1,23 +0,0 @@
const wait = require('./wait');
const process = require('process');
const cp = require('child_process');
const path = require('path');
test('throws invalid number', async() => {
await expect(wait('foo')).rejects.toThrow('milleseconds not a number');
});
test('wait 500 ms', async() => {
const start = new Date();
await wait(500);
const end = new Date();
var delta = Math.abs(end - start);
expect(delta).toBeGreaterThan(450);
});
// shows how the runner will run a javascript action with env / stdout protocol
test('test runs', () => {
process.env['INPUT_MILLISECONDS'] = 500;
const ip = path.join(__dirname, 'index.js');
console.log(cp.execSync(`node ${ip}`).toString());
})