Skip to content

Commit

Permalink
feat(fta): add prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
exiguus committed Nov 26, 2023
1 parent 48742f2 commit 93de950
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 109 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ jobs:
id: test-action
uses: ./
with:
milliseconds: 1000
file_path: ./src/

- name: Print Output
- name: Print Output Values
id: output
run: echo "${{ steps.test-action.outputs.time }}"
run: echo "${{ steps.test-action.outputs.details }}" && echo "${{ steps.test-action.outputs.summary }}"
22 changes: 22 additions & 0 deletions __tests__/fta.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Unit tests for src/wait.ts
*/

import * as fta from '../src/fta'
import { expect } from '@jest/globals'

describe('wait.ts', () => {
it('throws on invalid file_path', async () => {
const file_path = ''
await expect(fta.run(file_path)).rejects.toThrow(
'Param `file_path` is required'
)
})

it('throws on non-existent file_path', async () => {
const file_path = 'non-existent-file'
await expect(fta.run(file_path)).rejects.toThrow(
'Param `file_path` does not exist'
)
})
})
35 changes: 20 additions & 15 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let debugMock: jest.SpyInstance
let errorMock: jest.SpyInstance
let getInputMock: jest.SpyInstance
let setFailedMock: jest.SpyInstance
let setOutputMock: jest.SpyInstance
// let setOutputMock: jest.SpyInstance

describe('action', () => {
beforeEach(() => {
Expand All @@ -30,15 +30,15 @@ describe('action', () => {
errorMock = jest.spyOn(core, 'error').mockImplementation()
getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
// setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
})

it('sets the time output', async () => {
it('sets the detail and summary output', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string): string => {
switch (name) {
case 'milliseconds':
return '500'
case 'file_path':
return './src/'
default:
return ''
}
Expand All @@ -48,29 +48,34 @@ describe('action', () => {
expect(runMock).toHaveReturned()

// Verify that all of the core library functions were called correctly
expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...')
expect(debugMock).toHaveBeenNthCalledWith(1, "Input 'file_path' is: ./src/")
expect(debugMock).toHaveBeenNthCalledWith(
2,
expect.stringMatching(timeRegex)
)
expect(debugMock).toHaveBeenNthCalledWith(
3,
expect.stringMatching(timeRegex)
)
expect(setOutputMock).toHaveBeenNthCalledWith(
1,
'time',
2,
expect.stringMatching(timeRegex)
)
// expect(setOutputMock).toHaveBeenNthCalledWith(
// 1,
// 'details',
// expect.stringContaining('FTA Score (Lower is Better)')
// )
// expect(setOutputMock).toHaveBeenNthCalledWith(
// 1,
// 'summary',
// expect.stringContaining('"file_name": "fta.ts"')
// )
expect(errorMock).not.toHaveBeenCalled()
})

it('sets a failed status', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string): string => {
switch (name) {
case 'milliseconds':
return 'this is not a number'
case 'file_path':
return 'Param `file_path` is required'
default:
return ''
}
Expand All @@ -82,7 +87,7 @@ describe('action', () => {
// Verify that all of the core library functions were called correctly
expect(setFailedMock).toHaveBeenNthCalledWith(
1,
'milliseconds not a number'
'Param `file_path` does not exist'
)
expect(errorMock).not.toHaveBeenCalled()
})
Expand Down
25 changes: 0 additions & 25 deletions __tests__/wait.test.ts

This file was deleted.

22 changes: 12 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
name: 'The name of your action here'
description: 'Provide a description here'
author: 'Your name or organization here'
name: "The name of your action here"
description: "Provide a description here"
author: "Your name or organization here"

# Add your action's branding here. This will appear on the GitHub Marketplace.
branding:
icon: 'heart'
color: 'red'
icon: "heart"
color: "red"

# Define your inputs here.
inputs:
milliseconds:
description: 'Your input description here'
file_path:
description: "Your input description here"
required: true
default: '1000'
default: "./src/"

# Define your outputs here.
outputs:
time:
description: 'Your output description here'
summary:
description: "Your output description here"
details:
description: "Your output description here"

runs:
using: node20
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 75 additions & 30 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
]
},
"dependencies": {
"@actions/core": "^1.10.1"
"@actions/core": "^1.10.1",
"fta-cli": "^1.0.0"
},
"devDependencies": {
"@types/jest": "^29.5.8",
Expand Down
Loading

0 comments on commit 93de950

Please sign in to comment.