Actions
Cleanup #45433
closedCleanup #44530: mgr/dashboard: speed-up Angular unit tests
mgr/dashboard: Don't have two different unit test mechanics
Status:
Resolved
Priority:
Normal
Assignee:
Stephan Müller
Category:
Testing & 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).
Updated by Alfonso Martínez almost 4 years ago
- Status changed from New to Fix Under Review
- Pull request ID set to 34965
Updated by Stephan Müller almost 4 years ago
- Status changed from Fix Under Review to Resolved
Updated by Stephan Müller almost 4 years ago
- Status changed from Resolved to Pending Backport
Updated by Stephan Müller almost 4 years ago
- Copied to Backport #46693: octopus: mgr/dashboard: Don't have two different unit test mechanics added
Updated by Nathan Cutler over 3 years ago
- Status changed from Pending Backport to Resolved
While running with --resolve-parent, the script "backport-create-issue" noticed that all backports of this issue are in status "Resolved" or "Rejected".
Actions