diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3d3578545..7f5802441 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,7 +146,8 @@ jobs: ${{ runner.os }}-node-${{ matrix.node-version }}-angular-${{ matrix.angular-version }}-yarn- - run: yarn install - - run: yarn delete-paths + - run: yarn delete-path-alias @ngworker/lumberjack + - run: yarn delete-path-alias @ngworker/lumberjack/*-driver - uses: actions/download-artifact@v2 with: name: lumberjack-package @@ -188,7 +189,8 @@ jobs: ${{ runner.os }}-node-${{ matrix.node-version }}-angular-${{ matrix.angular-version }}-yarn- - run: yarn install - - run: yarn delete-paths + - run: yarn delete-path-alias @ngworker/lumberjack + - run: yarn delete-path-alias @ngworker/lumberjack/*-driver - uses: actions/download-artifact@v2 with: name: lumberjack-package diff --git a/angular.json b/angular.json index ed652a6a6..9194292a3 100644 --- a/angular.json +++ b/angular.json @@ -169,7 +169,7 @@ "projectType": "library", "root": "libs/internal/test-util", "sourceRoot": "libs/internal/test-util/src", - "prefix": "lib", + "prefix": "internal", "architect": { "test": { "builder": "@angular-devkit/build-angular:karma", @@ -194,6 +194,39 @@ } } } + }, + "internal-console-driver-test-util": { + "projectType": "library", + "root": "libs/internal/console-driver/test-util", + "sourceRoot": "libs/internal/console-driver/test-util/src", + "prefix": "internal", + "architect": { + "test": { + "builder": "@angular-devkit/build-angular:karma", + "options": { + "main": "libs/internal/console-driver/test-util/src/test.ts", + "tsConfig": "libs/internal/console-driver/test-util/tsconfig.spec.json", + "karmaConfig": "libs/internal/console-driver/test-util/karma.conf.js" + }, + "configurations": { + "ci": { + "browsers": "ChromeHeadless", + "progress": false, + "watch": false + } + } + }, + "lint": { + "builder": "@angular-devkit/build-angular:tslint", + "options": { + "tsConfig": [ + "libs/internal/console-driver/test-util/tsconfig.lib.json", + "libs/internal/console-driver/test-util/tsconfig.spec.json" + ], + "exclude": ["**/node_modules/**", "!libs/internal/console-driver/test-util/**"] + } + } + } } }, "defaultProject": "lumberjack-app" diff --git a/apps/lumberjack-app/src/app/app.component.spec.ts b/apps/lumberjack-app/src/app/app.component.spec.ts index af8fede30..6a7689267 100644 --- a/apps/lumberjack-app/src/app/app.component.spec.ts +++ b/apps/lumberjack-app/src/app/app.component.spec.ts @@ -1,6 +1,7 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { createComponentFactory, Spectator } from '@ngneat/spectator'; +import { NoopConsoleModule } from '@internal/console-driver/test-util'; import { LumberjackLogLevel, LumberjackModule } from '@ngworker/lumberjack'; import { ConsoleDriverModule } from '@ngworker/lumberjack/console-driver'; import { HttpDriverModule } from '@ngworker/lumberjack/http-driver'; @@ -15,6 +16,7 @@ describe('AppComponent', () => { HttpClientTestingModule, LumberjackModule.forRoot(), ConsoleDriverModule.forRoot(), + NoopConsoleModule, HttpDriverModule.forRoot({ levels: [LumberjackLogLevel.Error], logWagonSize: 5, @@ -23,7 +25,6 @@ describe('AppComponent', () => { }), ], }); - beforeEach(() => { spectator = createComponent(); }); diff --git a/libs/internal/console-driver/test-util/README.md b/libs/internal/console-driver/test-util/README.md new file mode 100644 index 000000000..59647d0ba --- /dev/null +++ b/libs/internal/console-driver/test-util/README.md @@ -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. diff --git a/libs/internal/console-driver/test-util/karma.conf.js b/libs/internal/console-driver/test-util/karma.conf.js new file mode 100644 index 000000000..bb7446237 --- /dev/null +++ b/libs/internal/console-driver/test-util/karma.conf.js @@ -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'), + }, + }); +}; diff --git a/libs/internal/console-driver/test-util/src/index.ts b/libs/internal/console-driver/test-util/src/index.ts new file mode 100644 index 000000000..252cab8cd --- /dev/null +++ b/libs/internal/console-driver/test-util/src/index.ts @@ -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'; diff --git a/libs/internal/console-driver/test-util/src/lib/noop-console/noop-console.module.ts b/libs/internal/console-driver/test-util/src/lib/noop-console/noop-console.module.ts new file mode 100644 index 000000000..c023d554c --- /dev/null +++ b/libs/internal/console-driver/test-util/src/lib/noop-console/noop-console.module.ts @@ -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 {} diff --git a/libs/internal/console-driver/test-util/src/lib/noop-console/noop-console.service.ts b/libs/internal/console-driver/test-util/src/lib/noop-console/noop-console.service.ts new file mode 100644 index 000000000..8f245c5ac --- /dev/null +++ b/libs/internal/console-driver/test-util/src/lib/noop-console/noop-console.service.ts @@ -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 +} diff --git a/libs/internal/console-driver/test-util/src/lib/spy-console/spy-console.module.ts b/libs/internal/console-driver/test-util/src/lib/spy-console/spy-console.module.ts new file mode 100644 index 000000000..7daf932b9 --- /dev/null +++ b/libs/internal/console-driver/test-util/src/lib/spy-console/spy-console.module.ts @@ -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 {} diff --git a/libs/internal/console-driver/test-util/src/lib/spy-console/spy-console.service.spec.ts b/libs/internal/console-driver/test-util/src/lib/spy-console/spy-console.service.spec.ts new file mode 100644 index 000000000..56a3c9e46 --- /dev/null +++ b/libs/internal/console-driver/test-util/src/lib/spy-console/spy-console.service.spec.ts @@ -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); + }); +}); diff --git a/libs/internal/console-driver/test-util/src/lib/spy-console/spy-console.service.ts b/libs/internal/console-driver/test-util/src/lib/spy-console/spy-console.service.ts new file mode 100644 index 000000000..4a262714b --- /dev/null +++ b/libs/internal/console-driver/test-util/src/lib/spy-console/spy-console.service.ts @@ -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 { + 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(); + } +} diff --git a/libs/internal/console-driver/test-util/src/test.ts b/libs/internal/console-driver/test-util/src/test.ts new file mode 100644 index 000000000..6e21dc019 --- /dev/null +++ b/libs/internal/console-driver/test-util/src/test.ts @@ -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[]; + (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); diff --git a/libs/internal/console-driver/test-util/tsconfig.lib.json b/libs/internal/console-driver/test-util/tsconfig.lib.json new file mode 100644 index 000000000..432a53aa0 --- /dev/null +++ b/libs/internal/console-driver/test-util/tsconfig.lib.json @@ -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"] +} diff --git a/libs/internal/console-driver/test-util/tsconfig.spec.json b/libs/internal/console-driver/test-util/tsconfig.spec.json new file mode 100644 index 000000000..258f1e56a --- /dev/null +++ b/libs/internal/console-driver/test-util/tsconfig.spec.json @@ -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"] +} diff --git a/libs/internal/console-driver/test-util/tslint.json b/libs/internal/console-driver/test-util/tslint.json new file mode 100644 index 000000000..3812a73ac --- /dev/null +++ b/libs/internal/console-driver/test-util/tslint.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../tslint.json", + "rules": { + "directive-selector": [true, "attribute", "lib", "camelCase"], + "component-selector": [true, "element", "lib", "kebab-case"] + }, + "linterOptions": { + "exclude": ["!**/*"] + } +} diff --git a/libs/internal/test-util/src/index.ts b/libs/internal/test-util/src/index.ts index 1e5982d20..32a5061af 100644 --- a/libs/internal/test-util/src/index.ts +++ b/libs/internal/test-util/src/index.ts @@ -6,7 +6,6 @@ export * from './lib/expect-ng-module-to-be-guarded'; export * from './lib/logs/log-creators'; export * from './lib/noop-driver/noop-driver.module'; export * from './lib/noop-driver/noop.driver'; +export * from './lib/resolve-dependency'; export * from './lib/spy-driver/spy-driver.module'; export * from './lib/spy-driver/spy.driver'; -export * from './lib/resolve-dependency'; -export * from './lib/array-equality'; diff --git a/libs/internal/test-util/src/lib/array-equality.ts b/libs/internal/test-util/src/lib/array-equality.ts deleted file mode 100644 index 4f2d43461..000000000 --- a/libs/internal/test-util/src/lib/array-equality.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Shallow compares two arrays - */ -export function arrayEquals(a: T[], b: T[]) { - return a.length === b.length && a.every((val, index) => val === b[index]); -} diff --git a/libs/internal/test-util/tsconfig.lib.json b/libs/internal/test-util/tsconfig.lib.json index 20b2896b6..ad17f11ba 100644 --- a/libs/internal/test-util/tsconfig.lib.json +++ b/libs/internal/test-util/tsconfig.lib.json @@ -2,7 +2,7 @@ { "extends": "../../../tsconfig.json", "compilerOptions": { - "outDir": "../../out-tsc/lib", + "outDir": "../../../out-tsc/lib", "target": "es2015", "declaration": true, "inlineSources": true, diff --git a/libs/internal/test-util/tsconfig.spec.json b/libs/internal/test-util/tsconfig.spec.json index 46aa92ab7..84af7a02c 100644 --- a/libs/internal/test-util/tsconfig.spec.json +++ b/libs/internal/test-util/tsconfig.spec.json @@ -2,7 +2,7 @@ { "extends": "../../../tsconfig.json", "compilerOptions": { - "outDir": "../../out-tsc/spec", + "outDir": "../../../out-tsc/spec", "types": ["jasmine", "node"] }, "files": ["src/test.ts"], diff --git a/libs/ngworker/lumberjack/console-driver/src/index.ts b/libs/ngworker/lumberjack/console-driver/src/index.ts index 99bf1f6f0..18772ee61 100644 --- a/libs/ngworker/lumberjack/console-driver/src/index.ts +++ b/libs/ngworker/lumberjack/console-driver/src/index.ts @@ -5,3 +5,5 @@ export * from './lib/console-driver-root.module'; export * from './lib/console-driver.module'; export * from './lib/console.driver'; +export * from './lib/lumberjack-console'; +export * from './lib/lumberjack-console.token'; diff --git a/libs/ngworker/lumberjack/console-driver/src/lib/console-driver-config.token.spec.ts b/libs/ngworker/lumberjack/console-driver/src/lib/console-driver-config.token.spec.ts index 4858bcfcf..9c7d36af4 100644 --- a/libs/ngworker/lumberjack/console-driver/src/lib/console-driver-config.token.spec.ts +++ b/libs/ngworker/lumberjack/console-driver/src/lib/console-driver-config.token.spec.ts @@ -13,7 +13,7 @@ const verboseDriverConfig: LogDriverConfig = { }; describe('ConsoleDriverConfigToken', () => { - describe('given a provided console driver config', () => { + describe('given a provided console log driver config', () => { beforeEach(() => { TestBed.configureTestingModule({ providers: [ @@ -30,14 +30,14 @@ describe('ConsoleDriverConfigToken', () => { }); }); - describe('given no provided console driver config', () => { + describe('given no provided console log driver config', () => { beforeEach(() => { TestBed.configureTestingModule({ providers: [{ provide: LogDriverConfigToken, useValue: verboseDriverConfig }], }); }); - it('then the log driver config is resolved', () => { + it('then the value of the log driver config is resolved', () => { const actualDriverConfig = resolveDependency(ConsoleDriverConfigToken); expect(actualDriverConfig).toBe(verboseDriverConfig); diff --git a/libs/ngworker/lumberjack/console-driver/src/lib/console.driver.spec.ts b/libs/ngworker/lumberjack/console-driver/src/lib/console.driver.spec.ts new file mode 100644 index 000000000..23d83b6ce --- /dev/null +++ b/libs/ngworker/lumberjack/console-driver/src/lib/console.driver.spec.ts @@ -0,0 +1,78 @@ +import { TestBed } from '@angular/core/testing'; + +import { SpyConsole, SpyConsoleModule } from '@internal/console-driver/test-util'; +import { resolveDependency } from '@internal/test-util'; +import { LogDriver, LogDriverToken, LumberjackLogLevel } from '@ngworker/lumberjack'; + +import { ConsoleDriverModule } from './console-driver.module'; +import { ConsoleDriver } from './console.driver'; +import { LumberjackConsoleToken } from './lumberjack-console.token'; + +describe(ConsoleDriver.name, () => { + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [ConsoleDriverModule.forRoot({ levels: [LumberjackLogLevel.Verbose] }), SpyConsoleModule], + }); + + const [_driver] = (resolveDependency(LogDriverToken) as unknown) as LogDriver[]; + driver = _driver as ConsoleDriver; + spyLogger = resolveDependency(LumberjackConsoleToken) as SpyConsole; + }); + + let driver: ConsoleDriver; + let spyLogger: SpyConsole; + + it("logs the critical level to the console's error channel", () => { + const expectedMessage = LumberjackLogLevel.Critical; + + driver.logCritical(expectedMessage); + + expect(spyLogger.error).toHaveBeenCalledTimes(1); + expect(spyLogger.error).toHaveBeenCalledWith(expectedMessage); + }); + + it("logs the debug level to the console's debug channel", () => { + const expectedMessage = LumberjackLogLevel.Debug; + + driver.logDebug(expectedMessage); + + expect(spyLogger.debug).toHaveBeenCalledTimes(1); + expect(spyLogger.debug).toHaveBeenCalledWith(expectedMessage); + }); + + it("logs the error level to the console's error channel", () => { + const expectedMessage = LumberjackLogLevel.Error; + + driver.logError(expectedMessage); + + expect(spyLogger.error).toHaveBeenCalledTimes(1); + expect(spyLogger.error).toHaveBeenCalledWith(expectedMessage); + }); + + it("logs the info level to the console's info channel", () => { + const expectedMessage = LumberjackLogLevel.Info; + + driver.logInfo(expectedMessage); + + expect(spyLogger.info).toHaveBeenCalledTimes(1); + expect(spyLogger.info).toHaveBeenCalledWith(expectedMessage); + }); + + it("logs the trace level to the console's trace channel", () => { + const expectedMessage = LumberjackLogLevel.Trace; + + driver.logTrace(expectedMessage); + + expect(spyLogger.trace).toHaveBeenCalledTimes(1); + expect(spyLogger.trace).toHaveBeenCalledWith(expectedMessage); + }); + + it("logs the warning level to the console's warn channel", () => { + const expectedMessage = LumberjackLogLevel.Warning; + + driver.logWarning(expectedMessage); + + expect(spyLogger.warn).toHaveBeenCalledTimes(1); + expect(spyLogger.warn).toHaveBeenCalledWith(expectedMessage); + }); +}); diff --git a/libs/ngworker/lumberjack/console-driver/src/lib/console.driver.ts b/libs/ngworker/lumberjack/console-driver/src/lib/console.driver.ts index 3953f8181..02fb41022 100644 --- a/libs/ngworker/lumberjack/console-driver/src/lib/console.driver.ts +++ b/libs/ngworker/lumberjack/console-driver/src/lib/console.driver.ts @@ -3,33 +3,38 @@ import { Inject, Injectable } from '@angular/core'; import { LogDriver, LogDriverConfig } from '@ngworker/lumberjack'; import { ConsoleDriverConfigToken } from './console-driver-config.token'; +import { LumberjackConsole } from './lumberjack-console'; +import { LumberjackConsoleToken } from './lumberjack-console.token'; @Injectable() export class ConsoleDriver implements LogDriver { - constructor(@Inject(ConsoleDriverConfigToken) public config: LogDriverConfig) {} + constructor( + @Inject(ConsoleDriverConfigToken) public config: LogDriverConfig, + @Inject(LumberjackConsoleToken) private console: LumberjackConsole + ) {} logCritical(logEntry: string): void { - console.error(logEntry); + this.console.error(logEntry); } logDebug(logEntry: string): void { - console.debug(logEntry); + this.console.debug(logEntry); } logError(logEntry: string): void { - console.error(logEntry); + this.console.error(logEntry); } logInfo(logEntry: string): void { - console.info(logEntry); + this.console.info(logEntry); } logTrace(logEntry: string): void { // tslint:disable-next-line: no-console - console.trace(logEntry); + this.console.trace(logEntry); } logWarning(logEntry: string): void { - console.warn(logEntry); + this.console.warn(logEntry); } } diff --git a/libs/ngworker/lumberjack/console-driver/src/lib/lumberjack-console.token.spec.ts b/libs/ngworker/lumberjack/console-driver/src/lib/lumberjack-console.token.spec.ts new file mode 100644 index 000000000..acfbaf41e --- /dev/null +++ b/libs/ngworker/lumberjack/console-driver/src/lib/lumberjack-console.token.spec.ts @@ -0,0 +1,11 @@ +import { resolveDependency } from '@internal/test-util'; + +import { LumberjackConsoleToken } from './lumberjack-console.token'; + +describe('LumberjackConsoleToken', () => { + it('resolves to the console by default', () => { + const actualConsoleLogger = resolveDependency(LumberjackConsoleToken); + + expect(actualConsoleLogger).toBe(console); + }); +}); diff --git a/libs/ngworker/lumberjack/console-driver/src/lib/lumberjack-console.token.ts b/libs/ngworker/lumberjack/console-driver/src/lib/lumberjack-console.token.ts new file mode 100644 index 000000000..d674991f4 --- /dev/null +++ b/libs/ngworker/lumberjack/console-driver/src/lib/lumberjack-console.token.ts @@ -0,0 +1,8 @@ +import { InjectionToken } from '@angular/core'; + +import { LumberjackConsole } from './lumberjack-console'; + +export const LumberjackConsoleToken = new InjectionToken('Lumberjack Console', { + factory: (): LumberjackConsole => console, + providedIn: 'root', +}); diff --git a/libs/ngworker/lumberjack/console-driver/src/lib/lumberjack-console.ts b/libs/ngworker/lumberjack/console-driver/src/lib/lumberjack-console.ts new file mode 100644 index 000000000..e2d8be2b3 --- /dev/null +++ b/libs/ngworker/lumberjack/console-driver/src/lib/lumberjack-console.ts @@ -0,0 +1 @@ +export type LumberjackConsole = Pick; diff --git a/libs/ngworker/lumberjack/src/index.ts b/libs/ngworker/lumberjack/src/index.ts index 62001fe3e..0f93c6f38 100644 --- a/libs/ngworker/lumberjack/src/index.ts +++ b/libs/ngworker/lumberjack/src/index.ts @@ -9,4 +9,4 @@ export * from './lib/lumberjack-log-levels'; export * from './lib/lumberjack-logger.service'; export * from './lib/lumberjack.module'; export * from './lib/lumberjack.service'; -export * from './lib/time'; +export * from './lib/time/lumberjack-time.service'; diff --git a/libs/ngworker/lumberjack/src/lib/configs/lumberjack-log.config.ts b/libs/ngworker/lumberjack/src/lib/configs/lumberjack-log.config.ts index 4b2ffe9db..9f21907e3 100644 --- a/libs/ngworker/lumberjack/src/lib/configs/lumberjack-log.config.ts +++ b/libs/ngworker/lumberjack/src/lib/configs/lumberjack-log.config.ts @@ -1,7 +1,7 @@ import { inject, InjectionToken } from '@angular/core'; import { LumberjackLog } from '../lumberjack-log'; -import { LumberjackTimeService } from '../time'; +import { LumberjackTimeService } from '../time/lumberjack-time.service'; export const LumberjackLogConfigToken: InjectionToken = new InjectionToken( '__LUMBERJACK_LOG_CONFIG__', diff --git a/libs/ngworker/lumberjack/src/lib/lumberjack-logger.service.spec.ts b/libs/ngworker/lumberjack/src/lib/lumberjack-logger.service.spec.ts index c218cdcb6..cfdccde95 100644 --- a/libs/ngworker/lumberjack/src/lib/lumberjack-logger.service.spec.ts +++ b/libs/ngworker/lumberjack/src/lib/lumberjack-logger.service.spec.ts @@ -11,7 +11,7 @@ import { import { LumberjackLogger } from './lumberjack-logger.service'; import { LumberjackService } from './lumberjack.service'; -import { LumberjackTimeService } from './time'; +import { LumberjackTimeService } from './time/lumberjack-time.service'; @Injectable({ providedIn: 'root', diff --git a/libs/ngworker/lumberjack/src/lib/lumberjack-logger.service.ts b/libs/ngworker/lumberjack/src/lib/lumberjack-logger.service.ts index 224b799f6..a57a1d5b3 100644 --- a/libs/ngworker/lumberjack/src/lib/lumberjack-logger.service.ts +++ b/libs/ngworker/lumberjack/src/lib/lumberjack-logger.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { LumberjackLogEntryLevel, LumberjackLogLevel } from './lumberjack-log-levels'; import { LumberjackService } from './lumberjack.service'; -import { LumberjackTimeService } from './time'; +import { LumberjackTimeService } from './time/lumberjack-time.service'; @Injectable() export abstract class LumberjackLogger { diff --git a/libs/ngworker/lumberjack/src/lib/lumberjack.service.spec.ts b/libs/ngworker/lumberjack/src/lib/lumberjack.service.spec.ts index b1b65ee1a..690dd7223 100644 --- a/libs/ngworker/lumberjack/src/lib/lumberjack.service.spec.ts +++ b/libs/ngworker/lumberjack/src/lib/lumberjack.service.spec.ts @@ -1,6 +1,7 @@ import { StaticProvider } from '@angular/core'; import { TestBed } from '@angular/core/testing'; +import { NoopConsoleModule } from '@internal/console-driver/test-util'; import { createCriticalLog, createDebugLog, @@ -73,7 +74,12 @@ describe(LumberjackService.name, () => { it('accepts logs when multiple log drivers are registered', () => { TestBed.configureTestingModule({ - imports: [LumberjackModule.forRoot(), NoopDriverModule.forRoot(), ConsoleDriverModule.forRoot()], + imports: [ + LumberjackModule.forRoot(), + NoopDriverModule.forRoot(), + ConsoleDriverModule.forRoot(), + NoopConsoleModule, + ], }); expect(logDebugMessage).not.toThrow(); diff --git a/libs/ngworker/lumberjack/src/lib/time/index.ts b/libs/ngworker/lumberjack/src/lib/time/index.ts deleted file mode 100644 index 3a0a2d499..000000000 --- a/libs/ngworker/lumberjack/src/lib/time/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './lumberjack-time.service'; diff --git a/package.json b/package.json index 91a263155..a869b0135 100644 --- a/package.json +++ b/package.json @@ -16,13 +16,13 @@ "build:lib": "ng build ngworker-lumberjack --prod && npx copy README.md ./dist/ngworker/lumberjack", "test:lib": "ng test ngworker-lumberjack", "test:lib:ci": "yarn test:lib --configuration=ci", - "test:internal": "ng test internal-test-util", - "test:internal:ci": "yarn test:internal --configuration=ci", + "test:internal": "ng test internal-test-util && ng test internal-console-driver-test-util", + "test:internal:ci": "ng test internal-test-util --configuration=ci && ng test internal-console-driver-test-util --configuration=ci", "release": "cd libs/ngworker/lumberjack && standard-version --infile ../../../CHANGELOG.md", "publish": "cd dist/ngworker/lumberjack && npm publish", "ci": "yarn install && yarn lint && yarn build:lib && yarn test:internal:ci && yarn test:lib:ci && yarn build && yarn test:ci && yarn e2e", "format": "npx prettier --config prettier.config.js --write \"**/*.*\" \"!dist/**\" \"!yarn.lock\"", - "delete-paths": "npx json -I -f tsconfig.json -e 'delete this.compilerOptions.paths;'" + "delete-path-alias": "node tools/delete-path-alias.js" }, "private": true, "dependencies": { diff --git a/tools/delete-path-alias.js b/tools/delete-path-alias.js new file mode 100644 index 000000000..20b1c114d --- /dev/null +++ b/tools/delete-path-alias.js @@ -0,0 +1,13 @@ +const json = require('json'); + +function editJsonInPlace(filePath, commands) { + json.main(['', '', '-f', filePath, '--in-place', '-e', `${commands.join('; ')};`]); +} + +function deletePathAlias(alias) { + editJsonInPlace('tsconfig.json', [`delete this.compilerOptions.paths["${alias}"]`]); +} + +const [alias] = process.argv.slice(2); + +deletePathAlias(alias); diff --git a/tsconfig.json b/tsconfig.json index 567bb41b9..5d4988538 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,6 +18,7 @@ "lib": ["es2018", "dom"], "paths": { "@internal/test-util": ["libs/internal/test-util/src/index.ts"], + "@internal/console-driver/test-util": ["libs/internal/console-driver/test-util/src/index.ts"], "@ngworker/lumberjack": ["libs/ngworker/lumberjack/src/index.ts"], "@ngworker/lumberjack/*-driver": ["libs/ngworker/lumberjack/*-driver/src/index.ts"] }