Skip to content

Commit

Permalink
Merge pull request #448 from hannaeko/avoid-bundling-tests-fixture-prod
Browse files Browse the repository at this point in the history
Avoid bundling the mock interceptor in prod env
  • Loading branch information
matsduf authored Jun 17, 2024
2 parents 63824b2 + 2d257ed commit 2081722
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
15 changes: 3 additions & 12 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, Routes } from '@angular/router';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { HttpClientModule } from '@angular/common/http';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { environment } from '../environments/environment';
Expand Down Expand Up @@ -29,11 +29,6 @@ import { AlertService } from './services/alert.service';
import { NavigationService } from './services/navigation.service';
import { HeaderComponent } from './components/header/header.component';

import { HttpRequestInterceptor } from './interceptors/request.interceptor';
import { HttpMockRequestInterceptor } from './interceptors/mock.interceptor';

export const isMock = environment.mock;

const appRoutes: Routes = [
{ path: 'run-test/:domain', component: DomainComponent },
{ path: 'run-test', component: DomainComponent },
Expand Down Expand Up @@ -82,19 +77,15 @@ const appRoutes: Routes = [
DnsCheckService,
AlertService,
NavigationService,
{
provide: HTTP_INTERCEPTORS,
useClass: isMock ? HttpMockRequestInterceptor : HttpRequestInterceptor,
multi: true
},
{
provide: APP_INITIALIZER,
useFactory: (appService: AppService) => {
return () => appService.loadConfig()
},
multi: true,
deps: [AppService]
}
},
...environment.extraProvider,
],
bootstrap: [AppComponent]
})
Expand Down
14 changes: 0 additions & 14 deletions src/app/interceptors/request.interceptor.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const environment = {
...common,
production: true,
apiEndpoint: '/api',
mock: false
mock: false,
extraProvider: [],
};
9 changes: 9 additions & 0 deletions src/environments/environment.tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { common } from "./common";
import { HTTP_INTERCEPTORS } from "@angular/common/http";
import { HttpMockRequestInterceptor } from "../app/interceptors/mock.interceptor";

export const environment = {
...common,
Expand All @@ -8,4 +10,11 @@ export const environment = {
// Use a non existent file to always load the config from the environment file
configUrl: 'assets/app.config.non-existent.json',
pollingInterval: 0.1 * 1000,
extraProvider: [
{
provide: HTTP_INTERCEPTORS,
useClass: HttpMockRequestInterceptor,
multi: true
}
]
};
11 changes: 10 additions & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.
import { common } from "./common";
import { HttpMockRequestInterceptor } from "../app/interceptors/mock.interceptor";
import { HTTP_INTERCEPTORS } from "@angular/common/http";

export const environment = {
...common,
production: false,
apiEndpoint: '/api',
mock: true
mock: true,
extraProvider: [
{
provide: HTTP_INTERCEPTORS,
useClass: HttpMockRequestInterceptor,
multi: true
}
]
};

0 comments on commit 2081722

Please sign in to comment.