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/>`_.
npm-debug.log
testem.log
/typings
-/src/unit-test-configuration.ts
# e2e
/cypress/screenshots
"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",
}
];
- 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);
'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(() => {
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);
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);
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);
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);
{ 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(''));
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);
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 {
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(() => {
executing_tasks: [{}]
};
- configureTestBed(
- {
- providers: [RbdMirroringService],
- imports: [HttpClientTestingModule]
- },
- true
- );
+ configureTestBed({
+ providers: [RbdMirroringService],
+ imports: [HttpClientTestingModule]
+ });
beforeEach(() => {
service = TestBed.get(RbdMirroringService);
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);
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);
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);
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';
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 {
+++ /dev/null
-export const _DEV_ = false;
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