Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

18 changes: 16 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,24 @@ jobs:
npm install
- run: |
npm run all
test: # make sure the action works on a clean machine without building
test-linux: # make sure the action works on a clean linux machine without building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
milliseconds: 1000
version: 'latest'
test-macos: # make sure the action works on a clean macos machine without building
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
version: 'latest'
test-windows: # make sure the action works on a clean windows machine without building
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
version: 'latest'
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @actions/actions-runtime
* @puppetlabs/dio
94 changes: 70 additions & 24 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,75 @@
import {wait} from '../src/wait'
import * as process from 'process'
import * as cp from 'child_process'
import * as path from 'path'
import {expect, test} from '@jest/globals'

test('throws invalid number', async () => {
const input = parseInt('foo', 10)
await expect(wait(input)).rejects.toThrow('milliseconds not a number')
jest.mock('@actions/core')
jest.mock('../src/setup-step-cli')
import {run} from '../src/main'
import {afterEach, expect, jest, test} from '@jest/globals'
const core = require('@actions/core')
const step = require('../src/setup-step-cli')

afterEach(() => {
jest.clearAllMocks()
})

test('should succeed calling main program entrypoint with latest version', async () => {
// Mock getting Actions input for latest version and return value for installStepCli
const version = 'latest'
core.getInput = jest.fn().mockReturnValueOnce(version)
Object.defineProperty(step, 'installStepCli', {
value: jest.fn().mockImplementationOnce(() => Promise.resolve())
})

// Run function and validate steps
run()
expect(step.installStepCli).toHaveBeenCalledWith('latest')
})

test('should succeed calling main program entrypoint with specific version', async () => {
// Mock getting Actions input for a specific version and return value for installStepCli
const version = '0.0.0'
core.getInput = jest.fn().mockReturnValueOnce(version)
Object.defineProperty(step, 'installStepCli', {
value: jest.fn().mockImplementationOnce(() => Promise.resolve())
})

// Run function and validate steps
run()
expect(step.installStepCli).toHaveBeenCalledWith('0.0.0')
})

test('should fail version input validation', async () => {
// Mock getting Actions input and return value for installStepCli
const version = 'notasemver'
core.getInput = jest.fn().mockReturnValueOnce(version)

// Run function and validate steps
run()
expect(step.installStepCli).toHaveBeenCalledTimes(0)
expect(core.setFailed).toHaveBeenCalledWith(
'The supplied input notasemver is not a valid version. Please supply a semver format like major.minor.hotfix'
)
})

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)
test('should fail calling main program entrypoint with Error thrown', async () => {
// Mock installStepCli throwing error
const version = '0.0.0'
core.getInput = jest.fn().mockReturnValueOnce(version)
step.installStepCli.mockImplementationOnce(() => {
throw new Error('some failure')
})

// Run function and validate steps
run()
expect(step.installStepCli).toHaveBeenCalled
expect(core.setFailed).toHaveBeenCalledWith('some failure')
})

// 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())
test('should fail calling main program entrypoint without Error thrown', async () => {
// Mock installStepCli rejected without error
const version = '0.0.0'
core.getInput = jest.fn().mockReturnValueOnce(version)
step.installStepCli.mockImplementationOnce(() => Promise.reject())

// Run function and validate steps
run()
expect(step.installStepCli).toHaveBeenCalled
expect(core.setFailed).toHaveBeenCalledTimes(0)
})
Loading