Skip to content

Commit

Permalink
refactor: reorder and rename tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sztadii committed Mar 6, 2024
1 parent c0e71e4 commit 0c88ed2
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/file-naming-enforcer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,23 @@ describe('fileNamingEnforcer function', () => {
fileService.removeFolder(/mocks-/)
})

it('when type is missing then we display an error message and kill a process', async () => {
await fileNamingEnforcer.enforce('folder=./mocks')
it('display a success message when searched files are correct', async () => {
const folderName = 'mocks-7'
await fileService.createFiles(folderName, [
'simple-styles.sass',
'other-styles.sass'
])

expect(processService.killProcess).toHaveBeenCalledTimes(1)
await fileNamingEnforcer.enforce(
`type=kebabCase folder=./${folderName} ext=sass`
)

expect(processService.killProcess).not.toHaveBeenCalled()
expect(logger.log).toHaveBeenCalledTimes(1)
expect(logger.log).toHaveBeenCalledWith('Uuu, `type` argument is missing')
expect(logger.log).toHaveBeenCalledWith('Great, everything looks fine :)')
})

it('when a project convention is kebabCase and all files are correct then we display a success message', async () => {
it('display a success message when a project convention is kebabCase and all files are correct', async () => {
const folderName = 'mocks-1'
await fileService.createFiles(folderName, [
'file-one.js',
Expand All @@ -49,7 +57,15 @@ describe('fileNamingEnforcer function', () => {
expect(logger.log).toHaveBeenCalledWith('Great, everything looks fine :)')
})

it('by default ignore some files and allow to ignore other', async () => {
it('display an error message and kill the process when type is missing', async () => {
await fileNamingEnforcer.enforce('folder=./mocks')

expect(processService.killProcess).toHaveBeenCalledTimes(1)
expect(logger.log).toHaveBeenCalledTimes(1)
expect(logger.log).toHaveBeenCalledWith('Uuu, `type` argument is missing')
})

it('by default ignore some files and allow to ignore others', async () => {
const folderName = 'mocks-2'
await fileService.createFiles(folderName, [
'README.md',
Expand All @@ -67,7 +83,7 @@ describe('fileNamingEnforcer function', () => {
expect(logger.log).toHaveBeenCalledWith('Great, everything looks fine :)')
})

it('when a project convention is kebabCase and some files are wrong then we display an error message and kill a process', async () => {
it('display an error message and kill the process when a project convention is kebabCase and some files are wrong', async () => {
const folderName = 'mocks-3'
await fileService.createFile(folderName, 'SIMPLE-READ.md')

Expand All @@ -80,7 +96,7 @@ describe('fileNamingEnforcer function', () => {
)
})

it('when a project convention is capitalize and some files are wrong then we display an error message and kill a process', async () => {
it('display an error message and kill the process when a project convention is capitalize and some files are wrong', async () => {
const folderName = 'mocks-4'
await fileService.createFiles(folderName, [
'SIMPLE-READ.md',
Expand All @@ -97,7 +113,7 @@ describe('fileNamingEnforcer function', () => {
)
})

it('when a project convention is not supported then we display an error message and kill a process', async () => {
it('display an error message and kill the process when the project convention is not supported', async () => {
await fileNamingEnforcer.enforce('folder=./mocks type=newCase')

expect(processService.killProcess).toHaveBeenCalledTimes(1)
Expand All @@ -107,7 +123,7 @@ describe('fileNamingEnforcer function', () => {
)
})

it('when a folder is empty then we display a error message and kill a process', async () => {
it('display an error message and kill the process when the folder is empty', async () => {
const folderName = 'mocks-5'
await fileService.createFolder(folderName)
await fileNamingEnforcer.enforce(`type=kebabCase folder=./${folderName}`)
Expand All @@ -119,7 +135,7 @@ describe('fileNamingEnforcer function', () => {
)
})

it('when a folder does not exist we display a error message and kill a process', async () => {
it('display an error message and kill the process when the folder does not exist', async () => {
await fileNamingEnforcer.enforce('type=kebabCase folder=./xxx')

expect(processService.killProcess).toHaveBeenCalledTimes(1)
Expand All @@ -129,7 +145,7 @@ describe('fileNamingEnforcer function', () => {
)
})

it('when we could not find any file with provided extension', async () => {
it('display an error message and kill the process when no files with the provided extension are found', async () => {
const folderName = 'mocks-6'
await fileService.createFiles(folderName, [
'SIMPLE-READ.md',
Expand All @@ -146,20 +162,4 @@ describe('fileNamingEnforcer function', () => {
`Uuu, in folder ./${folderName} we could not find any file with .tsx extension`
)
})

it('when searched files are correct then we display a success message', async () => {
const folderName = 'mocks-7'
await fileService.createFiles(folderName, [
'simple-styles.sass',
'other-styles.sass'
])

await fileNamingEnforcer.enforce(
`type=kebabCase folder=./${folderName} ext=sass`
)

expect(processService.killProcess).not.toHaveBeenCalled()
expect(logger.log).toHaveBeenCalledTimes(1)
expect(logger.log).toHaveBeenCalledWith('Great, everything looks fine :)')
})
})

0 comments on commit 0c88ed2

Please sign in to comment.