-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add console logger * chore: keep internal path mappings * chore: support Node.js 10 * test: fix tests * feat: rename to LumberjackConsole * fix: remove barrel to remove circular dependency warning
- Loading branch information
Showing
35 changed files
with
409 additions
and
33 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
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,5 @@ | ||
# Internal test utilities for console driver | ||
|
||
## Running unit tests | ||
|
||
Run `ng test internal-console-driver-test-util` to execute the unit tests. |
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,14 @@ | ||
const path = require('path'); | ||
|
||
const getBaseKarmaConfig = require('../../../../karma.conf'); | ||
|
||
module.exports = (config) => { | ||
const baseConfig = getBaseKarmaConfig(); | ||
config.set({ | ||
...baseConfig, | ||
coverageIstanbulReporter: { | ||
...baseConfig.coverageIstanbulReporter, | ||
dir: path.join(__dirname, '../../../../coverage/libs/internal/test-util'), | ||
}, | ||
}); | ||
}; |
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,8 @@ | ||
/* | ||
* Public API Surface of @internal/console-driver/test-util | ||
*/ | ||
|
||
export * from './lib/noop-console/noop-console.module'; | ||
export * from './lib/noop-console/noop-console.service'; | ||
export * from './lib/spy-console/spy-console.module'; | ||
export * from './lib/spy-console/spy-console.service'; |
17 changes: 17 additions & 0 deletions
17
libs/internal/console-driver/test-util/src/lib/noop-console/noop-console.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,17 @@ | ||
import { NgModule, Optional, SkipSelf } from '@angular/core'; | ||
|
||
import { LumberjackConsoleToken } from '@ngworker/lumberjack/console-driver'; | ||
|
||
import { NoopConsole } from './noop-console.service'; | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ | ||
deps: [[new Optional(), new SkipSelf(), NoopConsole]], | ||
provide: LumberjackConsoleToken, | ||
useFactory: (maybeExistingInstance: NoopConsole | null): NoopConsole => | ||
maybeExistingInstance || new NoopConsole(), | ||
}, | ||
], | ||
}) | ||
export class NoopConsoleModule {} |
33 changes: 33 additions & 0 deletions
33
libs/internal/console-driver/test-util/src/lib/noop-console/noop-console.service.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,33 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
import { LumberjackConsole } from '@ngworker/lumberjack/console-driver'; | ||
|
||
/** | ||
* No-op console logger. | ||
* | ||
* Every method is a no-op. | ||
*/ | ||
@Injectable() | ||
export class NoopConsole implements LumberjackConsole { | ||
// tslint:disable: no-any | ||
debug(...data: any[]): void; | ||
debug(message?: any, ...optionalParams: any[]): void; | ||
debug(message?: any, ...optionalParams: any[]) {} | ||
|
||
error(...data: any[]): void; | ||
error(message?: any, ...optionalParams: any[]): void; | ||
error(message?: any, ...optionalParams: any[]) {} | ||
|
||
info(...data: any[]): void; | ||
info(message?: any, ...optionalParams: any[]): void; | ||
info(message?: any, ...optionalParams: any[]) {} | ||
|
||
trace(...data: any[]): void; | ||
trace(message?: any, ...optionalParams: any[]): void; | ||
trace(message?: any, ...optionalParams: any[]) {} | ||
|
||
warn(...data: any[]): void; | ||
warn(message?: any, ...optionalParams: any[]): void; | ||
warn(message?: any, ...optionalParams: any[]) {} | ||
// tslint:enable: no-any | ||
} |
16 changes: 16 additions & 0 deletions
16
libs/internal/console-driver/test-util/src/lib/spy-console/spy-console.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,16 @@ | ||
import { NgModule, Optional, SkipSelf } from '@angular/core'; | ||
|
||
import { LumberjackConsoleToken } from '@ngworker/lumberjack/console-driver'; | ||
|
||
import { SpyConsole } from './spy-console.service'; | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ | ||
deps: [[new Optional(), new SkipSelf(), SpyConsole]], | ||
provide: LumberjackConsoleToken, | ||
useFactory: (maybeExistingInstance: SpyConsole | null): SpyConsole => maybeExistingInstance || new SpyConsole(), | ||
}, | ||
], | ||
}) | ||
export class SpyConsoleModule {} |
36 changes: 36 additions & 0 deletions
36
libs/internal/console-driver/test-util/src/lib/spy-console/spy-console.service.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,36 @@ | ||
import { SpyConsole } from './spy-console.service'; | ||
|
||
describe(SpyConsole.name, () => { | ||
beforeEach(() => { | ||
spy = new SpyConsole(); | ||
}); | ||
|
||
let spy: SpyConsole; | ||
|
||
it('can be passed a lot of arguments', () => { | ||
const hundredNumbers = Array(100) | ||
.fill(undefined) | ||
.map((_, index) => index + 1); | ||
|
||
spy.debug.apply(spy, hundredNumbers); | ||
|
||
expect(spy.debug).toHaveBeenCalledTimes(1); | ||
expect(spy.debug).toHaveBeenCalledWith(...hundredNumbers); | ||
}); | ||
|
||
it('can reset spy tracking', () => { | ||
spy.debug(1); | ||
spy.debug(2); | ||
spy.error(1); | ||
spy.error(2); | ||
spy.error(3); | ||
|
||
expect(spy.debug).toHaveBeenCalledTimes(2); | ||
expect(spy.error).toHaveBeenCalledTimes(3); | ||
|
||
spy.reset(); | ||
|
||
expect(spy.debug).toHaveBeenCalledTimes(0); | ||
expect(spy.error).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
libs/internal/console-driver/test-util/src/lib/spy-console/spy-console.service.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,32 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
import { LumberjackConsole } from '@ngworker/lumberjack/console-driver'; | ||
|
||
/** | ||
* Spy console logger. | ||
* | ||
* Every method is a spy. | ||
*/ | ||
@Injectable() | ||
export class SpyConsole implements LumberjackConsole, jasmine.SpyObj<LumberjackConsole> { | ||
debug = jasmine.createSpy('debug'); | ||
|
||
error = jasmine.createSpy('error'); | ||
|
||
info = jasmine.createSpy('info'); | ||
|
||
trace = jasmine.createSpy('trace'); | ||
|
||
warn = jasmine.createSpy('warn'); | ||
|
||
/** | ||
* Reset tracking on spies. | ||
*/ | ||
reset(): void { | ||
this.debug.calls.reset(); | ||
this.error.calls.reset(); | ||
this.info.calls.reset(); | ||
this.trace.calls.reset(); | ||
this.warn.calls.reset(); | ||
} | ||
} |
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,24 @@ | ||
// This file is required by karma.conf.js and loads recursively all the .spec and framework files | ||
|
||
import { getTestBed } from '@angular/core/testing'; | ||
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; | ||
import 'zone.js/dist/zone'; | ||
import 'zone.js/dist/zone-testing'; | ||
|
||
declare const require: { | ||
context( | ||
path: string, | ||
deep?: boolean, | ||
filter?: RegExp | ||
): { | ||
keys(): string[]; | ||
<T>(id: string): T; | ||
}; | ||
}; | ||
|
||
// First, initialize the Angular testing environment. | ||
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); | ||
// Then we find all the tests. | ||
const context = require.context('./', true, /\.spec\.ts$/); | ||
// And load the modules. | ||
context.keys().map(context); |
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,18 @@ | ||
/* To learn more about this file see: https://angular.io/config/tsconfig. */ | ||
{ | ||
"extends": "../../../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../../../out-tsc/lib", | ||
"target": "es2015", | ||
"declaration": true, | ||
"inlineSources": true, | ||
"types": [], | ||
"lib": ["dom", "es2018"] | ||
}, | ||
"angularCompilerOptions": { | ||
"skipTemplateCodegen": true, | ||
"strictMetadataEmit": true, | ||
"enableResourceInlining": true | ||
}, | ||
"exclude": ["src/test.ts", "**/*.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,10 @@ | ||
/* To learn more about this file see: https://angular.io/config/tsconfig. */ | ||
{ | ||
"extends": "../../../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../../../out-tsc/spec", | ||
"types": ["jasmine", "node"] | ||
}, | ||
"files": ["src/test.ts"], | ||
"include": ["**/*.spec.ts", "**/*.d.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 @@ | ||
{ | ||
"extends": "../../../tslint.json", | ||
"rules": { | ||
"directive-selector": [true, "attribute", "lib", "camelCase"], | ||
"component-selector": [true, "element", "lib", "kebab-case"] | ||
}, | ||
"linterOptions": { | ||
"exclude": ["!**/*"] | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.