From 121e4931c46bdd0e14aa34d6766b346df4d2214b Mon Sep 17 00:00:00 2001 From: Francois Best Date: Wed, 10 Mar 2021 00:32:26 +0100 Subject: [PATCH] chore: Test getRefContext --- __tests__/gha.test.ts | 22 ++++++++++++++++++++++ __tests__/main.test.ts | 28 ---------------------------- src/wait.ts | 9 --------- 3 files changed, 22 insertions(+), 37 deletions(-) create mode 100644 __tests__/gha.test.ts delete mode 100644 __tests__/main.test.ts delete mode 100644 src/wait.ts diff --git a/__tests__/gha.test.ts b/__tests__/gha.test.ts new file mode 100644 index 0000000..2ba2a43 --- /dev/null +++ b/__tests__/gha.test.ts @@ -0,0 +1,22 @@ +import { getRefContext } from '../src/gha' + +test('getRefContext - branch', () => { + expect(getRefContext('refs/heads/foo')).toEqual('branch *foo*') + expect(getRefContext('refs/heads/foo/bar/egg')).toEqual( + 'branch *foo/bar/egg*' + ) + expect(getRefContext('refs/heads/foo.bar-egg')).toEqual( + 'branch *foo.bar-egg*' + ) +}) + +test('getRefContext - tag', () => { + expect(getRefContext('refs/tags/1.2.3')).toEqual('tag *1.2.3*') + expect(getRefContext('refs/tags/1.2.3-beta_off-12')).toEqual( + 'tag *1.2.3-beta_off-12*' + ) +}) + +test('getRefContext - PR', () => { + expect(getRefContext('refs/pull/123/merge')).toEqual('PR *#123*') +}) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts deleted file mode 100644 index bd5b3da..0000000 --- a/__tests__/main.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { wait } from '../src/wait' -import * as process from 'process' -import * as cp from 'child_process' -import * as path from 'path' - -test('throws invalid number', async () => { - const input = parseInt('foo', 10) - await expect(wait(input)).rejects.toThrow('milliseconds not a number') -}) - -test('wait 500 ms', async () => { - const start = new Date() - await wait(500) - const end = new Date() - var delta = Math.abs(end.getTime() - start.getTime()) - 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 np = process.execPath - const ip = path.join(__dirname, '..', 'lib', 'main.js') - const options: cp.ExecFileSyncOptions = { - env: process.env - } - console.log(cp.execFileSync(np, [ip], options).toString()) -}) diff --git a/src/wait.ts b/src/wait.ts deleted file mode 100644 index b169d9a..0000000 --- a/src/wait.ts +++ /dev/null @@ -1,9 +0,0 @@ -export async function wait(milliseconds: number): Promise { - return new Promise(resolve => { - if (isNaN(milliseconds)) { - throw new Error('milliseconds not a number') - } - - setTimeout(() => resolve('done!'), milliseconds) - }) -}