Skip to content

Commit

Permalink
frontend: fix indexDB test suite
Browse files Browse the repository at this point in the history
indexDB is a global identifier and it doesn't need an import. But when
running in test environment it was failing as it was not defined.

Signed-off-by: Kautilya Tripathi <[email protected]>
  • Loading branch information
knrt10 committed Nov 14, 2023
1 parent 7055148 commit 6586c9c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-unused-imports": "^1.1.5",
"fake-indexeddb": "^5.0.1",
"github-markdown-css": "^5.1.0",
"https-browserify": "^1.0.0",
"humanize-duration": "^3.27.2",
Expand Down Expand Up @@ -193,7 +194,6 @@
"@testing-library/user-event": "^14.5.1",
"@types/redux-mock-store": "^1.0.4",
"fetch-mock": "^9.11.0",
"fake-indexeddb": "^5.0.1",
"http-proxy-middleware": "^2.0.1",
"husky": "^4.3.8",
"i18next-parser": "^4.7.0",
Expand Down
23 changes: 19 additions & 4 deletions frontend/src/stateless/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import 'fake-indexeddb/auto';
import { indexedDB as indexedDBtest } from 'fake-indexeddb';
import * as jsyaml from 'js-yaml';
import { v4 as uuidv4 } from 'uuid';

Expand Down Expand Up @@ -43,7 +43,12 @@ interface KubeconfigObject {
*/
export function storeStatelessClusterKubeconfig(kubeconfig: any): Promise<void> {
return new Promise<void>((resolve, reject) => {
const request = indexedDB.open('kubeconfigs', 1);
let request;
if (process.env.NODE_ENV === 'test') {
request = indexedDBtest.open('kubeconfigs', 1);
} else {
request = indexedDB.open('kubeconfigs', 1);
}

request.onupgradeneeded = function (event: any) {
const db = event.target ? event.target.result : null;
Expand Down Expand Up @@ -96,7 +101,12 @@ export function storeStatelessClusterKubeconfig(kubeconfig: any): Promise<void>
*/
export function getStatelessClusterKubeConfigs(): Promise<string[]> {
return new Promise<string[]>((resolve, reject) => {
const request = indexedDB.open('kubeconfigs', 1);
let request;
if (process.env.NODE_ENV === 'test') {
request = indexedDBtest.open('kubeconfigs', 1);
} else {
request = indexedDB.open('kubeconfigs', 1);
}

request.onupgradeneeded = function (event: any) {
const db = event.target ? event.target.result : null;
Expand Down Expand Up @@ -148,7 +158,12 @@ export function getStatelessClusterKubeConfigs(): Promise<string[]> {
export function findKubeconfigByClusterName(clusterName: string): Promise<string | null> {
return new Promise<string | null>(async (resolve, reject) => {
try {
const request = indexedDB.open('kubeconfigs', 1);
let request;
if (process.env.NODE_ENV === 'test') {
request = indexedDBtest.open('kubeconfigs', 1);
} else {
request = indexedDB.open('kubeconfigs', 1);
}

request.onupgradeneeded = function (event: any) {
const db = event.target ? event.target.result : null;
Expand Down
2 changes: 2 additions & 0 deletions plugins/headlamp-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-unused-imports": "^1.1.5",
"fake-indexeddb": "^5.0.1",
"fetch-mock": "^9.11.0",
"file-loader": "^6.2.0",
"filemanager-webpack-plugin": "^7.0.0",
Expand Down Expand Up @@ -134,6 +135,7 @@
"url": "^0.11.0",
"url-loader": "^4.1.1",
"util": "^0.12.4",
"uuid": "^9.0.4",
"validate-npm-package-name": "^3.0.0",
"vfile": "^5.3.0",
"vm-browserify": "^1.1.2",
Expand Down

0 comments on commit 6586c9c

Please sign in to comment.