Ng not ejected anymore

This commit is contained in:
Maxime GRIS
2018-02-25 22:01:57 +01:00
parent 1ae6f7aedc
commit 67ab31c458
26 changed files with 473 additions and 733 deletions

View File

@@ -1,7 +1,9 @@
import { TestBed, async } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
import { ElectronService } from 'app/providers/electron.service';
import { ElectronService } from './providers/electron.service';
import { TranslateService, TranslateModule } from '@ngx-translate/core';
describe('AppComponent', () => {
beforeEach(async(() => {
@@ -9,10 +11,13 @@ describe('AppComponent', () => {
declarations: [
AppComponent
],
providers : [
ElectronService
providers: [
ElectronService,
{ provide: TranslateService, useClass: TranslateServiceStub }
],
imports: [RouterTestingModule]
imports: [RouterTestingModule,
TranslateModule.forRoot()
]
}).compileComponents();
}));
@@ -22,3 +27,8 @@ describe('AppComponent', () => {
expect(app).toBeTruthy();
}));
});
class TranslateServiceStub {
setDefaultLang(lang: string): void {
}
}

View File

@@ -1,6 +1,7 @@
import { Component } from '@angular/core';
import { ElectronService } from './providers/electron.service';
import { TranslateService } from '@ngx-translate/core';
import { AppConfig } from './app.config';
@Component({
selector: 'app-root',
@@ -12,13 +13,12 @@ export class AppComponent {
private translate: TranslateService) {
translate.setDefaultLang('en');
console.log('AppConfig', AppConfig);
if (electronService.isElectron()) {
console.log('Mode electron');
// Check if electron is correctly injected (see externals in webpack.config.js)
console.log('c', electronService.ipcRenderer);
// Check if nodeJs childProcess is correctly injected (see externals in webpack.config.js)
console.log('c', electronService.childProcess);
console.log('Electron ipcRenderer', electronService.ipcRenderer);
console.log('NodeJS childProcess', electronService.childProcess);
} else {
console.log('Mode web');
}

23
src/app/app.config.ts Normal file
View File

@@ -0,0 +1,23 @@
import { CONF_LOCAL } from '../environments/environment.local';
import { CONF_DEV } from '../environments/environment.dev';
import { CONF_PROD } from '../environments/environment.prod';
const ENV = 'prod';
const LOCAL: String = 'local';
const DEV: String = 'dev';
const PROD: String = 'prod';
let conf: any;
console.log('Env', ENV);
if (ENV === PROD) {
conf = CONF_PROD;
} else if (ENV === DEV) {
conf = CONF_DEV;
} else {
conf = CONF_LOCAL;
}
export const AppConfig = Object.assign({}, conf);

View File

@@ -15,7 +15,7 @@ import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { ElectronService } from './providers/electron.service';
import { WebviewDirective } from 'app/directives/webview.directive';
import { WebviewDirective } from './directives/webview.directive';
import { AppComponent } from './app.component';
import { HomeComponent } from './components/home/home.component';

View File

@@ -1,6 +1,7 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HomeComponent } from './home.component';
import { TranslateModule } from '@ngx-translate/core';
describe('HomeComponent', () => {
let component: HomeComponent;
@@ -8,7 +9,10 @@ describe('HomeComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ HomeComponent ]
declarations: [ HomeComponent ],
imports: [
TranslateModule.forRoot()
]
})
.compileComponents();
}));
@@ -23,16 +27,8 @@ describe('HomeComponent', () => {
expect(component).toBeTruthy();
});
it(`should have as title 'App works !'`, async(() => {
fixture = TestBed.createComponent(HomeComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('App works !');
}));
it('should render title in a h1 tag', async(() => {
fixture = TestBed.createComponent(HomeComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('App works !');
expect(compiled.querySelector('h1').textContent).toBeTruthy();
}));
});

View File

@@ -0,0 +1,9 @@
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `index.ts`, but if you do
// `ng build --env=prod` then `index.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.
export const CONF_DEV = {
production: false,
environment: 'DEV'
};

View File

@@ -0,0 +1,4 @@
export const CONF_LOCAL = {
production: false,
environment: 'LOCAL'
};

View File

@@ -0,0 +1,4 @@
export const CONF_PROD = {
production: true,
environment: 'PROD'
};

View File

@@ -1,5 +0,0 @@
// This file contains production variables. (When you work in PROD MODE)
// This file is use by webpack. Please don't rename it and don't move it to another directory.
export const environment = {
production: true
};

View File

@@ -1,5 +0,0 @@
// This file contains development variables. (When you work in DEV MODE)
// This file is use by webpack. Please don't rename it and don't move it to another directory.
export const environment = {
production: false
};

View File

@@ -2,9 +2,9 @@ import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from 'environments';
import { AppConfig } from './app/app.config';
if (environment.production) {
if (AppConfig.production) {
enableProdMode();
}

View File

@@ -11,13 +11,15 @@ import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
import { Observable } from 'rxjs/Observable';
import { TranslateLoader, TranslateService } from '@ngx-translate/core';
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
declare const __karma__: any;
declare const require: any;
// Prevent Karma from running prematurely.
__karma__.loaded = function () {};
__karma__.loaded = function () { };
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
@@ -28,5 +30,6 @@ getTestBed().initTestEnvironment(
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
// Finally, start Karma to run the tests.
__karma__.start();