Skip to content

Commit

Permalink
feat: upgrading to angular v9 (#267)
Browse files Browse the repository at this point in the history
* chore: upgrading to angular v9

- upgraded angular dependencies to v9
- removed deprecated initUIEvent with UIEvent constructor
- with latest typescript, spyOnProperty getter test failed for es2015
  due to js compilation. Changed test target to es5 to fix this.
- upgraded karma and jasmine to latest

BREAKING CHANGE: This PR sets the angular peer dependencies to v9

* feat: adding inject method to spectator

- This method taps into the type safe TestBed.inject function.
- Marked Spectator.get() as deprecated.

* refactor: updating function signature of inject

* refactor: updating Token<T> type and using with inject

* refactor: updating injectionType with actual declaration
  • Loading branch information
anandtiwary authored Feb 18, 2020
1 parent 23b78da commit e13c955
Show file tree
Hide file tree
Showing 40 changed files with 14,084 additions and 9,217 deletions.
10 changes: 8 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"options": {
"tsConfig": "projects/spectator/tsconfig.lib.json",
"project": "projects/spectator/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "projects/spectator/tsconfig.lib.prod.json"
}
}
},
"test": {
Expand Down Expand Up @@ -42,6 +47,7 @@
}
}
}
}},
}
},
"defaultProject": "spectator"
}
}
22,838 changes: 13,727 additions & 9,111 deletions package-lock.json

Large diffs are not rendered by default.

51 changes: 26 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"license": "MIT",
"description": "Angular tests made easy",
"scripts": {
"postinstall": "ngcc",
"ng": "ng",
"build": "ng build && npm run build:schematics && npm run copy:schematics && npm run copy:docs && npm run copy:bin",
"build:schematics": "tsc -p projects/spectator/schematics/tsconfig.json",
Expand All @@ -25,57 +26,57 @@
"dependencies": {
"@testing-library/dom": "6.1.0",
"jquery": "3.4.1",
"replace-in-file": "^4.1.3"
"replace-in-file": "^4.1.3",
"tslib": "^1.10.0"
},
"devDependencies": {
"git-cz": "^3.2.1",
"@angular-builders/jest": "^8.0.4",
"@angular-devkit/build-angular": "~0.802.0",
"@angular-devkit/build-ng-packagr": "~0.802.0",
"@angular/animations": "~8.2.0",
"@angular/cli": "~8.2.0",
"@angular/common": "~8.2.0",
"@angular/compiler": "~8.2.0",
"@angular/compiler-cli": "~8.2.0",
"@angular/core": "~8.2.0",
"@angular/forms": "~8.2.0",
"@angular/language-service": "~8.2.0",
"@angular/platform-browser": "~8.2.0",
"@angular/platform-browser-dynamic": "~8.2.0",
"@angular/router": "~8.2.0",
"@angular-devkit/build-angular": "~0.900.1",
"@angular-devkit/build-ng-packagr": "~0.900.1",
"@angular-devkit/schematics": "^9.0.1",
"@angular/animations": "~9.0.0",
"@angular/cli": "~9.0.1",
"@angular/common": "~9.0.0",
"@angular/compiler": "~9.0.0",
"@angular/compiler-cli": "~9.0.0",
"@angular/core": "~9.0.0",
"@angular/forms": "~9.0.0",
"@angular/language-service": "~9.0.0",
"@angular/platform-browser": "~9.0.0",
"@angular/platform-browser-dynamic": "~9.0.0",
"@angular/router": "~9.0.0",
"@commitlint/cli": "8.1.0",
"@commitlint/config-angular": "8.1.0",
"@commitlint/config-conventional": "8.1.0",
"@types/jasmine": "~3.3.8",
"@types/jasmine": "~3.5.3",
"@types/jest": "^24.0.15",
"@types/node": "~8.9.4",
"@types/node": "^12.11.1",
"all-contributors-cli": "^4.11.1",
"codelyzer": "^5.0.0",
"codelyzer": "^5.1.2",
"core-js": "^2.5.4",
"cross-env": "^5.1.4",
"cz-conventional-changelog": "^2.1.0",
"helpful-decorators": "^1.7.2",
"husky": "^0.14.3",
"jasmine-core": "~3.4.0",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"jest": "^24.8.0",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine": "~3.1.1",
"karma-jasmine-html-reporter": "^1.4.0",
"lint-staged": "^7.0.2",
"ng-packagr": "^5.1.0",
"ng-packagr": "^9.0.0",
"prettier": "^1.11.1",
"rxjs": "~6.4.0",
"rxjs": "~6.5.4",
"schematics-utilities": "^1.1.1",
"standard-version": "^4.4.0",
"ts-node": "~7.0.0",
"tsickle": "^0.37.0",
"tslib": "^1.9.0",
"tslint": "~5.15.0",
"typescript": "~3.5.3",
"zone.js": "~0.9.1"
"typescript": "~3.7.5",
"zone.js": "~0.10.2"
},
"config": {
"commitizen": {
Expand Down
8 changes: 4 additions & 4 deletions projects/spectator/jest/src/lib/mock.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { FactoryProvider } from '@angular/core';
import { installProtoMethods, CompatibleSpy, SpyObject as BaseSpyObject, InjectableType } from '@ngneat/spectator';
import { FactoryProvider, AbstractType, Type } from '@angular/core';
import { installProtoMethods, CompatibleSpy, SpyObject as BaseSpyObject } from '@ngneat/spectator';

export type SpyObject<T> = BaseSpyObject<T> & { [P in keyof T]: T[P] & (T[P] extends (...args: any[]) => infer R ? jest.Mock<R> : T[P]) };

/**
* @internal
*/
export function createSpyObject<T>(type: InjectableType<T>, template?: Partial<Record<keyof T, any>>): SpyObject<T> {
export function createSpyObject<T>(type: Type<T> | AbstractType<T>, template?: Partial<Record<keyof T, any>>): SpyObject<T> {
const mock: any = { ...template } || {};

installProtoMethods(mock, type.prototype, () => {
Expand Down Expand Up @@ -36,7 +36,7 @@ export function createSpyObject<T>(type: InjectableType<T>, template?: Partial<R
/**
* @publicApi
*/
export function mockProvider<T>(type: InjectableType<T>, properties?: Partial<Record<keyof T, any>>): FactoryProvider {
export function mockProvider<T>(type: Type<T> | AbstractType<T>, properties?: Partial<Record<keyof T, any>>): FactoryProvider {
return {
provide: type,
useFactory: () => createSpyObject(type, properties)
Expand Down
10 changes: 9 additions & 1 deletion projects/spectator/jest/src/lib/spectator-directive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type } from '@angular/core';
import { Type, InjectionToken, AbstractType } from '@angular/core';
import {
createDirectiveFactory as baseCreateDirectiveFactory,
isType,
Expand All @@ -15,9 +15,17 @@ import { mockProvider, SpyObject } from './mock';
* @publicApi
*/
export class SpectatorDirective<D, H = HostComponent> extends BaseSpectatorDirective<D, H> {
/**
* @deprecated Deprecated in favour of inject(). Will be removed once TestBed.get is discontinued.
* @param type Token
*/
public get<T>(type: Token<T> | Token<any>, fromComponentInjector: boolean = false): SpyObject<T> {
return super.get(type, fromComponentInjector) as SpyObject<T>;
}

public inject<T>(token: Token<T>, fromComponentInjector: boolean = false): SpyObject<T> {
return super.inject(token, fromComponentInjector) as SpyObject<T>;
}
}

/**
Expand Down
10 changes: 9 additions & 1 deletion projects/spectator/jest/src/lib/spectator-host.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type } from '@angular/core';
import { Type, InjectionToken, AbstractType } from '@angular/core';
import {
createHostFactory as baseCreateHostFactory,
isType,
Expand All @@ -20,9 +20,17 @@ export type SpectatorWithHost<C, H = HostComponent> = SpectatorHost<C, H>;
* @publicApi
*/
export class SpectatorHost<C, H = HostComponent> extends BaseSpectatorHost<C, H> {
/**
* @deprecated Deprecated in favour of inject(). Will be removed once TestBed.get is discontinued.
* @param type Token
*/
public get<T>(type: Token<T> | Token<any>, fromComponentInjector: boolean = false): SpyObject<T> {
return super.get(type, fromComponentInjector) as SpyObject<T>;
}

public inject<T>(token: Token<T>, fromComponentInjector: boolean = false): SpyObject<T> {
return super.inject(token, fromComponentInjector) as SpyObject<T>;
}
}

/**
Expand Down
7 changes: 6 additions & 1 deletion projects/spectator/jest/src/lib/spectator-http.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type } from '@angular/core';
import { Type, InjectionToken, AbstractType } from '@angular/core';
import {
createHttpFactory as baseCreateHttpFactory,
isType,
Expand All @@ -15,7 +15,12 @@ import { mockProvider, SpyObject } from './mock';
* @publicApi
*/
export interface SpectatorHttp<S> extends BaseSpectatorHttp<S> {
/**
* @deprecated Deprecated in favour of inject(). Will be removed once TestBed.get is discontinued.
* @param type Token
*/
get<T>(token: Token<T> | Token<any>): SpyObject<T>;
inject<T>(token: Token<T>): SpyObject<T>;
}

/**
Expand Down
10 changes: 9 additions & 1 deletion projects/spectator/jest/src/lib/spectator-routing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type } from '@angular/core';
import { Type, InjectionToken, AbstractType } from '@angular/core';
import {
createRoutingFactory as baseCreateRoutingFactory,
isType,
Expand All @@ -14,9 +14,17 @@ import { mockProvider, SpyObject } from './mock';
* @publicApi
*/
export class SpectatorRouting<C> extends BaseSpectatorRouting<C> {
/**
* @deprecated Deprecated in favour of inject(). Will be removed once TestBed.get is discontinued.
* @param type Token
*/
public get<T>(type: Token<T> | Token<any>, fromComponentInjector: boolean = false): SpyObject<T> {
return super.get(type, fromComponentInjector) as SpyObject<T>;
}

public inject<T>(token: Token<T>, fromComponentInjector: boolean = false): SpyObject<T> {
return super.inject(token, fromComponentInjector) as SpyObject<T>;
}
}

/**
Expand Down
7 changes: 6 additions & 1 deletion projects/spectator/jest/src/lib/spectator-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type } from '@angular/core';
import { Type, InjectionToken, AbstractType } from '@angular/core';
import {
createService as baseCreateService,
createServiceFactory as baseCreateServiceFactory,
Expand All @@ -15,7 +15,12 @@ import { mockProvider, SpyObject } from './mock';
* @publicApi
*/
export interface SpectatorService<S> extends BaseSpectatorService<S> {
/**
* @deprecated Deprecated in favour of inject(). Will be removed once TestBed.get is discontinued.
* @param type Token
*/
get<T>(token: Token<T> | Token<any>): SpyObject<T>;
inject<T>(token: Type<T> | InjectionToken<T> | AbstractType<T>): SpyObject<T>;
}

/**
Expand Down
10 changes: 9 additions & 1 deletion projects/spectator/jest/src/lib/spectator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type } from '@angular/core';
import { Type, InjectionToken, AbstractType } from '@angular/core';
import {
createComponentFactory as baseCreateComponentFactory,
isType,
Expand Down Expand Up @@ -30,7 +30,15 @@ export function createComponentFactory<C>(typeOrOptions: SpectatorOptions<C> | T
}

export class Spectator<C> extends BaseSpectator<C> {
/**
* @deprecated Deprecated in favour of inject(). Will be removed once TestBed.get is discontinued.
* @param type Token
*/
public get<T>(type: Token<T> | Token<any>, fromComponentInjector: boolean = false): SpyObject<T> {
return super.get(type, fromComponentInjector) as SpyObject<T>;
}

public inject<T>(token: Token<T>, fromComponentInjector: boolean = false): SpyObject<T> {
return super.inject(token, fromComponentInjector) as SpyObject<T>;
}
}
8 changes: 4 additions & 4 deletions projects/spectator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"replace-in-file": "^4.1.3"
},
"peerDependencies": {
"@angular/common": "^8.0.0",
"@angular/core": "^8.0.0",
"@angular/router": "^8.0.0",
"typescript": ">= 2.8.0"
"@angular/common": "^9.0.1",
"@angular/core": "^9.0.1",
"@angular/router": "^9.0.1",
"typescript": ">= 3.7.0"
},
"bin": {
"spectator-migrate": "./migrate.js"
Expand Down
18 changes: 9 additions & 9 deletions projects/spectator/schematics/src/spectator/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/spectator/schematics/src/spectator/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e13c955

Please sign in to comment.