Skip to content

Commit

Permalink
Unit test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-waarneming-nl committed Oct 6, 2024
1 parent fe5b66c commit 3cf870b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
36 changes: 18 additions & 18 deletions src/rules/__tests__/no-missing-translations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ const ruleTester = new RuleTester()

jest.mock('fs', () => {
const actualFs = jest.requireActual<typeof import('fs')>('fs')
return {
__esModule: true, // Mark as an ES module
const newFs = {
...actualFs,
default: {
...actualFs,
readFileSync: jest.fn((file: string) => {
if (file === 'en.json') {
return JSON.stringify({
'Existing key': 'Existing value',
'Key that only exists in en.json': 'Value',
})
}
if (file === 'nl.json') {
return JSON.stringify({
'Existing key': 'Existing value',
})
}
}),
},
readFileSync: jest.fn((file: string) => {
if (file === 'en.json') {
return JSON.stringify({
'Existing key': 'Existing value',
'Key that only exists in en.json': 'Value',
})
}
if (file === 'nl.json') {
return JSON.stringify({
'Existing key': 'Existing value',
})
}
}),
}
return {
__esModule: true,
...newFs,
}
})

Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-missing-translations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs'
import { readFileSync } from 'fs'

import { ESLintUtils, TSESTree } from '@typescript-eslint/utils'
import { RuleContext } from '@typescript-eslint/utils/ts-eslint'
Expand All @@ -14,7 +14,7 @@ type Options = [
]

const checkTranslationFileForKey = (translationFile: string, translationKey: string) => {
const fileContent = fs.readFileSync(translationFile, 'utf8')
const fileContent = readFileSync(translationFile, 'utf8')
const jsonData = JSON.parse(fileContent)
return !(translationKey in jsonData)
}
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,7 @@ __metadata:
"@typescript-eslint/utils": ^8.7.0
eslint: ^9.11.1
eslint-plugin-import: ^2.27.5
jest: ^29.7.0
jest: ^29.4.3
prettier: ^2.8.4
ts-jest: ^29.0.5
typescript: 5.1
Expand Down Expand Up @@ -3615,7 +3615,7 @@ __metadata:
languageName: node
linkType: hard

"jest@npm:^29.7.0":
"jest@npm:^29.4.3":
version: 29.7.0
resolution: "jest@npm:29.7.0"
dependencies:
Expand Down

0 comments on commit 3cf870b

Please sign in to comment.