-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compiler): introduce
NgJestCompiler
for code compilation
Closes #288 Closes #322 Closes #353 BREAKING CHANGE: With the new jest transformer, `jest-preset-angular` now switches to default to use this new transformer and no longer use `ts-jest` to transform codes. Users who are currently doing in jest config ``` // jest.config.js module.exports = { // [...] transform: { '^.+\\.(ts|js|html)$': 'ts-jest', }, } ``` should change to ``` // jest.config.js module.exports = { // [...] transform: { '^.+\\.(ts|js|html)$': 'jest-preset-angular', }, } ``` `isolatedModule: true` will still use `ts-jest` to compile `ts` to `js` but you won't get full compatibility with Ivy.
- Loading branch information
Showing
42 changed files
with
2,352 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
e2e/test-app-v10/src/app/dynamic-component/dynamic-button.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-dynamic-button', | ||
template: ` | ||
<button (click)="onClick()"> | ||
Hello | ||
</button> | ||
`, | ||
}) | ||
export class DynamicButtonComponent { | ||
onClick() { | ||
console.log('Click!'); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
e2e/test-app-v10/src/app/dynamic-component/dynamic-host.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { DynamicHostComponent } from './dynamic-host.component'; | ||
import { DynamicHostModule } from './dynamic-host.module'; | ||
|
||
describe('Dynamic components', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [DynamicHostModule], | ||
}); | ||
}); | ||
|
||
it('dynamically renders a button', async () => { | ||
const fixture = TestBed.createComponent(DynamicHostComponent); | ||
fixture.detectChanges(); | ||
const button = fixture.debugElement.query(By.css('button')).nativeElement as HTMLButtonElement; | ||
expect(button.textContent).toContain('Hello'); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
e2e/test-app-v10/src/app/dynamic-component/dynamic-host.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Component } from '@angular/core'; | ||
import { DynamicButtonComponent } from './dynamic-button.component'; | ||
|
||
@Component({ | ||
selector: 'app-dynamic-host', | ||
template: ` | ||
<ng-container [ngComponentOutlet]="dynamicComponentType"></ng-container> | ||
`, | ||
}) | ||
export class DynamicHostComponent { | ||
dynamicComponentType = DynamicButtonComponent; | ||
} |
10 changes: 10 additions & 0 deletions
10
e2e/test-app-v10/src/app/dynamic-component/dynamic-host.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { DynamicHostComponent } from './dynamic-host.component'; | ||
|
||
@NgModule({ | ||
declarations: [DynamicHostComponent], | ||
exports: [DynamicHostComponent], | ||
imports: [CommonModule], | ||
}) | ||
export class DynamicHostModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { forwardRef, Inject, ReflectiveInjector } from '@angular/core'; | ||
|
||
class Door { | ||
lock: Lock; | ||
|
||
// Door attempts to inject Lock, despite it not being defined yet. | ||
// forwardRef makes this possible. | ||
constructor(@Inject(forwardRef(() => Lock)) lock: Lock) { | ||
this.lock = lock; | ||
} | ||
} | ||
|
||
// Only at this point Lock is defined. | ||
class Lock {} | ||
|
||
test('should work', () => { | ||
const injector = ReflectiveInjector.resolveAndCreate([Door, Lock]); | ||
const door = injector.get(Door); | ||
expect(door instanceof Door).toBeTruthy(); | ||
expect(door.lock instanceof Lock).toBeTruthy(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
e2e/test-app-v9/src/app/ngc-compiled-lib/ngc-compiled-lib.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { Ng2GoogleChartsModule } from 'ng2-google-charts'; | ||
import { GeoChartComponent } from './ngc-compiled-lib.component'; | ||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; | ||
|
||
describe('GeoChartComponent', () => { | ||
let component: GeoChartComponent; | ||
let fixture: ComponentFixture<GeoChartComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
CommonModule, | ||
Ng2GoogleChartsModule, | ||
], | ||
providers: [], | ||
declarations: [ GeoChartComponent ], | ||
schemas: [ | ||
CUSTOM_ELEMENTS_SCHEMA, | ||
], | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(GeoChartComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
e2e/test-app-v9/src/app/ngc-compiled-lib/ngc-compiled-lib.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'; | ||
import { GoogleChartInterface } from 'ng2-google-charts'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
|
||
@Component({ | ||
// tslint:disable-next-line:component-selector | ||
selector: 'influo-geo-chart', | ||
template: ` | ||
<google-chart | ||
*ngIf="googleChartConfig$ | async as googleChartConfig; else loader" | ||
[data]="googleChartConfig"> | ||
</google-chart> | ||
<ng-template #loader> | ||
<mat-spinner color="accent" diameter="80" strokeWidth="8"></mat-spinner> | ||
</ng-template> | ||
`, | ||
}) | ||
export class GeoChartComponent implements OnInit, OnChanges { | ||
@Input() columns: any; | ||
@Input() config: GoogleChartInterface; | ||
@Input() data: Array<Array<string | number>>; | ||
|
||
private defaultConfig: GoogleChartInterface = { | ||
chartType: 'GeoChart', | ||
dataTable: [], | ||
options: { | ||
legend: false, | ||
region: 155, | ||
enableRegionInteractivity: true, | ||
displayMode: 'region', | ||
colors: [ '#e6e6e6', '#1672AD' ], | ||
datalessRegionColor: '#e6e6e6', | ||
}, | ||
}; | ||
|
||
constructor() { | ||
} | ||
|
||
_googleChartConfig = new BehaviorSubject<GoogleChartInterface | null>(null); | ||
|
||
set googleChartConfig(config: GoogleChartInterface) { | ||
const value = this._googleChartConfig.getValue() || {}; | ||
|
||
this._googleChartConfig.next(Object.assign({}, value, config)); | ||
} | ||
|
||
get googleChartConfig$() { | ||
return this._googleChartConfig.asObservable(); | ||
} | ||
|
||
ngOnInit() { | ||
} | ||
|
||
ngOnChanges(changes: SimpleChanges): void { | ||
if (this.columns && this.data) { | ||
this.googleChartConfig = Object.assign({}, this.defaultConfig, this.config, { | ||
dataTable: [ | ||
this.columns, | ||
...this.data, | ||
], | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.scss'], | ||
}) | ||
export class AppComponent { | ||
title = 'test-app-v10'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'foo-root', | ||
template: `<h1>Hello World !!</h1>`, | ||
}) | ||
export class FooComponent { | ||
title: number = 'test-app-v10'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
export class ClassInject {} | ||
|
||
@Injectable() | ||
export class MyService { | ||
// eslint-disable-next-line | ||
constructor(_v: ClassInject) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { getFoo } from './foo'; | ||
|
||
jest.mock('./foo'); | ||
|
||
console.log(getFoo()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function getFoo(): string { | ||
return 'foo'; | ||
} |
File renamed without changes.
Oops, something went wrong.