generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable strict mode and other stricter tsconfig settings, fix is…
…sues (#7)
- Loading branch information
1 parent
a39acc2
commit d8f349b
Showing
44 changed files
with
1,390 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
import hmppsConfig from '@ministryofjustice/eslint-config-hmpps' | ||
|
||
export default hmppsConfig() | ||
export default [ | ||
...hmppsConfig(), | ||
{ | ||
rules: { | ||
'dot-notation': 'off', | ||
}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { expect } from 'chai' | ||
|
||
context('Healthcheck', () => { | ||
context('All healthy', () => { | ||
beforeEach(() => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
Cypress.Commands.add('signIn', (options = { failOnStatusCode: true }) => { | ||
cy.request('/') | ||
return cy.task('getSignInUrl').then((url: string) => cy.visit(url, options)) | ||
return cy.task<string>('getSignInUrl').then((url: string) => { | ||
cy.visit(url, options) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import '@testing-library/jest-dom' | ||
|
||
// @ts-expect-error setImmediate args have any types | ||
globalThis.setImmediate = globalThis.setImmediate || ((fn, ...args) => global.setTimeout(fn, 0, ...args)) | ||
|
||
// Reset JSDOM | ||
|
||
type AddEventListenerParams = Parameters<Document['addEventListener']> | ||
const sideEffects = { | ||
document: { | ||
addEventListener: { | ||
fn: document.addEventListener, | ||
refs: [] as { | ||
type: AddEventListenerParams['0'] | ||
listener: AddEventListenerParams['1'] | ||
options: AddEventListenerParams['2'] | ||
}[], | ||
}, | ||
keys: Object.keys(document) as unknown as (keyof typeof document)[], | ||
}, | ||
window: { | ||
addEventListener: { | ||
fn: window.addEventListener, | ||
refs: [] as { | ||
type: AddEventListenerParams['0'] | ||
listener: AddEventListenerParams['1'] | ||
options: AddEventListenerParams['2'] | ||
}[], | ||
}, | ||
keys: Object.keys(window) as unknown as (keyof typeof window)[], | ||
}, | ||
} | ||
|
||
// Lifecycle Hooks | ||
// ----------------------------------------------------------------------------- | ||
beforeAll(async () => { | ||
// Spy addEventListener | ||
;['document', 'window'].forEach(_obj => { | ||
const obj: 'document' | 'window' = _obj as 'document' | 'window' | ||
const { fn } = sideEffects[obj].addEventListener | ||
const { refs } = sideEffects[obj].addEventListener | ||
|
||
const addEventListenerSpy: Document['addEventListener'] = ( | ||
type: string, | ||
listener: EventListenerOrEventListenerObject, | ||
options: boolean | EventListenerOptions, | ||
) => { | ||
// Store listener reference so it can be removed during reset | ||
refs.push({ type, listener, options }) | ||
// Call original window.addEventListener | ||
fn(type, listener, options) | ||
} | ||
|
||
// Add to default key array to prevent removal during reset | ||
sideEffects[obj].keys.push('addEventListener') | ||
|
||
// Replace addEventListener with mock | ||
global[obj].addEventListener = addEventListenerSpy | ||
}) | ||
}) | ||
|
||
// Reset JSDOM. This attempts to remove side effects from tests, however it does | ||
// not reset all changes made to globals like the window and document | ||
// objects. Tests requiring a full JSDOM reset should be stored in separate | ||
// files, which is only way to do a complete JSDOM reset with Jest. | ||
beforeEach(async () => { | ||
const rootElm = document.documentElement | ||
|
||
// Remove attributes on root element | ||
;[...rootElm.attributes].forEach(attr => rootElm.removeAttribute(attr.name)) | ||
|
||
// Remove elements (faster than setting innerHTML) | ||
while (rootElm.firstChild) { | ||
rootElm.removeChild(rootElm.firstChild) | ||
} | ||
|
||
// Remove global listeners and keys | ||
;['document', 'window'].forEach(_obj => { | ||
const obj: 'document' | 'window' = _obj as 'document' | 'window' | ||
const { refs } = sideEffects[obj].addEventListener | ||
|
||
refs.forEach(ref => { | ||
const { type, listener, options } = ref | ||
global[obj].removeEventListener(type, listener, options) | ||
}) | ||
|
||
// need a semicolon to start here because we have semis turned off and ASI won't work and eslint tries to blend the two together | ||
;(Object.keys(global[obj]) as unknown as (keyof (typeof global)[typeof obj])[]) | ||
.filter(key => !sideEffects[obj].keys.includes(key) && !key.includes('coverage')) | ||
.forEach(key => { | ||
delete global[obj][key] | ||
}) | ||
}) | ||
|
||
// Restore base elements | ||
rootElm.innerHTML = '<head></head><body></body>' | ||
}) | ||
|
||
export {} |
Oops, something went wrong.