Skip to content

Commit d20c4d6

Browse files
author
Alex Malkevich
authored
Merge pull request #5 from orchestratora/feat-ng8
[Feat] Angular v8 update
2 parents f45e5b5 + 249bcf8 commit d20c4d6

10 files changed

+5610
-5667
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
> Testing utilities for Angular projects
1111
12-
`npm install -D @orchestrator/ngx-testing`
12+
`npm install -D @orchestrator/ngx-testing@next`
1313

1414
## Why?
1515

package-lock.json

+5,473-5,605
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+33-39
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,45 @@
1717
"test:report": "cd coverage && codecov",
1818
"lint": "ng lint",
1919
"e2e": "ng e2e",
20-
"format": "npm-run-all -p format:*",
21-
"format:code": "prettier --write \"projects/**/*.{ts,js,json,?css}\"",
22-
"format:html": "prettyhtml \"projects/**/*.html\"",
20+
"format": "prettier --write \"projects/**/*.{ts,js,json,?css,html}\"",
2321
"pack": "copyfiles LICENSE README.md dist/ngx-testing",
2422
"presemantic-release": "npm run build && npm run pack",
2523
"semantic-release": "semantic-release"
2624
},
2725
"private": true,
2826
"dependencies": {
29-
"@angular/animations": "~7.1.0",
30-
"@angular/common": "~7.1.0",
31-
"@angular/compiler": "~7.1.0",
32-
"@angular/core": "~7.1.0",
33-
"@angular/forms": "~7.1.0",
34-
"@angular/platform-browser": "~7.1.0",
35-
"@angular/platform-browser-dynamic": "~7.1.0",
36-
"@angular/router": "~7.1.0",
37-
"core-js": "^2.5.4",
38-
"rxjs": "~6.3.3",
39-
"zone.js": "~0.8.26"
27+
"@angular/animations": "~8.0.0",
28+
"@angular/common": "~8.0.0",
29+
"@angular/compiler": "~8.0.0",
30+
"@angular/core": "~8.0.0",
31+
"@angular/forms": "~8.0.0",
32+
"@angular/platform-browser": "~8.0.0",
33+
"@angular/platform-browser-dynamic": "~8.0.0",
34+
"@angular/router": "~8.0.0",
35+
"core-js": "^2.0.0",
36+
"rxjs": "~6.5.2",
37+
"zone.js": "~0.9.1"
4038
},
4139
"devDependencies": {
42-
"@angular-devkit/build-angular": "^0.12.2",
43-
"@angular-devkit/build-ng-packagr": "^0.12.2",
44-
"@angular/cli": "~7.1.4",
45-
"@angular/compiler-cli": "~7.1.0",
46-
"@angular/language-service": "~7.1.0",
47-
"@commitlint/cli": "^7.2.1",
48-
"@commitlint/config-conventional": "^7.1.2",
40+
"@angular-devkit/build-angular": "~0.800.2",
41+
"@angular-devkit/build-ng-packagr": "~0.800.2",
42+
"@angular/cli": "~8.0.2",
43+
"@angular/compiler-cli": "~8.0.0",
44+
"@angular/language-service": "~8.0.0",
45+
"@commitlint/cli": "^8.0.0",
46+
"@commitlint/config-conventional": "^8.0.0",
4947
"@semantic-release/changelog": "^3.0.2",
5048
"@semantic-release/commit-analyzer": "^6.1.0",
5149
"@semantic-release/git": "^7.0.8",
52-
"@semantic-release/github": "^5.2.9",
53-
"@semantic-release/npm": "^5.1.4",
50+
"@semantic-release/github": "^5.2.10",
51+
"@semantic-release/npm": "^5.1.9",
5452
"@semantic-release/release-notes-generator": "^7.1.4",
55-
"@starptech/prettyhtml": "^0.8.16",
5653
"@types/jasmine": "~2.8.8",
5754
"@types/jasminewd2": "~2.0.3",
58-
"@types/node": "~8.9.4",
55+
"@types/node": "~12.0.8",
5956
"codecov": "^3.1.0",
60-
"codelyzer": "~4.5.0",
61-
"commitizen": "^3.0.5",
57+
"codelyzer": "^5.1.0",
58+
"commitizen": "^3.1.1",
6259
"copyfiles": "^2.1.0",
6360
"cz-conventional-changelog": "^2.1.0",
6461
"husky": "^1.3.1",
@@ -70,16 +67,17 @@
7067
"karma-jasmine": "~1.1.2",
7168
"karma-jasmine-html-reporter": "^0.2.2",
7269
"lint-staged": "^8.1.0",
73-
"ng-packagr": "^4.2.0",
70+
"ng-packagr": "^5.3.0",
7471
"npm-run-all": "^4.1.5",
72+
"prettier": "^1.18.2",
7573
"protractor": "~5.4.0",
7674
"rimraf": "^2.6.3",
77-
"semantic-release": "^15.13.2",
78-
"ts-node": "~7.0.0",
79-
"tsickle": ">=0.29.0",
80-
"tslib": "^1.9.0",
81-
"tslint": "~5.11.0",
82-
"typescript": "~3.1.6"
75+
"semantic-release": "^15.13.16",
76+
"ts-node": "^8.1.0",
77+
"tsickle": "^0.35.0",
78+
"tslib": "^1.10.0",
79+
"tslint": "~5.17.0",
80+
"typescript": "~3.4.5"
8381
},
8482
"config": {
8583
"commitizen": {
@@ -103,13 +101,9 @@
103101
"tslint -p tsconfig.json -c tslint.json --fix",
104102
"git add"
105103
],
106-
"projects/**/*.{ts,js,json,?css}": [
104+
"projects/**/*.{ts,js,json,?css,html}": [
107105
"prettier --write",
108106
"git add"
109-
],
110-
"projects/**/*.html": [
111-
"prettyhtml",
112-
"git add"
113107
]
114108
}
115109
}

projects/ngx-testing/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"bindings"
2020
],
2121
"peerDependencies": {
22-
"@angular/common": "^7.0.0",
23-
"@angular/core": "^7.0.0",
24-
"@angular/platform-browser": "^7.0.0"
22+
"@angular/common": "^8.0.0",
23+
"@angular/core": "^8.0.0",
24+
"@angular/platform-browser": "^8.0.0"
2525
}
2626
}

projects/ngx-testing/src/lib/host-generator.service.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ export class HostGeneratorService {
6565
return this.generateForDirective<T>();
6666
default:
6767
throw Error(
68-
`HostGeneratorService: Cannot generate host component for unknown kind: ${
69-
this.typeKind
70-
}`,
68+
`HostGeneratorService: Cannot generate host component for unknown kind: ${this.typeKind}`,
7169
);
7270
}
7371
}
@@ -139,7 +137,7 @@ export class HostGeneratorService {
139137

140138
@Component(meta)
141139
class TestHostComponent implements HostComponent<T> {
142-
@ViewChild(type)
140+
@ViewChild(type, { static: false })
143141
instance: T;
144142

145143
constructor() {

projects/ngx-testing/src/lib/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ export type AsHostComponent<T> = HostComponent<T> &
4242
{ [K in keyof T]: T[K] extends EventEmitter<infer A> ? OutputMock<A> : T[K] };
4343

4444
export type TemplateBindings = ComponentFactory<any>['inputs'];
45+
export type TemplateBinding = TemplateBindings extends Array<infer T>
46+
? T
47+
: unknown;
4548

4649
export interface DirectiveIO {
4750
inputs: TemplateBindings;
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Directive, EventEmitter, Input, Output } from '@angular/core';
2+
import { async, TestBed } from '@angular/core/testing';
3+
4+
import { getDirectiveIO } from './util';
5+
6+
describe('Util', () => {
7+
describe('getDirectiveIO() function', () => {
8+
@Directive({ selector: '[ngtTest]' })
9+
class TestDirective {
10+
@Input() input1: any;
11+
// tslint:disable-next-line: no-input-rename
12+
@Input('renamedInput') input2: any;
13+
14+
@Output() output1 = new EventEmitter();
15+
// tslint:disable-next-line: no-output-rename
16+
@Output('renamedOutput') output2 = new EventEmitter();
17+
}
18+
19+
beforeEach(async(() => {
20+
TestBed.configureTestingModule({
21+
declarations: [TestDirective],
22+
}).compileComponents();
23+
}));
24+
25+
it('should return resolved IO of given directive type', () => {
26+
expect(getDirectiveIO(TestDirective)).toEqual({
27+
inputs: [
28+
{ propName: 'input1', templateName: 'input1' },
29+
{ propName: 'input2', templateName: 'renamedInput' },
30+
],
31+
outputs: [
32+
{ propName: 'output1', templateName: 'output1' },
33+
{ propName: 'output2', templateName: 'renamedOutput' },
34+
],
35+
});
36+
});
37+
});
38+
});

projects/ngx-testing/src/lib/util.ts

+51-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,67 @@
11
import { InjectionToken, Type } from '@angular/core';
22
import { TestBed } from '@angular/core/testing';
33

4-
import { DirectiveIO } from './types';
4+
import { DirectiveIO, TemplateBinding, TemplateBindings } from './types';
5+
6+
/**
7+
* @internal
8+
* Defined by Angular
9+
*/
10+
interface PropDecoratorFactory {
11+
bindingPropertyName?: string;
12+
ngMetadataName: string;
13+
}
14+
15+
/**
16+
* @internal
17+
* Defined by Angular
18+
*/
19+
interface PropMetadata {
20+
[prop: string]: PropDecoratorFactory[];
21+
}
22+
23+
interface IOMetadata {
24+
[prop: string]: PropDecoratorFactory;
25+
}
526

627
/**
728
* @internal
829
*/
930
export function getDirectiveIO<T>(dirType: Type<T>): DirectiveIO {
10-
const { inputs, outputs } = (dirType as any).ngBaseDef;
11-
const defToIO = def =>
12-
Object.keys(def).map(key => ({
13-
propName: key,
14-
templateName: def[key] || key,
15-
}));
31+
const propMeta = dirType['__prop__metadata__'] as PropMetadata;
32+
33+
const inputsMeta = filterPropMeta(propMeta, 'Input');
34+
const outputsMeta = filterPropMeta(propMeta, 'Output');
1635

1736
return {
18-
inputs: defToIO(inputs),
19-
outputs: defToIO(outputs),
37+
inputs: propMetaToTemplateBindings(inputsMeta),
38+
outputs: propMetaToTemplateBindings(outputsMeta),
2039
};
2140
}
2241

42+
function propMetaToTemplateBindings(meta: IOMetadata): TemplateBindings {
43+
return Object.keys(meta).map(
44+
propName =>
45+
({
46+
propName,
47+
templateName: meta[propName].bindingPropertyName || propName,
48+
} as TemplateBinding),
49+
);
50+
}
51+
52+
function filterPropMeta(
53+
obj: PropMetadata,
54+
type: 'Input' | 'Output',
55+
): IOMetadata {
56+
return Object.keys(obj).reduce(
57+
(acc, k) => {
58+
const meta = obj[k].find(m => m.ngMetadataName === type);
59+
return meta ? { ...acc, [k]: meta } : acc;
60+
},
61+
{} as IOMetadata,
62+
);
63+
}
64+
2365
/**
2466
* @internal
2567
*/

tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
"outDir": "./dist/out-tsc",
66
"sourceMap": true,
77
"declaration": false,
8-
"module": "es2015",
8+
"module": "esnext",
99
"moduleResolution": "node",
1010
"emitDecoratorMetadata": true,
1111
"experimentalDecorators": true,
1212
"importHelpers": true,
13-
"target": "es5",
13+
"target": "es2015",
1414
"typeRoots": [
1515
"node_modules/@types"
1616
],

tslint.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@
118118
"check-type"
119119
],
120120
"no-output-on-prefix": true,
121-
"use-input-property-decorator": true,
122-
"use-output-property-decorator": true,
123-
"use-host-property-decorator": true,
121+
"no-inputs-metadata-property": true,
122+
"no-outputs-metadata-property": true,
123+
"no-host-metadata-property": true,
124124
"no-input-rename": true,
125125
"no-output-rename": true,
126-
"use-life-cycle-interface": true,
126+
"use-lifecycle-interface": true,
127127
"use-pipe-transform-interface": true,
128128
"component-class-suffix": true,
129129
"directive-class-suffix": true

0 commit comments

Comments
 (0)