Project

General

Profile

Cleanup #45433

Cleanup #44530: mgr/dashboard: speed-up Angular unit tests

mgr/dashboard: Don't have two different unit test mechanics

Added by Stephan Müller 2 months ago. Updated 3 days ago.

Status:
Resolved
Priority:
Normal
Category:
dashboard/qa
Target version:
-
% Done:

0%

Tags:
Backport:
octopus
Reviewed:
Affected Versions:
Pull request ID:

Description

Use the DEV test method as default. To be able to do that our workaround needs to include a new statement. It has to set `testBedApi._instantiated` to false after every test.

This will look like the following in the end:

diff --git a/src/pybind/mgr/dashboard/frontend/src/testing/unit-test-helper.ts b/src/pybind/mgr/dashboard/frontend/src/testing/unit-test-helper.ts
index b7de47f303..e94c1a3df1 100644
--- a/src/pybind/mgr/dashboard/frontend/src/testing/unit-test-helper.ts
+++ b/src/pybind/mgr/dashboard/frontend/src/testing/unit-test-helper.ts
@@ -1,5 +1,5 @@
 import { LOCALE_ID, TRANSLATIONS, TRANSLATIONS_FORMAT, Type } from '@angular/core';
-import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { ComponentFixture, getTestBed, TestBed } from '@angular/core/testing';
 import { AbstractControl } from '@angular/forms';
 import { By } from '@angular/platform-browser';

@@ -18,31 +18,28 @@ import {
   AlertmanagerNotificationAlert,
   PrometheusRule
 } from '../app/shared/models/prometheus-alerts';
-import { _DEV_ } from '../unit-test-configuration';
 import { CrushNode } from '../app/shared/models/crush-node';
 import { CrushRule, CrushRuleConfig } from '../app/shared/models/crush-rule';

-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(() => {
+export function configureTestBed(configuration: any) {
+  const testBedApi: any = getTestBed();
+  const resetTestingModule = TestBed.resetTestingModule;
+  beforeAll((done) =>
+    (async () => {
+      // prevent Angular from resetting testing module
+      TestBed.resetTestingModule = () => TestBed;
+      TestBed.resetTestingModule();
       TestBed.configureTestingModule(configuration);
-    }));
-  }
+    })()
+      .then(done)
+      .catch(done.fail)
+  );
+  afterEach(() => {
+    testBedApi._instantiated = false;
+  });
+  afterAll(() => {
+    TestBed.resetTestingModule = resetTestingModule;
+  });
 }

 export class PermissionHelper {

This means to remove the unit test configuration and amending the documentation as well as the unit test script (And remove the usage of the second parameter).

History

#1 Updated by Stephan Müller about 2 months ago

  • Backport set to octopus

#2 Updated by Alfonso Martínez about 2 months ago

  • Status changed from New to Fix Under Review
  • Pull request ID set to 34965

#3 Updated by Stephan Müller 3 days ago

  • Status changed from Fix Under Review to Resolved

Also available in: Atom PDF