]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Always use fast angular unit tests 34965/head
authorStephan Müller <smueller@suse.com>
Thu, 7 May 2020 15:13:57 +0000 (17:13 +0200)
committerStephan Müller <smueller@suse.com>
Fri, 8 May 2020 15:33:34 +0000 (17:33 +0200)
This will replace the current approach having a fast testing workaround
that didn't fully work on every test. Now using ng-bullet's optimization
works with every test, therefore there is no need to keep the old
configuration files and use the slow testing on Jenkins.

Fixes: https://tracker.ceph.com/issues/45433
Signed-off-by: Stephan Müller <smueller@suse.com>
19 files changed:
src/pybind/mgr/dashboard/HACKING.rst
src/pybind/mgr/dashboard/frontend/.gitignore
src/pybind/mgr/dashboard/frontend/package.json
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-form/iscsi-target-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-form/nfs-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-list/nfs-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/login-password-form/login-password-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-form/role-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-password-form/user-password-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/rbd-mirroring.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/settings.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/module-status-guard.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/testing/unit-test-helper.ts
src/pybind/mgr/dashboard/frontend/src/unit-test-configuration.ts.sample [deleted file]
src/pybind/mgr/dashboard/run-frontend-unittests.sh

index 6d0f47fab1379d1a07f784646e14273939ce20e7..4c6dc706467fdc4ccea0c52ffc398113a64d5e61 100644 (file)
@@ -315,10 +315,6 @@ to be visible in the rendered template.
 Running Unit Tests
 ~~~~~~~~~~~~~~~~~~
 
-Create ``unit-test-configuration.ts`` file based on
-``unit-test-configuration.ts.sample`` in directory
-``src/pybind/mgr/dashboard/frontend/src``.
-
 Run ``npm run test`` to execute the unit tests via `Jest
 <https://facebook.github.io/jest/>`_.
 
index 5bb225251f09f9660c224423b460d7bacb1ac3d6..e7dc03521bf634cad2c5319bfff3b99155ddaff5 100644 (file)
@@ -31,7 +31,6 @@
 npm-debug.log
 testem.log
 /typings
-/src/unit-test-configuration.ts
 
 # e2e
 /cypress/screenshots
index 3250965721aef185acfde861c7df27aae561e675..1c4fe015a5593c182c1bd828cd4deb598e1101fc 100644 (file)
     "i18n:pull": "npx i18ntool pull -c i18n.config.json",
     "i18n:merge": "npx i18ntool merge -c i18n.config.json",
     "i18n:token": "npx i18ntool config token",
-    "test": "npm run test:config && jest --watch",
-    "test:ci": "npm run test:config && JEST_SILENT_REPORTER_DOTS=true jest --coverage --reporters jest-silent-reporter",
-    "test:config": "if [ ! -e 'src/unit-test-configuration.ts' ]; then cp 'src/unit-test-configuration.ts.sample' 'src/unit-test-configuration.ts'; fi",
+    "test": "jest --watch",
+    "test:ci": "JEST_SILENT_REPORTER_DOTS=true jest --coverage --reporters jest-silent-reporter",
     "e2e": "start-test 4200 'cypress open'",
     "e2e:ci": "start-test 4200 'cypress run -b chrome --headless'",
     "lint:tslint": "ng lint",
     "lint:prettier": "prettier --list-different \"{src,cypress}/**/*.{ts,scss}\"",
     "lint:html": "htmllint src/app/**/*.html && html-linter --config html-linter.config.json",
-    "lint:tsc": "npm run test:config && tsc -p src/tsconfig.app.json --noEmit && tsc -p tsconfig.spec.json --noEmit && tsc -p cypress/tsconfig.json --noEmit",
+    "lint:tsc": "tsc -p src/tsconfig.app.json --noEmit && tsc -p tsconfig.spec.json --noEmit && tsc -p cypress/tsconfig.json --noEmit",
     "lint": "npm run lint:tsc && npm run lint:tslint && npm run lint:prettier && npm run lint:html",
     "fix:prettier": "prettier --write \"{src,cypress}/**/*.{ts,scss}\"",
     "fix:tslint": "npm run lint:tslint -- --fix",
index 3779144ffbef07e4aac9f5ca3f49de187e3faf65..6fa48af6ec4a2b7bb6ec66bcef5d5c2f72ec5e9f 100644 (file)
@@ -141,26 +141,23 @@ describe('IscsiTargetFormComponent', () => {
     }
   ];
 
-  configureTestBed(
-    {
-      declarations: [IscsiTargetFormComponent],
-      imports: [
-        SharedModule,
-        ReactiveFormsModule,
-        HttpClientTestingModule,
-        RouterTestingModule,
-        ToastrModule.forRoot()
-      ],
-      providers: [
-        i18nProviders,
-        {
-          provide: ActivatedRoute,
-          useValue: new ActivatedRouteStub({ target_iqn: undefined })
-        }
-      ]
-    },
-    true
-  );
+  configureTestBed({
+    declarations: [IscsiTargetFormComponent],
+    imports: [
+      SharedModule,
+      ReactiveFormsModule,
+      HttpClientTestingModule,
+      RouterTestingModule,
+      ToastrModule.forRoot()
+    ],
+    providers: [
+      i18nProviders,
+      {
+        provide: ActivatedRoute,
+        useValue: new ActivatedRouteStub({ target_iqn: undefined })
+      }
+    ]
+  });
 
   beforeEach(() => {
     fixture = TestBed.createComponent(IscsiTargetFormComponent);
index 783eeed810d0d1b3ec12cc3d2e4c0db339368e09..cc56046df62e8722418ca1ea32c0b84b4a1fe1b4 100644 (file)
@@ -47,20 +47,17 @@ describe('TelemetryComponent', () => {
     'url'
   ];
 
-  configureTestBed(
-    {
-      declarations: [TelemetryComponent],
-      imports: [
-        HttpClientTestingModule,
-        ReactiveFormsModule,
-        RouterTestingModule,
-        SharedModule,
-        ToastrModule.forRoot()
-      ],
-      providers: i18nProviders
-    },
-    true
-  );
+  configureTestBed({
+    declarations: [TelemetryComponent],
+    imports: [
+      HttpClientTestingModule,
+      ReactiveFormsModule,
+      RouterTestingModule,
+      SharedModule,
+      ToastrModule.forRoot()
+    ],
+    providers: i18nProviders
+  });
 
   describe('configForm', () => {
     beforeEach(() => {
index 4b5ec0c909981dcdc1fa4a27ee00aa2fa2d950e3..bb20702800b17e8dddb27c92d8c8652ce2ffacd6 100644 (file)
@@ -21,29 +21,26 @@ describe('NfsFormComponent', () => {
   let httpTesting: HttpTestingController;
   let activatedRoute: ActivatedRouteStub;
 
-  configureTestBed(
-    {
-      declarations: [NfsFormComponent, NfsFormClientComponent],
-      imports: [
-        HttpClientTestingModule,
-        ReactiveFormsModule,
-        RouterTestingModule,
-        SharedModule,
-        ToastrModule.forRoot(),
-        TypeaheadModule.forRoot()
-      ],
-      providers: [
-        {
-          provide: ActivatedRoute,
-          useValue: new ActivatedRouteStub({ cluster_id: undefined, export_id: undefined })
-        },
-        i18nProviders,
-        SummaryService,
-        CephReleaseNamePipe
-      ]
-    },
-    true
-  );
+  configureTestBed({
+    declarations: [NfsFormComponent, NfsFormClientComponent],
+    imports: [
+      HttpClientTestingModule,
+      ReactiveFormsModule,
+      RouterTestingModule,
+      SharedModule,
+      ToastrModule.forRoot(),
+      TypeaheadModule.forRoot()
+    ],
+    providers: [
+      {
+        provide: ActivatedRoute,
+        useValue: new ActivatedRouteStub({ cluster_id: undefined, export_id: undefined })
+      },
+      i18nProviders,
+      SummaryService,
+      CephReleaseNamePipe
+    ]
+  });
 
   beforeEach(() => {
     const summaryService = TestBed.get(SummaryService);
index 36039aa4d97e85ea97191d943ef1b788699a5a37..d8cbf7c6eac82a489e2c37bdd0fa033143eea20f 100644 (file)
@@ -33,21 +33,18 @@ describe('NfsListComponent', () => {
     summaryService['summaryDataSource'].next(data);
   };
 
-  configureTestBed(
-    {
-      declarations: [NfsListComponent, NfsDetailsComponent],
-      imports: [
-        BrowserAnimationsModule,
-        HttpClientTestingModule,
-        RouterTestingModule,
-        SharedModule,
-        ToastrModule.forRoot(),
-        TabsModule.forRoot()
-      ],
-      providers: [TaskListService, i18nProviders]
-    },
-    true
-  );
+  configureTestBed({
+    declarations: [NfsListComponent, NfsDetailsComponent],
+    imports: [
+      BrowserAnimationsModule,
+      HttpClientTestingModule,
+      RouterTestingModule,
+      SharedModule,
+      ToastrModule.forRoot(),
+      TabsModule.forRoot()
+    ],
+    providers: [TaskListService, i18nProviders]
+  });
 
   beforeEach(() => {
     fixture = TestBed.createComponent(NfsListComponent);
index cf21e749ad70ff4dda40841429e752df5d71970d..c336d26657e6fe579924f089d18b57f86be73411 100755 (executable)
@@ -24,21 +24,18 @@ describe('LoginPasswordFormComponent', () => {
   let authStorageService: AuthStorageService;
   let authService: AuthService;
 
-  configureTestBed(
-    {
-      imports: [
-        HttpClientTestingModule,
-        RouterTestingModule,
-        ReactiveFormsModule,
-        ComponentsModule,
-        ToastrModule.forRoot(),
-        SharedModule
-      ],
-      declarations: [LoginPasswordFormComponent],
-      providers: i18nProviders
-    },
-    true
-  );
+  configureTestBed({
+    imports: [
+      HttpClientTestingModule,
+      RouterTestingModule,
+      ReactiveFormsModule,
+      ComponentsModule,
+      ToastrModule.forRoot(),
+      SharedModule
+    ],
+    declarations: [LoginPasswordFormComponent],
+    providers: i18nProviders
+  });
 
   beforeEach(() => {
     fixture = TestBed.createComponent(LoginPasswordFormComponent);
index 10b5e3b776d720c2b0f830998089f0512cb384b1..3cff98667da42827c3750fa7f0dbda9867cfe7c0 100644 (file)
@@ -31,20 +31,17 @@ describe('RoleFormComponent', () => {
 
   const routes: Routes = [{ path: 'roles', component: FakeComponent }];
 
-  configureTestBed(
-    {
-      imports: [
-        RouterTestingModule.withRoutes(routes),
-        HttpClientTestingModule,
-        ReactiveFormsModule,
-        ToastrModule.forRoot(),
-        SharedModule
-      ],
-      declarations: [RoleFormComponent, FakeComponent],
-      providers: i18nProviders
-    },
-    true
-  );
+  configureTestBed({
+    imports: [
+      RouterTestingModule.withRoutes(routes),
+      HttpClientTestingModule,
+      ReactiveFormsModule,
+      ToastrModule.forRoot(),
+      SharedModule
+    ],
+    declarations: [RoleFormComponent, FakeComponent],
+    providers: i18nProviders
+  });
 
   beforeEach(() => {
     fixture = TestBed.createComponent(RoleFormComponent);
index 9574504f0fd2c30f3c62cfbc8762513bd9efcdea..bd06b8e7dd2c12f85a0c1ae5e75a0fee2983e399 100644 (file)
@@ -44,23 +44,20 @@ describe('UserFormComponent', () => {
     { path: 'users', component: FakeComponent }
   ];
 
-  configureTestBed(
-    {
-      imports: [
-        RouterTestingModule.withRoutes(routes),
-        HttpClientTestingModule,
-        ReactiveFormsModule,
-        ComponentsModule,
-        ToastrModule.forRoot(),
-        SharedModule,
-        ButtonsModule.forRoot(),
-        BsDatepickerModule.forRoot()
-      ],
-      declarations: [UserFormComponent, FakeComponent],
-      providers: i18nProviders
-    },
-    true
-  );
+  configureTestBed({
+    imports: [
+      RouterTestingModule.withRoutes(routes),
+      HttpClientTestingModule,
+      ReactiveFormsModule,
+      ComponentsModule,
+      ToastrModule.forRoot(),
+      SharedModule,
+      ButtonsModule.forRoot(),
+      BsDatepickerModule.forRoot()
+    ],
+    declarations: [UserFormComponent, FakeComponent],
+    providers: i18nProviders
+  });
 
   beforeEach(() => {
     spyOn(TestBed.get(PasswordPolicyService), 'getHelpText').and.callFake(() => of(''));
index 3ac5f040fb0944f66d14cfac580409a0ae25b550..a53f4451cb3bf28416269fac4ea3774ca566c79b 100644 (file)
@@ -22,21 +22,18 @@ describe('UserPasswordFormComponent', () => {
   let router: Router;
   let authStorageService: AuthStorageService;
 
-  configureTestBed(
-    {
-      imports: [
-        HttpClientTestingModule,
-        RouterTestingModule,
-        ReactiveFormsModule,
-        ComponentsModule,
-        ToastrModule.forRoot(),
-        SharedModule
-      ],
-      declarations: [UserPasswordFormComponent],
-      providers: i18nProviders
-    },
-    true
-  );
+  configureTestBed({
+    imports: [
+      HttpClientTestingModule,
+      RouterTestingModule,
+      ReactiveFormsModule,
+      ComponentsModule,
+      ToastrModule.forRoot(),
+      SharedModule
+    ],
+    declarations: [UserPasswordFormComponent],
+    providers: i18nProviders
+  });
 
   beforeEach(() => {
     fixture = TestBed.createComponent(UserPasswordFormComponent);
index 8fa84bf65ae7dc65a65bdf77ff2b3d131925ed07..1302f7a3abee6f7c864c305866d8a6a5b0f1d054 100644 (file)
@@ -1,10 +1,10 @@
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { By } from '@angular/platform-browser';
 
-import { configureTestSuite } from 'ng-bullet';
 import { MockModule } from 'ng-mocks';
 import { of } from 'rxjs';
 
+import { configureTestBed } from '../../../../testing/unit-test-helper';
 import { Permission, Permissions } from '../../../shared/models/permissions';
 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
 import {
@@ -49,23 +49,21 @@ describe('NavigationComponent', () => {
   let component: NavigationComponent;
   let fixture: ComponentFixture<NavigationComponent>;
 
-  configureTestSuite(() => {
-    TestBed.configureTestingModule({
-      declarations: [NavigationComponent],
-      imports: [MockModule(NavigationModule)],
-      providers: [
-        {
-          provide: AuthStorageService,
-          useValue: {
-            getPermissions: jest.fn(),
-            isPwdDisplayed$: { subscribe: jest.fn() }
-          }
-        },
-        { provide: SummaryService, useValue: { subscribe: jest.fn() } },
-        { provide: FeatureTogglesService, useValue: { get: jest.fn() } },
-        { provide: PrometheusAlertService, useValue: { alerts: [] } }
-      ]
-    });
+  configureTestBed({
+    declarations: [NavigationComponent],
+    imports: [MockModule(NavigationModule)],
+    providers: [
+      {
+        provide: AuthStorageService,
+        useValue: {
+          getPermissions: jest.fn(),
+          isPwdDisplayed$: { subscribe: jest.fn() }
+        }
+      },
+      { provide: SummaryService, useValue: { subscribe: jest.fn() } },
+      { provide: FeatureTogglesService, useValue: { get: jest.fn() } },
+      { provide: PrometheusAlertService, useValue: { alerts: [] } }
+    ]
   });
 
   beforeEach(() => {
index 37be86346dd0cca9112bf8facdb5fa2adc7fc086..5aacb19d9cf7088d582b32ccd17a066432fa5729 100644 (file)
@@ -27,13 +27,10 @@ describe('RbdMirroringService', () => {
     executing_tasks: [{}]
   };
 
-  configureTestBed(
-    {
-      providers: [RbdMirroringService],
-      imports: [HttpClientTestingModule]
-    },
-    true
-  );
+  configureTestBed({
+    providers: [RbdMirroringService],
+    imports: [HttpClientTestingModule]
+  });
 
   beforeEach(() => {
     service = TestBed.get(RbdMirroringService);
index 86b8c06e503a25c667400c95729d555d21c969fd..dd73fe9cd0e2603dcd16f7d09e17cfad24a6b3a3 100644 (file)
@@ -11,13 +11,10 @@ describe('SettingsService', () => {
   const exampleUrl = 'api/settings/something';
   const exampleValue = 'http://localhost:3000';
 
-  configureTestBed(
-    {
-      providers: [SettingsService],
-      imports: [HttpClientTestingModule]
-    },
-    true
-  );
+  configureTestBed({
+    providers: [SettingsService],
+    imports: [HttpClientTestingModule]
+  });
 
   beforeEach(() => {
     service = TestBed.get(SettingsService);
index 9912d67bea5e4cf76869afbcc030bab3ca103ab8..f1fbcd38baba986f7dddfcd749f909c5d91d68e4 100644 (file)
@@ -39,14 +39,11 @@ describe('ModuleStatusGuardService', () => {
     expect(router.url).toBe(urlResult);
   };
 
-  configureTestBed(
-    {
-      imports: [RouterTestingModule.withRoutes(routes)],
-      providers: [ModuleStatusGuardService, { provide: HttpClient, useValue: fakeService }],
-      declarations: [FooComponent]
-    },
-    true
-  );
+  configureTestBed({
+    imports: [RouterTestingModule.withRoutes(routes)],
+    providers: [ModuleStatusGuardService, { provide: HttpClient, useValue: fakeService }],
+    declarations: [FooComponent]
+  });
 
   beforeEach(() => {
     service = TestBed.get(ModuleStatusGuardService);
index 6c797d50633fbcd488e781bdc402ef240805051c..be83c323c704bb711d3320c22a042aec31a8216f 100644 (file)
@@ -35,12 +35,9 @@ describe('TaskManagerService', () => {
   let summaryService: any;
   let called: boolean;
 
-  configureTestBed(
-    {
-      providers: [TaskManagerService, { provide: SummaryService, useClass: SummaryServiceMock }]
-    },
-    true
-  );
+  configureTestBed({
+    providers: [TaskManagerService, { provide: SummaryService, useClass: SummaryServiceMock }]
+  });
 
   beforeEach(() => {
     taskManagerService = TestBed.get(TaskManagerService);
index e7d8b6fdd5c108b0b691df4539c308c85259a7a2..fa8a326bbbe7dd5eb683c96f7f34df93fe3ab365 100644 (file)
@@ -1,9 +1,10 @@
 import { LOCALE_ID, TRANSLATIONS, TRANSLATIONS_FORMAT, Type } from '@angular/core';
-import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { AbstractControl } from '@angular/forms';
 import { By } from '@angular/platform-browser';
 
 import { I18n } from '@ngx-translate/i18n-polyfill';
+import { configureTestSuite } from 'ng-bullet';
 import { BsModalRef } from 'ngx-bootstrap/modal';
 
 import { TableActionsComponent } from '../app/shared/datatable/table-actions/table-actions.component';
@@ -18,29 +19,9 @@ import {
   AlertmanagerNotificationAlert,
   PrometheusRule
 } from '../app/shared/models/prometheus-alerts';
-import { _DEV_ } from '../unit-test-configuration';
-
-export function configureTestBed(configuration: any, useOldMethod?: boolean) {
-  if (_DEV_ && !useOldMethod) {
-    const resetTestingModule = TestBed.resetTestingModule;
-    beforeAll((done) =>
-      (async () => {
-        TestBed.resetTestingModule();
-        TestBed.configureTestingModule(configuration);
-        // prevent Angular from resetting testing module
-        TestBed.resetTestingModule = () => TestBed;
-      })()
-        .then(done)
-        .catch(done.fail)
-    );
-    afterAll(() => {
-      TestBed.resetTestingModule = resetTestingModule;
-    });
-  } else {
-    beforeEach(async(() => {
-      TestBed.configureTestingModule(configuration);
-    }));
-  }
+
+export function configureTestBed(configuration: any) {
+  configureTestSuite(() => TestBed.configureTestingModule(configuration));
 }
 
 export class PermissionHelper {
diff --git a/src/pybind/mgr/dashboard/frontend/src/unit-test-configuration.ts.sample b/src/pybind/mgr/dashboard/frontend/src/unit-test-configuration.ts.sample
deleted file mode 100644 (file)
index 74dbf2c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-export const _DEV_ = false;
index 38c47f8e4d779228bdbfb3618b16200f59674baf..6195750147f19ca577a1b076c40758a74fca42f5 100755 (executable)
@@ -14,19 +14,8 @@ fi
 npm run build -- --prod --progress=false || failed=true
 
 # Unit Tests
-config='src/unit-test-configuration.ts'
-if [ -e $config ]; then
-  mv $config ${config}_old
-fi
-cp ${config}.sample $config
-
 npm run test:ci || failed=true
 
-rm $config
-if [ -e ${config}_old ]; then
-  mv ${config}_old $config
-fi
-
 # Linting
 npm run lint --silent
 if [ $? -gt 0 ]; then