From 01408a6ef79f7ff6d36186937c1e436c3f29a1a8 Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Wed, 9 Oct 2019 23:17:08 -0400 Subject: [PATCH] Fix example tests (#32) --- __tests__/main.test.ts | 10 +++++++--- src/main.ts | 2 +- src/wait.ts | 8 ++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 4c437c4..6f7475e 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -4,7 +4,8 @@ import * as cp from 'child_process' import * as path from 'path' test('throws invalid number', async() => { - await expect(wait('foo')).rejects.toThrow('milleseconds not a number'); + const input = parseInt('foo', 10); + await expect(wait(input)).rejects.toThrow('milleseconds not a number'); }); test('wait 500 ms', async() => { @@ -19,5 +20,8 @@ test('wait 500 ms', async() => { test('test runs', () => { process.env['INPUT_MILLISECONDS'] = '500'; const ip = path.join(__dirname, '..', 'lib', 'main.js'); - console.log(cp.execSync(`node ${ip}`).toString()); -}) \ No newline at end of file + const options: cp.ExecSyncOptions = { + env: process.env + }; + console.log(cp.execSync(`node ${ip}`, options).toString()); +}); \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 474cb28..191f388 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,7 +7,7 @@ async function run() { console.log(`Waiting ${ms} milliseconds ...`) core.debug((new Date()).toTimeString()) - await wait(parseInt(ms)); + await wait(parseInt(ms, 10)); core.debug((new Date()).toTimeString()) core.setOutput('time', new Date().toTimeString()); diff --git a/src/wait.ts b/src/wait.ts index 3dcfbdb..9eff51f 100644 --- a/src/wait.ts +++ b/src/wait.ts @@ -1,7 +1,7 @@ -export function wait(milliseconds) { - return new Promise((resolve, reject) => { - if (typeof(milliseconds) !== 'number') { - throw new Error('milleseconds not a number'); +export function wait(milliseconds: number) { + return new Promise((resolve) => { + if (isNaN(milliseconds)) { + throw new Error('milleseconds not a number'); } setTimeout(() => resolve("done!"), milliseconds)