Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate frontend test framework from Karma to Jest #2995

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8fa2d09
attempt
Yicong-Huang Oct 25, 2024
a4d5121
update karma and jasmine
Yicong-Huang Oct 25, 2024
7a9664f
reduce timeout
Yicong-Huang Oct 25, 2024
47be51c
fix testcases
Yicong-Huang Oct 26, 2024
7b9f8f4
fix tests
Yicong-Huang Oct 26, 2024
571a6c0
fix test framework
Yicong-Huang Oct 26, 2024
cd7fad6
change to log info
Yicong-Huang Oct 26, 2024
84fbe7f
fix format
Yicong-Huang Oct 26, 2024
c6ca0fd
change timeout
Yicong-Huang Oct 26, 2024
a27eceb
change timeout
Yicong-Huang Oct 26, 2024
4948ac4
change ci
Yicong-Huang Oct 26, 2024
1e0cc4b
change test setting
Yicong-Huang Oct 26, 2024
4ee72e7
use new headless
Yicong-Huang Oct 26, 2024
e6ff791
1 browser
Yicong-Huang Oct 26, 2024
22b34c4
change timeout
Yicong-Huang Oct 26, 2024
9765cab
change timeout
Yicong-Huang Oct 26, 2024
e6d25e1
try no nx
Yicong-Huang Oct 26, 2024
fdfdffb
use node 20
Yicong-Huang Oct 26, 2024
486bb79
update other settings
Yicong-Huang Oct 26, 2024
eaeae86
update other settings
Yicong-Huang Oct 26, 2024
e8f6251
prepare yarn 4
Yicong-Huang Oct 26, 2024
0fae3d4
change back
Yicong-Huang Oct 26, 2024
5b2a34f
use nx
Yicong-Huang Oct 26, 2024
98ffd50
change cache key
Yicong-Huang Oct 26, 2024
d797633
update
Yicong-Huang Oct 26, 2024
9686002
update
Yicong-Huang Oct 26, 2024
e792fdd
revert back ram config
Yicong-Huang Oct 26, 2024
c832bcf
remove unused
Yicong-Huang Oct 26, 2024
6f395c4
remove waitwebpack
Yicong-Huang Oct 26, 2024
0930e74
initial setup
Yicong-Huang Oct 27, 2024
1daa196
fix some test
Yicong-Huang Oct 28, 2024
4c78e1b
add jest-codemods
Yicong-Huang Oct 28, 2024
dc5f6d2
Merge branch 'master' into yicong-migrate-to-jest
Yicong-Huang Nov 3, 2024
bcc103b
fix lock
Yicong-Huang Nov 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 4 additions & 28 deletions core/gui/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
"buildOptimizer": true
}
},
"defaultConfiguration": ""
Expand All @@ -83,28 +77,10 @@
}
},
"test": {
"builder": "@angular-builders/custom-webpack:karma",
"builder": "@angular-builders/jest:run",
"options": {
"assets": ["src/assets"],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.test.ts"
}
],
"karmaConfig": "./karma.conf.js",
"main": "src/test.ts",
"polyfills": ["zone.js", "zone.js/testing"],
"styles": [
"node_modules/jointjs/css/layout.css",
"node_modules/jointjs/css/themes/material.css",
"node_modules/jointjs/css/themes/default.css",
"src/styles.scss"
],
"customWebpackConfig": {
"path": "./custom-webpack.config.js"
},
"tsConfig": "src/tsconfig.spec.json"
"tsConfig": "tsconfig.spec.json",
"configPath": "jest.config.ts"
}
},
"lint": {
Expand Down
40 changes: 40 additions & 0 deletions core/gui/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { Config } from "jest";

const esModules = [
"lodash-es",
"@ngrx",
"@angular",
"ng-zorro-antd",
"@ant-design",
"uuid",
"@ngx-formly",
"monaco-editor",
"vscode",
"monaco-editor-wrapper",
"y-monaco",
"@codingame",
"monaco-languageclient",
"@codingame/monaco-editor-wrapper",
].join("|");

const config: Config = {
preset: "jest-preset-angular",
setupFilesAfterEnv: [`${__dirname}/setup.ts`],
moduleNameMapper: {
"\\.(jpg|jpeg|png)$": `${__dirname}/mock-module.js`,
},
transformIgnorePatterns: [`<rootDir>/node_modules/(?!${esModules})`],
transform: {
"^.+\\.(ts|tsx)?$": [
"ts-jest",
{
allowSyntheticDefaultImports: true,
},
],
"^.+\\.(js|mjs)$": "babel-jest",
},
testEnvironment: "jsdom", // Set the environment to jsdom
};


export default config;
51 changes: 0 additions & 51 deletions core/gui/karma.conf.js

This file was deleted.

15 changes: 8 additions & 7 deletions core/gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
},
"devDependencies": {
"@angular-builders/custom-webpack": "16.0.1",
"@angular-builders/jest": "^18.0.0",
"@angular-devkit/build-angular": "16.2.12",
"@angular-eslint/eslint-plugin": "16.3.1",
"@angular-eslint/eslint-plugin-template": "16.3.1",
Expand All @@ -112,16 +113,17 @@
"@types/dagre": "0.7.47",
"@types/file-saver": "2.0.5",
"@types/graphlib": "2.1.8",
"@types/jasmine": "4.6.4",
"@types/jest": "^29.5.14",
"@types/json-schema": "7.0.9",
"@types/lodash": "4.14.179",
"@types/node": "18.15.5",
"@types/node": "^22.8.1",
"@types/papaparse": "5.3.5",
"@types/quill": "2.0.9",
"@types/uuid": "8.3.4",
"@types/validator": "13.12.0",
"@typescript-eslint/eslint-plugin": "7.0.2",
"@typescript-eslint/parser": "7.0.2",
"babel-jest": "^29.7.0",
"babel-plugin-dynamic-import-node": "2.3.3",
"concurrently": "7.4.0",
"eslint": "8.57.0",
Expand All @@ -134,10 +136,8 @@
"fs-extra": "10.0.1",
"git-describe": "4.1.0",
"jasmine-core": "5.4.0",
"jasmine-spec-reporter": "7.0.0",
"karma": "6.4.4",
"karma-chrome-launcher": "3.2.0",
"karma-jasmine": "5.1.0",
"jest": "^29.7.0",
"jest-codemods": "^0.34.0",
"nodecat": "2.0.0",
"nx": "20.0.3",
"nz-tslint-rules": "0.901.2",
Expand All @@ -146,7 +146,8 @@
"rxjs-marbles": "7.0.1",
"sass": "1.71.1",
"style-loader": "3.3.4",
"ts-node": "4.1.0",
"ts-jest": "^29.2.5",
"ts-node": "8.5.0",
"typescript": "5.1.6",
"webpack-bundle-analyzer": "4.5.0"
},
Expand Down
1 change: 1 addition & 0 deletions core/gui/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "jest-preset-angular/setup-jest";
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// import { NzDropDownModule } from "ng-zorro-antd/dropdown";
// import { NzMenuModule } from "ng-zorro-antd/menu";
// import { NzMessageModule } from "ng-zorro-antd/message";
// import { PresetService } from "src/app/workspace/service/preset/preset.service";
// import { PresetService } from "../../workspace/service/preset/preset.service";
// import { CustomNgMaterialModule } from "../../custom-ng-material.module";
// import { nonNull } from "../../util/assert";
// import { TEXERA_FORMLY_CONFIG } from "../formly-config";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { FieldWrapper, FormlyFieldConfig } from "@ngx-formly/core";
import { merge } from "lodash";
import { ReplaySubject } from "rxjs";
import { takeUntil, debounceTime, filter, first } from "rxjs/operators";
import { Preset, PresetService } from "src/app/workspace/service/preset/preset.service";

import { asType } from "../../util/assert";
import { NzMessageService } from "ng-zorro-antd/message";
import { Preset, PresetService } from "../../../workspace/service/preset/preset.service";

/**
* PresetWrapperComponent is a custom formly form field wrapper: https://formly.dev/guide/custom-formly-wrapper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing";
// import { fakeAsync, flush, inject, TestBed, tick } from "@angular/core/testing";
// import { AppSettings } from "src/app/common/app-setting";
// import { AppSettings } from "../../common/app-setting";
// import { UserConfigService, UserConfig } from "./user-config.service";
// import { UserService } from "../user.service";
// import { StubUserService } from "../stub-user.service";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { Observable, of, Subject } from "rxjs";
import { AppSettings } from "src/app/common/app-setting";
import { UserService } from "../user.service";
import { shareReplay, tap } from "rxjs/operators";
import { isType } from "src/app/common/util/assert";
import { AppSettings } from "../../../app-setting";


export type UserConfig = {
[key: string]: string;
Expand Down
2 changes: 1 addition & 1 deletion core/gui/src/app/common/util/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import deepMap from "deep-map";
import {
AttributeType,
SchemaAttribute,
} from "src/app/workspace/service/dynamic-schema/schema-propagation/schema-propagation.service";
} from "../../workspace/service/dynamic-schema/schema-propagation/schema-propagation.service";

export function formatBinaryData(value: string): string {
const length = value.length;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";

import { FiltersComponent } from "./filters.component";
import { StubOperatorMetadataService } from "src/app/workspace/service/operator-metadata/stub-operator-metadata.service";
import { OperatorMetadataService } from "src/app/workspace/service/operator-metadata/operator-metadata.service";
import { WorkflowPersistService } from "src/app/common/service/workflow-persist/workflow-persist.service";
import { StubWorkflowPersistService } from "src/app/common/service/workflow-persist/stub-workflow-persist.service";

import { testWorkflowEntries } from "../../user-dashboard-test-fixtures";
import { NzDropDownModule } from "ng-zorro-antd/dropdown";
import { JWT_OPTIONS, JwtHelperService } from "@auth0/angular-jwt";
import { FormsModule } from "@angular/forms";
import { HttpClientTestingModule } from "@angular/common/http/testing";
import { WorkflowPersistService } from "../../../../common/service/workflow-persist/workflow-persist.service";
import { OperatorMetadataService } from "../../../../workspace/service/operator-metadata/operator-metadata.service";
import {
StubOperatorMetadataService
} from "../../../../workspace/service/operator-metadata/stub-operator-metadata.service";
import { StubWorkflowPersistService } from "../../../../common/service/workflow-persist/stub-workflow-persist.service";

describe("FiltersComponent", () => {
let component: FiltersComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
import { OperatorMetadataService } from "src/app/workspace/service/operator-metadata/operator-metadata.service";
import { OperatorMetadataService } from "../../../../workspace/service/operator-metadata/operator-metadata.service";
import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
import { Observable, of } from "rxjs";
import { DashboardProject } from "../../../type/dashboard-project.interface";
import { remove } from "lodash-es";
import { NotificationService } from "src/app/common/service/notification/notification.service";
import { NotificationService } from "../../../../common/service/notification/notification.service";
import { UserProjectService } from "../../../service/user/project/user-project.service";
import { WorkflowPersistService } from "src/app/common/service/workflow-persist/workflow-persist.service";
import { WorkflowPersistService } from "../../../../common/service/workflow-persist/workflow-persist.service";
import { SearchFilterParameters } from "../../../type/search-filter-parameters";
import { UserService } from "../../../../common/service/user/user.service";
import { switchMap } from "rxjs/operators";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { ListItemComponent } from "./list-item.component";
import { WorkflowPersistService } from "src/app/common/service/workflow-persist/workflow-persist.service";
import { WorkflowPersistService } from "../../common/service/workflow-persist/workflow-persist.service";
import { HttpClientTestingModule } from "@angular/common/http/testing";
import { NzModalService } from "ng-zorro-antd/modal";
import { of, throwError } from "rxjs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ import {
} from "@angular/core";
import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
import { NzModalService } from "ng-zorro-antd/modal";
import { DashboardEntry } from "src/app/dashboard/type/dashboard-entry";
import { ShareAccessComponent } from "../share-access/share-access.component";
import {
WorkflowPersistService,
DEFAULT_WORKFLOW_NAME,
} from "src/app/common/service/workflow-persist/workflow-persist.service";
import { firstValueFrom } from "rxjs";
import { SearchService } from "../../../service/user/search.service";
import { HubWorkflowDetailComponent } from "../../../../hub/component/workflow/detail/hub-workflow-detail.component";
import { HubWorkflowService } from "../../../../hub/service/workflow/hub-workflow.service";
import { DownloadService } from "src/app/dashboard/service/user/download/download.service";
import { formatSize } from "src/app/common/util/size-formatter.util";
import { DashboardEntry } from "../../../type/dashboard-entry";
import { WorkflowPersistService, DEFAULT_WORKFLOW_NAME } from "../../../../common/service/workflow-persist/workflow-persist.service";
import { DownloadService } from "../../../service/user/download/download.service";
import { formatSize } from "../../../../common/util/size-formatter.util";

@UntilDestroy()
@Component({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { NotificationService } from "../../../../common/service/notification/not
import { HttpErrorResponse } from "@angular/common/http";
import { NzMessageService } from "ng-zorro-antd/message";
import { DatasetService } from "../../../service/user/dataset/dataset.service";
import { WorkflowPersistService } from "src/app/common/service/workflow-persist/workflow-persist.service";
import { WorkflowActionService } from "src/app/workspace/service/workflow-graph/model/workflow-action.service";
import { WorkflowPersistService } from "../../../../common/service/workflow-persist/workflow-persist.service";
import { WorkflowActionService } from "../../../../workspace/service/workflow-graph/model/workflow-action.service";

@UntilDestroy()
@Component({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { DatasetVersion } from "../../../../../common/type/dataset";
import { switchMap } from "rxjs/operators";
import { NotificationService } from "../../../../../common/service/notification/notification.service";
import { DownloadService } from "../../../../service/user/download/download.service";
import { formatSize } from "src/app/common/util/size-formatter.util";
import { formatSize } from "../../../../../common/util/size-formatter.util";


@UntilDestroy()
@Component({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { UserProjectListItemComponent } from "./user-project-list-item.component";
import { NotificationService } from "src/app/common/service/notification/notification.service";

import { UserProjectService } from "../../../../service/user/project/user-project.service";
import { DashboardProject } from "../../../../type/dashboard-project.interface";
import { HttpClientTestingModule } from "@angular/common/http/testing";
import { NzModalService } from "ng-zorro-antd/modal";
import { StubUserService } from "../../../../../common/service/user/stub-user.service";
import { UserService } from "../../../../../common/service/user/user.service";
import { HighlightSearchTermsPipe } from "../../user-workflow/user-workflow-list-item/highlight-search-terms.pipe";
import { NotificationService } from "../../../../../common/service/notification/notification.service";

describe("UserProjectListItemComponent", () => {
let component: UserProjectListItemComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
import { DashboardProject } from "../../../../type/dashboard-project.interface";
import { UserProjectService } from "../../../../service/user/project/user-project.service";
import { NotificationService } from "src/app/common/service/notification/notification.service";

import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
import { ShareAccessComponent } from "../../share-access/share-access.component";
import { NzModalService } from "ng-zorro-antd/modal";
import { UserService } from "../../../../../common/service/user/user.service";
import { NotificationService } from "../../../../../common/service/notification/notification.service";

@UntilDestroy()
@Component({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Component, OnInit, inject } from "@angular/core";
import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
import { File, Workflow, MongoExecution, MongoWorkflow } from "../../../../common/type/user";
import { DatasetQuota } from "src/app/dashboard/type/quota-statistic.interface";
import { DatasetQuota } from "../../../type/quota-statistic.interface";
import { NzTableSortFn } from "ng-zorro-antd/table";
import { UserQuotaService } from "src/app/dashboard/service/user/quota/user-quota.service";
import { AdminUserService } from "src/app/dashboard/service/admin/user/admin-user.service";
import { UserQuotaService } from "../../../service/user/quota/user-quota.service";
import { AdminUserService } from "../../../service/admin/user/admin-user.service";
import { NZ_MODAL_DATA } from "ng-zorro-antd/modal";
import * as Plotly from "plotly.js-basic-dist-min";
import { formatSize } from "src/app/common/util/size-formatter.util";
import { formatSize } from "../../../../common/util/size-formatter.util";

type UserServiceType = AdminUserService | UserQuotaService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export class WorkflowExecutionHistoryComponent implements OnInit, AfterViewInit
/**
* display icons corresponding to workflow execution status
*
* NOTES: Colors match with gui/src/app/workspace/service/joint-ui/joint-ui.service.ts line 347
* NOTES: Colors match with gui/../../workspace/service/joint-ui/joint-ui.service.ts line 347
* TODO: Move colors to a config file for changing them once for many files
*/
getExecutionStatus(statusCode: number): string[] {
Expand Down
Loading
Loading