Skip to content

Commit 2950056

Browse files
authored
Merge pull request #3 from robherley/robherley/ci
CI Updates
2 parents 0c264bc + e07e7af commit 2950056

File tree

6 files changed

+54
-9
lines changed

6 files changed

+54
-9
lines changed

.github/workflows/test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: test
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
jest:
8+
name: jest
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-node@v3
13+
with:
14+
node-version: 16
15+
- run: npm ci
16+
- run: npm test

__tests__/helpers.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from 'fs/promises'
2+
import * as core from '@actions/core'
23
import path from 'path'
34

45
export const testFixturesDirectory = path.join(__dirname, 'fixtures')
@@ -19,7 +20,7 @@ module github.com/robherley/go-test-example
1920
go 1.18
2021
`
2122

22-
export const setupActionsInputs = async () => {
23+
export const setupActionsInputs = () => {
2324
process.env['INPUT_MODULEDIRECTORY'] = testModuleDirectory
2425
process.env['INPUT_TESTARGUMENTS'] = testArguments
2526
}
@@ -46,3 +47,20 @@ export const getTestStdout = async (): Promise<string> => {
4647
)
4748
return buf.toString()
4849
}
50+
51+
export const mockActionsCoreLogging = () => {
52+
type LogFuncs = 'debug' | 'error' | 'warning' | 'notice' | 'info'
53+
const logMethods: LogFuncs[] = ['debug', 'error', 'warning', 'notice', 'info']
54+
logMethods.forEach(method => {
55+
jest
56+
.spyOn(core, method)
57+
.mockImplementation(
58+
(msg: string | Error, props?: core.AnnotationProperties) => {
59+
console.log(
60+
`[mock: core.${method}(${props ? JSON.stringify(props) : ''})]:`,
61+
msg
62+
)
63+
}
64+
)
65+
})
66+
}

__tests__/renderer.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { getTestStdout } from './helpers'
1+
import { getTestStdout, mockActionsCoreLogging } from './helpers'
22
import Renderer from '../src/renderer'
33

44
describe('Renderer', () => {
5+
beforeEach(async () => {
6+
mockActionsCoreLogging()
7+
})
8+
59
it('correctly parses test2json output', async () => {
610
const stdout = await getTestStdout()
711

__tests__/tester.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
testModuleDirectory,
99
mockProcessExit,
1010
createFakeGoModule,
11+
mockActionsCoreLogging,
1112
} from './helpers'
1213
import Tester from '../src/tester'
1314
import Renderer from '../src/renderer'
@@ -18,7 +19,8 @@ describe('Tester', () => {
1819
})
1920

2021
beforeEach(async () => {
21-
await setupActionsInputs()
22+
mockActionsCoreLogging()
23+
setupActionsInputs()
2224
})
2325

2426
it("sets defaults if inputs aren't set", async () => {

jest.config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

jest.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Config } from '@jest/types'
2+
3+
const config: Config.InitialOptions = {
4+
preset: 'ts-jest',
5+
testEnvironment: 'node',
6+
testPathIgnorePatterns: ['helpers.ts'],
7+
reporters: ['default', 'github-actions'],
8+
clearMocks: true,
9+
}
10+
11+
export default config

0 commit comments

Comments
 (0)