Skip to content

Commit 6b3addc

Browse files
committed
feat: added Unit testing using Jest for utils file (#15)
* fix: update import path for Kubeflow styles Signed-off-by: LogicalGuy77 <harshitacademia@gmail.com> * fix: update build scripts to ensure CSS assets are copied correctly Signed-off-by: LogicalGuy77 <harshitacademia@gmail.com> * fix: enhance frontend dependency installation and style setup Signed-off-by: LogicalGuy77 <harshitacademia@gmail.com> * fix: enhance frontend dependency installation and style setup Signed-off-by: LogicalGuy77 <harshitacademia@gmail.com> * fix: enhance frontend dependency installation and style setup Signed-off-by: LogicalGuy77 <harshitacademia@gmail.com> * feat: setup Jest and __mocks__ for unit testing * feat: enhance type definitions and add tests for predictor extension specifications * fix: format code for consistency in utils.jest.spec.ts * fix: update unit test command to use Jest instead of production --------- Signed-off-by: LogicalGuy77 <harshitacademia@gmail.com>
1 parent 1fa0e2b commit 6b3addc

File tree

9 files changed

+3404
-183
lines changed

9 files changed

+3404
-183
lines changed

.github/workflows/test-node.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ jobs:
6161
- name: Run Unit Tests
6262
run: |
6363
cd frontend
64-
npm run test:prod
64+
npm run test:jest

frontend/__mocks__/kubeflow.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Mock for Kubeflow imports used in getK8sObjectUiStatus function
2+
export enum STATUS_TYPE {
3+
UNINITIALIZED = "Uninitialized",
4+
TERMINATING = "Terminating",
5+
WARNING = "Warning",
6+
READY = "Ready",
7+
}
8+
9+
// Interface for Kubernetes condition
10+
export interface Condition {
11+
type: string;
12+
status: string;
13+
reason?: string;
14+
message?: string;
15+
}
16+
17+
// Interface for status object
18+
export interface Status {
19+
phase: STATUS_TYPE;
20+
state: string;
21+
message: string;
22+
}
23+
24+
// Interface for Kubernetes object
25+
export interface K8sObject {
26+
kind: string;
27+
metadata: {
28+
name?: string;
29+
namespace?: string;
30+
deletionTimestamp?: string;
31+
[key: string]: any;
32+
};
33+
status?: {
34+
conditions?: Condition[] | null;
35+
[key: string]: any;
36+
};
37+
spec?: any;
38+
}
39+
40+
// Types for getPredictorExtensionSpec tests
41+
export enum PredictorType {
42+
Tensorflow = 'tensorflow',
43+
Triton = 'triton',
44+
Sklearn = 'sklearn',
45+
Onnx = 'onnx',
46+
Pytorch = 'pytorch',
47+
Xgboost = 'xgboost',
48+
Pmml = 'pmml',
49+
Lightgbm = 'lightgbm',
50+
MLFlow = 'mlflow',
51+
Custom = 'custom',
52+
}
53+
54+
export interface PredictorExtensionSpec {
55+
storageUri?: string;
56+
runtimeVersion?: string;
57+
protocolVersion?: string;
58+
image?: string;
59+
name?: string;
60+
env?: Array<{
61+
name: string;
62+
value: string;
63+
}>;
64+
[key: string]: any;
65+
}
66+
67+
export interface ModelSpec extends PredictorExtensionSpec {
68+
modelFormat: {
69+
name: string;
70+
version?: string;
71+
};
72+
runtime?: string;
73+
}
74+
75+
export interface PredictorSpec {
76+
sklearn?: PredictorExtensionSpec;
77+
xgboost?: PredictorExtensionSpec;
78+
tensorflow?: PredictorExtensionSpec;
79+
pytorch?: PredictorExtensionSpec;
80+
triton?: PredictorExtensionSpec;
81+
onnx?: PredictorExtensionSpec;
82+
pmml?: PredictorExtensionSpec;
83+
lightgbm?: PredictorExtensionSpec;
84+
mlflow?: PredictorExtensionSpec;
85+
model?: ModelSpec;
86+
containers?: Array<{
87+
name?: string;
88+
image?: string;
89+
env?: Array<{
90+
name: string;
91+
value: string;
92+
}>;
93+
[key: string]: any;
94+
}>;
95+
[key: string]: any;
96+
}

frontend/jest.config.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = {
2+
preset: "jest-preset-angular",
3+
setupFilesAfterEnv: ["<rootDir>/src/test-setup.jest.ts"],
4+
testMatch: ["**/*.jest.spec.ts"],
5+
collectCoverageFrom: [
6+
"src/**/*.ts",
7+
"!src/**/*.spec.ts",
8+
"!src/**/*.jest.spec.ts",
9+
"!src/main.ts",
10+
"!src/polyfills.ts",
11+
],
12+
coverageDirectory: "coverage-jest",
13+
testEnvironment: "jsdom",
14+
moduleNameMapper: {
15+
"^kubeflow$": "<rootDir>/__mocks__/kubeflow.ts",
16+
"^src/(.*)$": "<rootDir>/src/$1",
17+
"^@/(.*)$": "<rootDir>/src/$1",
18+
},
19+
moduleFileExtensions: ["ts", "tsx", "js", "json"],
20+
transform: {
21+
"^.+\\.(ts|js|html)$": "jest-preset-angular",
22+
},
23+
transformIgnorePatterns: [
24+
"node_modules/(?!(kubeflow|@angular|rxjs|lodash-es)/)",
25+
],
26+
roots: ["<rootDir>/src"],
27+
modulePaths: ["<rootDir>/src"],
28+
};

0 commit comments

Comments
 (0)