Skip to content

Commit

Permalink
test: add missing test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Dec 2, 2023
1 parent b803cf0 commit 78a0c23
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions test/unit/loadConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('loadConfig', () => {
`)
})

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

const { config } = await loadConfig(
Expand Down Expand Up @@ -230,7 +230,7 @@ describe('loadConfig', () => {
}
})

it('should return null config when package.json file is invalid', async () => {
it('should not return config when package.json file is invalid', async () => {
const tempDir = await createTempDir()
const configPath = path.join(tempDir, 'package.json')

Expand Down Expand Up @@ -299,7 +299,7 @@ describe('loadConfig', () => {
}
})

it('should return null config when package.yaml file is invalid', async () => {
it('should not return config when package.yaml file is invalid', async () => {
const tempDir = await createTempDir()
const configPath = path.join(tempDir, 'package.yaml')

Expand All @@ -315,4 +315,42 @@ describe('loadConfig', () => {
await fs.rm(tempDir, { recursive: true })
}
})

it('should treat config file without extension as YAML', async () => {
const tempDir = await createTempDir()
const configPath = path.join(tempDir, 'lint-staged-config')

try {
expect.assertions(1)

await fs.writeFile(configPath, `"*": mytask`)

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

expect(config).toMatchInlineSnapshot(`
{
"*": "mytask",
}
`)
} finally {
await fs.rm(tempDir, { recursive: true })
}
})

it('should not return config when invalid file without extension', async () => {
const tempDir = await createTempDir()
const configPath = path.join(tempDir, 'lint-staged-config')

try {
expect.assertions(1)

await fs.writeFile(configPath, `{`)

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

expect(config).toBeUndefined()
} finally {
await fs.rm(tempDir, { recursive: true })
}
})
})

0 comments on commit 78a0c23

Please sign in to comment.