From 072cb395a0afa0c2f3f2aad74c0b3f5ff3ba6b70 Mon Sep 17 00:00:00 2001 From: Grzegorz Grzybek Date: Mon, 28 Oct 2024 14:00:31 +0100 Subject: [PATCH] chore(keycloak): Fix Jest tests with Keycloak.js 26 - but needs tsconfig.json change... --- packages/hawtio/jest.config.ts | 1 + packages/hawtio/src/__mocks__/keycloak.js | 3 +++ packages/hawtio/src/plugins/auth/keycloak/keycloak-service.ts | 4 ++-- packages/hawtio/tsconfig.json | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 packages/hawtio/src/__mocks__/keycloak.js diff --git a/packages/hawtio/jest.config.ts b/packages/hawtio/jest.config.ts index d9d79a75d..a38e5b721 100644 --- a/packages/hawtio/jest.config.ts +++ b/packages/hawtio/jest.config.ts @@ -15,6 +15,7 @@ const config: Config = { '\\.(css|less)$': '/src/__mocks__/styleMock.js', '@hawtiosrc/(.*)': '/src/$1', 'react-markdown': '/../../node_modules/react-markdown/react-markdown.min.js', + 'keycloak-js': path.resolve(__dirname, './src/__mocks__/keycloak.js'), 'monaco-editor': path.resolve(__dirname, './src/__mocks__/monacoEditor.js'), '@monaco-editor/react': path.resolve(__dirname, './src/__mocks__/monacoEditor.js'), '@patternfly/react-code-editor': path.resolve(__dirname, './src/__mocks__/codeEditorMock.js'), diff --git a/packages/hawtio/src/__mocks__/keycloak.js b/packages/hawtio/src/__mocks__/keycloak.js new file mode 100644 index 000000000..c3769a17a --- /dev/null +++ b/packages/hawtio/src/__mocks__/keycloak.js @@ -0,0 +1,3 @@ +module.exports = { + Keycloak: () => {}, +} diff --git a/packages/hawtio/src/plugins/auth/keycloak/keycloak-service.ts b/packages/hawtio/src/plugins/auth/keycloak/keycloak-service.ts index 32204a239..4bef8d763 100644 --- a/packages/hawtio/src/plugins/auth/keycloak/keycloak-service.ts +++ b/packages/hawtio/src/plugins/auth/keycloak/keycloak-service.ts @@ -237,7 +237,7 @@ class KeycloakService implements IKeycloakService { keycloak .updateToken(KEYCLOAK_TOKEN_MINIMUM_VALIDITY) - .then(refreshed => { + .then((refreshed: boolean) => { if (refreshed) { const token = keycloak.token if (token) { @@ -247,7 +247,7 @@ class KeycloakService implements IKeycloakService { log.debug('Token is still valid') } }) - .catch(reason => { + .catch((reason: Error) => { log.error("Couldn't update token:", reason) errorFn?.() }) diff --git a/packages/hawtio/tsconfig.json b/packages/hawtio/tsconfig.json index 1440b66cc..63068776e 100644 --- a/packages/hawtio/tsconfig.json +++ b/packages/hawtio/tsconfig.json @@ -16,7 +16,7 @@ "noImplicitThis": true, "noUncheckedIndexedAccess": true, "module": "esnext", - "moduleResolution": "node", + "moduleResolution": "bundler", "resolveJsonModule": true, "isolatedModules": true, "noEmit": true,