Skip to content

Commit

Permalink
Add tests for config loading
Browse files Browse the repository at this point in the history
  • Loading branch information
lerebear committed Jan 1, 2024
1 parent a8564b3 commit 959b5ff
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
43 changes: 43 additions & 0 deletions __tests__/initializer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as core from '@actions/core'
import * as initializer from '../src/initializer'

describe('initializer', () => {
const infoMock = jest.spyOn(core, 'info').mockImplementation(() => {})

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

it('uses the default configuration when no config file is provided', () => {
jest.spyOn(core, 'getInput').mockImplementation((name: string): string => {
switch (name) {
case 'configuration-file-path':
return ''
default:
return 'foo'
}
})

const config = initializer.loadConfiguration()

expect(config).toBeDefined()
expect(infoMock).toHaveBeenCalledWith('Using default sizeup configuration')
})

it('can load a custom configuration file', () => {
jest.spyOn(core, 'getInput').mockImplementation((name: string): string => {
switch (name) {
case 'configuration-file-path':
return '__tests__/test-configuration.yaml'
default:
return ''
}
})
const config = initializer.loadConfiguration()

expect(config).toBeDefined()
expect(infoMock).toHaveBeenCalledWith(
'Reading sizeup configuration from "__tests__/test-configuration.yaml"'
)
})
})
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.
2 changes: 1 addition & 1 deletion dist/index.js

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

2 changes: 1 addition & 1 deletion src/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function loadConfiguration(): Configuration {
let configFile = core.getInput('configuration-file-path')

if (configFile) {
core.info(`Reading sizeup configuration from ${configFile}`)
core.info(`Reading sizeup configuration from "${configFile}"`)
} else {
core.info('Using default sizeup configuration')
configFile = path.resolve(__dirname, './config/default.yaml')
Expand Down

0 comments on commit 959b5ff

Please sign in to comment.