Skip to content

Commit

Permalink
parse Inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Wagner committed Jun 4, 2021
1 parent 264cfae commit b595b59
Show file tree
Hide file tree
Showing 11 changed files with 6,710 additions and 93 deletions.
61 changes: 61 additions & 0 deletions __tests__/inputs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {Context} from '@actions/github/lib/context'
import {getInputs, DISPATCH_EVENT_NAME} from '../src/inputs'

test('raises error on issue_comment', () => {
const ctx = new Context()
ctx.eventName = 'issue_comment'

expect(getInputs(ctx)).toBeNull
})

test('loads repository_dispatch', () => {
const ctx = new Context()
ctx.eventName = 'repository_dispatch'
ctx.payload = {
action: DISPATCH_EVENT_NAME,
client_payload: {
jobID: 1,
jobToken: 'xxx',
credentialsToken: 'yyy'
}
}

const inputs = getInputs(ctx)
expect(inputs?.jobID).toEqual(1)
expect(inputs?.jobToken).toEqual('xxx')
expect(inputs?.credentialsToken).toEqual('yyy')
})

test('loads dynamic', () => {
const ctx = new Context()
ctx.eventName = 'dynamic'
ctx.payload = {
inputs: {
jobID: 1,
jobToken: 'xxx',
credentialsToken: 'yyy'
}
}

const inputs = getInputs(ctx)
expect(inputs?.jobID).toEqual(1)
expect(inputs?.jobToken).toEqual('xxx')
expect(inputs?.credentialsToken).toEqual('yyy')
})

test('loads workflow_dispatch', () => {
const ctx = new Context()
ctx.eventName = 'workflow_dispatch'
ctx.payload = {
inputs: {
jobID: '1',
jobToken: 'xxx',
credentialsToken: 'yyy'
}
}

const inputs = getInputs(ctx)
expect(inputs?.jobID).toEqual(1)
expect(inputs?.jobToken).toEqual('xxx')
expect(inputs?.credentialsToken).toEqual('yyy')
})
15 changes: 0 additions & 15 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
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 = {
Expand Down
7 changes: 1 addition & 6 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: 'Your name here'
name: 'Updater Action'
description: 'Provide a description here'
author: 'Your name or organization here'
inputs:
milliseconds: # change this
required: true
description: 'input description here'
default: 'default value if applicable'
runs:
using: 'node12'
main: 'dist/index.js'
Loading

0 comments on commit b595b59

Please sign in to comment.