2023-04-03 15:06:11 +00:00
|
|
|
import * as cp from 'child_process'
|
|
|
|
import * as path from 'path'
|
2023-04-03 16:10:31 +00:00
|
|
|
import * as process from 'process'
|
|
|
|
|
2023-04-03 15:06:11 +00:00
|
|
|
import {expect, test} from '@jest/globals'
|
2023-04-03 16:10:31 +00:00
|
|
|
import {wait} from '../src/wait'
|
2023-04-03 15:06:11 +00:00
|
|
|
|
|
|
|
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()
|
2023-04-03 16:10:31 +00:00
|
|
|
const delta = Math.abs(end.getTime() - start.getTime())
|
2023-04-03 15:06:11 +00:00
|
|
|
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())
|
|
|
|
})
|