Skip to content

Commit

Permalink
test: add unit test for uncovered error
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Nov 11, 2023
1 parent 0423311 commit 70487af
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/unit/loadConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ describe('loadConfig', () => {
`)
})

it('should return null config when YAML config file is invalid', async () => {
expect.assertions(1)

const configFile = path.join(__dirname, '__mocks__', 'lint-staged.yml')

await fs.writeFile(configFile, '{')

const { config } = await loadConfig({ configPath: configFile }, logger)

expect(config).toBeUndefined()

await fs.rm(configFile)
})

it('should load CommonJS config file from absolute path', async () => {
expect.assertions(1)

Expand Down Expand Up @@ -193,6 +207,30 @@ describe('loadConfig', () => {
await fs.rm(configFile)
})

it('should read config from package.json', async () => {
expect.assertions(1)

const configFile = path.join(__dirname, '__mocks__', 'package.json')

await fs.writeFile(
configFile,
JSON.stringify({
'lint-staged': {
'*': 'mytask',
},
})
)

const { config } = await loadConfig({ configPath: configFile }, logger)

expect(config).toMatchInlineSnapshot(`
{
"*": "mytask",
}
`)
await fs.rm(configFile)
})

it('should return null config when package.json file is invalid', async () => {
expect.assertions(1)

Expand Down

0 comments on commit 70487af

Please sign in to comment.