Skip to content

Commit

Permalink
Fixed unit tests and import order 😮‍💨
Browse files Browse the repository at this point in the history
  • Loading branch information
01taylop committed Jul 15, 2024
1 parent 8564438 commit 5963e8c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
7 changes: 5 additions & 2 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module.exports = {
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
['@babel/preset-env', {
modules: 'auto',
targets: { node: 'current' },
}],
'@babel/preset-typescript',
],
}
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const config: JestConfigWithTsJest = {
'^@Utils(.*)$': '<rootDir>/src/utils$1',
},
transform: {
'^.+\\.tsx?$': 'ts-jest'
'^.+\\.(js|ts)$': 'babel-jest',
},
}

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/sourceFiles.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { glob } from 'glob'

import colourLog from '@Utils/colourLog'
import { Linter } from '@Types'
import colourLog from '@Utils/colourLog'

import sourceFiles from '../sourceFiles'

Expand Down
2 changes: 1 addition & 1 deletion src/linters/markdownlint/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import markdownlint, { type LintResults } from 'markdownlint'

import colourLog from '@Utils/colourLog'
import { Linter, type LinterResult, type ProcessedResult } from '@Types'
import colourLog from '@Utils/colourLog'

import loadConfig from './loadConfig'

Expand Down
2 changes: 1 addition & 1 deletion src/sourceFiles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { glob } from 'glob'

import colourLog from '@Utils/colourLog'
import { Linter } from '@Types'
import colourLog from '@Utils/colourLog'
import { pluralise } from '@Utils/transform'

interface SourceFiles {
Expand Down
18 changes: 9 additions & 9 deletions src/utils/__tests__/colourLog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,25 @@ describe('colourLog', () => {
describe('error', () => {

it('logs the text in red', () => {
colourLog.error('An error occurred.')
colourLog.error('An error occurred')

expect(chalk.red).toHaveBeenCalledTimes(1)
expect(chalk.red).toHaveBeenCalledWith('An error occurred.')
expect(chalk.red).toHaveBeenCalledWith('An error occurred')
expect(mockedConsoleLog).toHaveBeenCalledTimes(1)
expect(mockedConsoleLog).toHaveBeenCalledWith('An error occurred.')
expect(mockedConsoleLog).toHaveBeenCalledWith('An error occurred')
})

it('logs the text in red but does not log the error if global.debug is false', () => {
const mockedConsoleError = jest.spyOn(console, 'error').mockImplementation(() => {})
global.debug = false

const error = new Error('Oops')
colourLog.error('An error occurred.', error)
colourLog.error('An error occurred', error)

expect(chalk.red).toHaveBeenCalledTimes(1)
expect(chalk.red).toHaveBeenCalledWith('An error occurred.')
expect(chalk.red).toHaveBeenCalledWith('An error occurred')
expect(mockedConsoleLog).toHaveBeenCalledTimes(1)
expect(mockedConsoleLog).toHaveBeenCalledWith('An error occurred.')
expect(mockedConsoleLog).toHaveBeenCalledWith('An error occurred')
expect(mockedConsoleError).toHaveBeenCalledTimes(0)
})

Expand All @@ -84,12 +84,12 @@ describe('colourLog', () => {
global.debug = true

const error = new Error('Oops')
colourLog.error('An error occurred.', error)
colourLog.error('An error occurred', error)

expect(chalk.red).toHaveBeenCalledTimes(1)
expect(chalk.red).toHaveBeenCalledWith('An error occurred.')
expect(chalk.red).toHaveBeenCalledWith('An error occurred')
expect(mockedConsoleLog).toHaveBeenCalledTimes(1)
expect(mockedConsoleLog).toHaveBeenCalledWith('An error occurred.')
expect(mockedConsoleLog).toHaveBeenCalledWith('An error occurred')
expect(mockedConsoleError).toHaveBeenCalledTimes(1)
expect(mockedConsoleError).toHaveBeenCalledWith(error)
})
Expand Down

0 comments on commit 5963e8c

Please sign in to comment.