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

Development: Upgrade to Angular 14 and Jest 28 #5202

Merged
merged 18 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ jobs:
env:
NODE_OPTIONS: --max_old_space_size=6144

- run: rm -rf build/resources/main/static

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

Expand Down
1 change: 0 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@
}
}
},
"defaultProject": "artemis",
"cli": {
"analytics": false,
"packageManager": "npm",
Expand Down
5 changes: 4 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ module.exports = {
},
},
},
testEnvironmentOptions: {
url: 'https://artemis.fake/test'
},
roots: ['<rootDir>', `<rootDir>/${baseUrl}`],
modulePaths: [`<rootDir>/${baseUrl}`],
setupFiles: ['jest-date-mock'],
Expand Down Expand Up @@ -63,7 +66,7 @@ module.exports = {
},
setupFilesAfterEnv: ['<rootDir>/src/test/javascript/spec/jest-test-setup.ts', 'jest-extended/all'],
moduleFileExtensions: ['ts', 'html', 'js', 'json', 'mjs'],
resolver: 'jest-preset-angular/build/resolvers/ng-jest-resolver.js',
resolver: '<rootDir>/jest.resolver.js',
transformIgnorePatterns: [`/node_modules/(?!${esModules})`],
transform: {
'^.+\\.(ts|js|mjs|html|svg)$': 'jest-preset-angular',
Expand Down
27 changes: 27 additions & 0 deletions jest.resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = (path, options) => {
// Call the defaultResolver, so we leverage its cache, error handling, etc.
return options.defaultResolver(path, {
...options,
// Use packageFilter to process parsed `package.json` before the resolution (see https://www.npmjs.com/package/resolve#resolveid-opts-cb)
packageFilter: pkg => {
// This is a workaround for https://github.com/uuidjs/uuid/pull/616
//
// jest-environment-jsdom 28+ tries to use browser exports instead of default exports,
// but uuid only offers an ESM browser export and not a CommonJS one. Jest does not yet
// support ESM modules natively, so this causes a Jest error related to trying to parse
// "export" syntax.
//
// This workaround prevents Jest from considering uuid's module-based exports at all;
// it falls back to uuid's CommonJS+node "main" property.
//
// Once we're able to migrate our Jest config to ESM and a browser crypto
// implementation is available for the browser+ESM version of uuid to use (eg, via
// https://github.com/jsdom/jsdom/pull/3352 or a similar polyfill), this can go away.
if (pkg.name === 'uuid') {
delete pkg['exports'];
delete pkg['module'];
}
return pkg;
},
});
};
12,264 changes: 7,476 additions & 4,788 deletions package-lock.json

Large diffs are not rendered by default.

74 changes: 39 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@
"node_modules"
],
"dependencies": {
"@angular/animations": "13.3.11",
"@angular/cdk": "13.3.9",
"@angular/common": "13.3.11",
"@angular/compiler": "13.3.11",
"@angular/core": "13.3.11",
"@angular/forms": "13.3.11",
"@angular/localize": "13.3.11",
"@angular/material": "13.3.9",
"@angular/platform-browser": "13.3.11",
"@angular/platform-browser-dynamic": "13.3.11",
"@angular/router": "13.3.11",
"@angular/service-worker": "13.3.11",
"@angular/animations": "14.0.4",
"@angular/cdk": "14.0.4",
"@angular/common": "14.0.4",
"@angular/compiler": "14.0.4",
"@angular/core": "14.0.4",
"@angular/forms": "14.0.4",
"@angular/localize": "14.0.4",
"@angular/material": "14.0.4",
"@angular/platform-browser": "14.0.4",
"@angular/platform-browser-dynamic": "14.0.4",
"@angular/router": "14.0.4",
"@angular/service-worker": "14.0.4",
"@ctrl/ngx-emoji-mart": "6.2.0",
"@danielmoncada/angular-datetime-picker": "14.1.0",
"@fingerprintjs/fingerprintjs": "3.3.3",
"@fortawesome/angular-fontawesome": "0.10.2",
"@fortawesome/angular-fontawesome": "0.11.1",
"@fortawesome/fontawesome-svg-core": "6.1.1",
"@fortawesome/free-regular-svg-icons": "6.1.1",
"@fortawesome/free-solid-svg-icons": "6.1.1",
"@ls1intum/apollon": "2.11.0",
"@ng-bootstrap/ng-bootstrap": "12.1.2",
"@ng-bootstrap/ng-bootstrap": "13.0.0-beta.1",
"@ngx-translate/core": "14.0.0",
"@ngx-translate/http-loader": "7.0.0",
"@sentry/browser": "7.3.1",
"@swimlane/ngx-charts": "20.1.0",
"@swimlane/ngx-datatable": "20.0.0",
"ace-builds": "1.7.1",
"bootstrap": "5.1.3",
"bootstrap": "5.2.0-beta1",
"brace": "0.11.1",
"compare-versions": "4.1.3",
"core-js": "3.23.3",
Expand All @@ -51,7 +51,7 @@
"mobile-drag-drop": "3.0.0-beta.0",
"ismobilejs-es5": "0.0.1",
"ngx-infinite-scroll": "13.0.2",
"ngx-webstorage": "9.0.0",
"ngx-webstorage": "10.0.1",
"papaparse": "5.3.2",
"process": "0.11.10",
"rxjs": "7.5.5",
Expand All @@ -75,54 +75,58 @@
},
"@swimlane/ngx-datatable": {
"rxjs": "7.5.5"
},
"ngx-infinite-scroll": {
"@angular/common": "14.0.4",
"@angular/core": "14.0.4"
}
},
"devDependencies": {
"@angular-builders/custom-webpack": "13.1.0",
"@angular-builders/jest": "13.0.4",
"@angular-devkit/build-angular": "13.3.8",
"@angular-eslint/eslint-plugin": "13.5.0",
"@angular/cli": "13.3.8",
"@angular/compiler-cli": "13.3.11",
"@angular/language-service": "13.3.11",
"@angular-builders/custom-webpack": "14.0.0",
"@angular-builders/jest": "14.0.0",
"@angular-devkit/build-angular": "14.0.4",
"@angular-eslint/eslint-plugin": "14.0.0",
"@angular/cli": "14.0.4",
"@angular/compiler-cli": "14.0.4",
"@angular/language-service": "14.0.4",
"@types/crypto-js": "4.1.1",
"@types/dompurify": "2.3.3",
"@types/jest": "27.5.2",
"@types/jest": "28.1.4",
"@types/lodash-es": "4.17.6",
"@types/node": "18.0.0",
"@types/node": "18.0.1",
"@types/papaparse": "5.3.2",
"@types/showdown": "2.0.0",
"@types/smoothscroll-polyfill": "0.3.1",
"@types/sockjs-client": "1.5.1",
"@types/uuid": "8.3.4",
"@typescript-eslint/eslint-plugin": "5.30.0",
"@typescript-eslint/eslint-plugin-tslint": "5.30.0",
"@typescript-eslint/parser": "5.30.0",
"@typescript-eslint/eslint-plugin": "5.30.4",
"@typescript-eslint/eslint-plugin-tslint": "5.30.4",
"@typescript-eslint/parser": "5.30.4",
"browser-sync": "2.27.10",
"browser-sync-webpack-plugin": "2.3.0",
"codelyzer": "6.0.2",
"eslint": "8.18.0",
"eslint": "8.19.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-deprecation": "1.3.2",
"eslint-plugin-prettier": "4.2.1",
"eslint-webpack-plugin": "3.2.0",
"folder-hash": "4.0.2",
"husky": "8.0.1",
"jest": "27.5.1",
"jest": "28.1.2",
"jest-canvas-mock": "2.4.0",
"jest-date-mock": "1.0.8",
"jest-extended": "2.0.0",
"jest-junit": "13.2.0",
"jest-preset-angular": "11.1.2",
"jest-junit": "14.0.0",
"jest-preset-angular": "12.1.0",
"lint-staged": "13.0.3",
"merge-jsons-webpack-plugin": "2.0.1",
"ng-mocks": "13.5.2",
"ng-mocks": "14.0.1",
"prettier": "2.7.1",
"sass": "1.53.0",
"ts-jest": "27.1.5",
"ts-jest": "28.0.5",
"tslint": "6.1.3",
"tslint-config-prettier": "1.18.0",
"typescript": "4.6.4",
"typescript": "4.7.4",
"weak-napi": "2.0.2",
"webpack": "5.73.0",
"webpack-bundle-analyzer": "4.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class PasswordResetFinishComponent implements OnInit, AfterViewInit {
success = false;
key = '';

passwordForm = this.fb.group({
passwordForm = this.fb.nonNullable.group({
newPassword: ['', [Validators.required, Validators.minLength(PASSWORD_MIN_LENGTH), Validators.maxLength(PASSWORD_MAX_LENGTH)]],
confirmPassword: ['', [Validators.required, Validators.minLength(PASSWORD_MIN_LENGTH), Validators.maxLength(PASSWORD_MAX_LENGTH)]],
});
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/app/account/password/password.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AccountService } from 'app/core/auth/account.service';
import { PasswordService } from './password.service';
import { ProfileService } from 'app/shared/layouts/profiles/profile.service';
import { FormBuilder, Validators } from '@angular/forms';
import { PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH } from 'app/app.constants';
import { PASSWORD_MAX_LENGTH, PASSWORD_MIN_LENGTH } from 'app/app.constants';

@Component({
selector: 'jhi-password',
Expand All @@ -19,7 +19,7 @@ export class PasswordComponent implements OnInit {
error = false;
success = false;
user?: User;
passwordForm = this.fb.group({
passwordForm = this.fb.nonNullable.group({
currentPassword: ['', [Validators.required]],
newPassword: ['', [Validators.required, Validators.minLength(PASSWORD_MIN_LENGTH), Validators.maxLength(PASSWORD_MAX_LENGTH)]],
confirmPassword: ['', [Validators.required, Validators.minLength(PASSWORD_MIN_LENGTH), Validators.maxLength(PASSWORD_MAX_LENGTH)]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class RegisterComponent implements OnInit, AfterViewInit {

usernamePattern = '^[a-zA-Z0-9]*';

registerForm = this.fb.group({
registerForm = this.fb.nonNullable.group({
firstName: ['', [Validators.required, Validators.minLength(2)]],
lastName: ['', [Validators.required, Validators.minLength(2)]],
login: ['', [Validators.required, Validators.minLength(USERNAME_MIN_LENGTH), Validators.maxLength(USERNAME_MAX_LENGTH), Validators.pattern(this.usernamePattern)]],
Expand Down
14 changes: 7 additions & 7 deletions src/main/webapp/app/account/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export class SettingsComponent implements OnInit {
account: User;
languages = LANGUAGES;
settingsForm = this.fb.group({
firstName: [undefined, [Validators.required, Validators.minLength(2), Validators.maxLength(50)]],
lastName: [undefined, [Validators.required, Validators.minLength(2), Validators.maxLength(50)]],
email: [undefined, [Validators.required, Validators.minLength(5), Validators.maxLength(100), Validators.email]],
langKey: [undefined],
firstName: [undefined as string | undefined, [Validators.required, Validators.minLength(2), Validators.maxLength(50)]],
lastName: [undefined as string | undefined, [Validators.required, Validators.minLength(2), Validators.maxLength(50)]],
email: [undefined as string | undefined, [Validators.required, Validators.minLength(5), Validators.maxLength(100), Validators.email]],
langKey: [undefined as string | undefined],
});
isRegistrationEnabled = false;

Expand Down Expand Up @@ -50,9 +50,9 @@ export class SettingsComponent implements OnInit {
save() {
this.success = false;
// Note: changing the email is currently not supported, because we would need to send another activation link
this.account.firstName = this.settingsForm.get('firstName')!.value;
this.account.lastName = this.settingsForm.get('lastName')!.value;
this.account.langKey = this.settingsForm.get('langKey')!.value;
this.account.firstName = this.settingsForm.get('firstName')!.value || undefined;
this.account.lastName = this.settingsForm.get('lastName')!.value || undefined;
this.account.langKey = this.settingsForm.get('langKey')!.value || undefined;

this.accountService.save(this.account).subscribe({
next: () => {
Expand Down
1 change: 0 additions & 1 deletion src/main/webapp/app/admin/admin.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,5 @@ const ENTITY_STATES = [...adminState];
OrganizationManagementDetailComponent,
OrganizationManagementUpdateComponent,
],
entryComponents: [HealthModalComponent],
})
export class ArtemisAdminModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { PASSWORD_MAX_LENGTH, PASSWORD_MIN_LENGTH, USERNAME_MAX_LENGTH, USERNAME_MIN_LENGTH } from 'app/app.constants';
import { faBan, faSave, faTimes } from '@fortawesome/free-solid-svg-icons';
import { COMMA, ENTER, TAB } from '@angular/cdk/keycodes';
import { FormControl } from '@angular/forms';
import { FormBuilder, FormControl, Validators } from '@angular/forms';
import { MatChipInputEvent } from '@angular/material/chips';
import { AlertService, AlertType } from 'app/core/util/alert.service';
import { ProfileService } from 'app/shared/layouts/profiles/profile.service';
import { ProfileInfo } from 'app/shared/layouts/profiles/profile-info.model';
import { FormBuilder, Validators } from '@angular/forms';

@Component({
selector: 'jhi-user-management-update',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { HttpErrorResponse, HttpHeaders, HttpResponse } from '@angular/common/http';
import { Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { HttpErrorResponse, HttpHeaders, HttpParams, HttpResponse } from '@angular/common/http';
import { ActivatedRoute, Router } from '@angular/router';
import { combineLatest, Subject, Subscription } from 'rxjs';
import { onError } from 'app/shared/util/global.utils';
Expand All @@ -18,8 +18,6 @@ import { LocalStorageService } from 'ngx-webstorage';
import { CourseManagementService } from 'app/course/manage/course-management.service';
import { Course } from 'app/entities/course.model';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { TemplateRef, ViewChild } from '@angular/core';
import { HttpParams } from '@angular/common/http';
import { ButtonSize } from 'app/shared/components/button.component';

export class UserFilter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class ComplaintResponseService {

public convertDateFromClient(complaintResponse: ComplaintResponse): ComplaintResponse {
return Object.assign({}, complaintResponse, {
submittedTime: complaintResponse.submittedTime != undefined && dayjs(complaintResponse.submittedTime).isValid ? complaintResponse.submittedTime.toJSON() : undefined,
submittedTime: complaintResponse.submittedTime != undefined && dayjs(complaintResponse.submittedTime).isValid() ? complaintResponse.submittedTime.toJSON() : undefined,
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/app/complaints/complaint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export class ComplaintService implements IComplaintService {

private convertDateFromClient(complaint: Complaint): Complaint {
return Object.assign({}, complaint, {
submittedTime: complaint.submittedTime && dayjs(complaint.submittedTime).isValid ? complaint.submittedTime.toJSON() : undefined,
submittedTime: complaint.submittedTime && dayjs(complaint.submittedTime).isValid() ? complaint.submittedTime.toJSON() : undefined,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { intersection } from 'lodash-es';
* Async Validator to make sure that a learning goal title is unique within a course
*/
export const titleUniqueValidator = (learningGoalService: LearningGoalService, courseId: number, initialTitle?: string) => {
return (learningGoalTitleControl: FormControl) => {
return (learningGoalTitleControl: FormControl<string | undefined>) => {
return of(learningGoalTitleControl.value).pipe(
delay(250),
switchMap((title) => {
Expand All @@ -26,7 +26,7 @@ export const titleUniqueValidator = (learningGoalService: LearningGoalService, c
if (res.body) {
learningGoalTitles = res.body.map((learningGoal) => learningGoal.title!);
}
if (learningGoalTitles.includes(title)) {
if (title && learningGoalTitles.includes(title)) {
return {
titleUnique: { valid: false },
};
Expand Down Expand Up @@ -111,8 +111,12 @@ export class LearningGoalFormComponent implements OnInit, OnChanges {
initialTitle = this.formData.title;
}
this.form = this.fb.group({
title: [undefined, [Validators.required, Validators.maxLength(255)], [this.titleUniqueValidator(this.learningGoalService, this.courseId, initialTitle)]],
description: [undefined, [Validators.maxLength(10000)]],
title: [
undefined as string | undefined,
[Validators.required, Validators.maxLength(255)],
[this.titleUniqueValidator(this.learningGoalService, this.courseId, initialTitle)],
],
description: [undefined as string | undefined, [Validators.maxLength(10000)]],
});
this.selectedLectureUnitsInTable = [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ import { PrerequisiteImportComponent } from 'app/course/learning-goals/learning-
PrerequisiteImportComponent,
],
exports: [LearningGoalCardComponent, LearningGoalsPopoverComponent],
entryComponents: [LearningGoalDetailModalComponent],
})
export class ArtemisLearningGoalsModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ export class CreateTestRunModalComponent implements OnInit {
const workingTime = this.artemisDurationFromSecondsPipe.transform(defaultWorkingTime ?? 0);
const workingTimeParts = workingTime.split(':');
this.workingTimeForm = new FormGroup({
minutes: new FormControl({ value: parseInt(workingTimeParts[0] ? workingTimeParts[0] : '0', 10), disabled: this.exam.visible }, [
minutes: new FormControl({ value: parseInt(workingTimeParts[0] ? workingTimeParts[0] : '0', 10), disabled: !!this.exam.visible }, [
Validators.min(0),
Validators.required,
]),
seconds: new FormControl({ value: parseInt(workingTimeParts[1] ? workingTimeParts[1] : '0', 10), disabled: this.exam.visible }, [
seconds: new FormControl({ value: parseInt(workingTimeParts[1] ? workingTimeParts[1] : '0', 10), disabled: !!this.exam.visible }, [
Validators.min(0),
Validators.max(59),
Validators.required,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

.exam-monitoring-side-panel-container {
display: flex;
align-items: end;
justify-content: end;
align-items: flex-end;
justify-content: flex-end;
}

@media (max-width: 767px) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import { SubmissionResultStatusModule } from 'app/overview/submission-result-sta
CodeEditorTutorAssessmentContainerComponent,
OrionTutorAssessmentComponent,
],
entryComponents: [ProgrammingAssessmentRepoExportDialogComponent],
exports: [ProgrammingAssessmentRepoExportButtonComponent],
})
export class ArtemisProgrammingAssessmentModule {}
Loading