diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index b10736d..f27a278 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -1,19 +1,18 @@ import {execSync} from 'child_process'; import * as path from 'path'; import * as process from 'process'; -import {getShouldFinalize} from '../src/validate'; +import {getShouldFinalize, getSourcemaps, getStartedAt} from '../src/validate' describe('validate', () => { describe('getShouldFinalize', () => { + const errorMessage = 'finalize is not a boolean'; afterEach(() => { delete process.env['INPUT_FINALIZE']; }); test('should throw an error when finalize is invalid', async () => { process.env['INPUT_FINALIZE'] = 'error'; - expect(() => getShouldFinalize()).toThrow( - 'finalize is not a boolean' - ); + expect(() => getShouldFinalize()).toThrow(errorMessage); }); test('should return true when finalize is omitted', async () => { @@ -25,6 +24,57 @@ describe('validate', () => { expect(getShouldFinalize()).toBe(false); }); }); + + describe('getSourcemaps', () => { + afterEach(() => { + delete process.env['INPUT_SOURCEMAPS']; + }); + + test('should return empty list when sourcemaps is omitted', async () => { + expect(getSourcemaps()).toEqual([]); + }); + + test('should return array when sourcemaps is false', () => { + process.env['INPUT_SOURCEMAPS'] = './lib'; + expect(getSourcemaps()).toEqual(['./lib']); + }); + }); + + describe('getStartedAt', () => { + const errorMessage = 'started_at not in valid format. Unix timestamp or ISO 8601 date expected'; + afterEach(() => { + delete process.env['INPUT_STARTED_AT']; + }); + + test('should throw an error when started_at is negative', async () => { + process.env['INPUT_STARTED_AT'] = '-1'; + expect(() => getStartedAt()).toThrow(errorMessage); + }); + + test('should throw an error when started_at is invalid', async () => { + process.env['INPUT_STARTED_AT'] = 'error'; + expect(() => getStartedAt()).toThrow(errorMessage); + }); + + test('should return null when started_at is omitted', async () => { + expect(getStartedAt()).toBeNull(); + }); + + test('should return an integer when started_at is an ISO8601 string.', async () => { + process.env['INPUT_STARTED_AT'] = '2017-07-13T19:40:00'; + expect(getStartedAt()).toEqual(1500000000); + }); + + test('should return an integer when started_at is an truncated ISO8601 string.', async () => { + process.env['INPUT_STARTED_AT'] = '2017-07-13'; + expect(getStartedAt()).toEqual(1499904000); + }); + + test('should return an integer when started_at is an integer.', async () => { + process.env['INPUT_STARTED_AT'] = '1500000000'; + expect(getStartedAt()).toEqual(1500000000); + }); + }); }); // shows how the runner will run a javascript action with env / stdout protocol