From 5f31b6acfcfd59b296734c6dd5521ff670045356 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 17 May 2019 10:31:07 -0400 Subject: [PATCH] Add tests, getInput should be case-insensitive and trim output --- packages/core/__tests__/lib.test.ts | 2 +- packages/core/package.json | 2 +- packages/core/src/core.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/__tests__/lib.test.ts b/packages/core/__tests__/lib.test.ts index bae8f580..292f20c6 100644 --- a/packages/core/__tests__/lib.test.ts +++ b/packages/core/__tests__/lib.test.ts @@ -20,7 +20,7 @@ describe('@actions/core', () => { }); it('getInput throws on missing required input', () => { - expect(() => core.getInput('missing', {required: true})).toThrow('Failed to find input missing'); + expect(() => core.getInput('missing', {required: true})).toThrow('Input required and not supplied: missing'); }); it('getInput doesnt throw on missing non-required input', () => { diff --git a/packages/core/package.json b/packages/core/package.json index 1c6b1181..3f39447a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -9,7 +9,7 @@ "author": "Bryan MacFarlane ", "homepage": "https://github.com/actions/toolkit/tree/master/packages/core", "license": "MIT", - "main": "lib/lib.js", + "main": "lib/core.js", "directories": { "lib": "lib", "test": "__tests__" diff --git a/packages/core/src/core.ts b/packages/core/src/core.ts index 013a9a28..a9baa76d 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -34,12 +34,12 @@ export function setSecret(name: string, val: string) { * @returns string */ export function getInput(name: string, options?: im.InputOptions): string { - let val:string = process.env['INPUT_' + name]; + let val: string = process.env['INPUT_' + name.replace(' ', '_').toUpperCase()] || ''; if (options && options.required && !val) { throw new Error(`Input required and not supplied: ${name}`); } - return val; + return val.trim(); } //-----------------------------------------------------------------------