-
-
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.
test: increase test coverage and extract test-util library (#22)
* test: add coverage to log drivers and log levels * test: increase coverage for log types * chore: git ignore debug.log files * test: use resolveDependency * test: extract test-util library * test: refactor test util library
- Loading branch information
Showing
24 changed files
with
351 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ npm-debug.log | |
yarn-error.log | ||
testem.log | ||
/typings | ||
debug.log | ||
|
||
# System Files | ||
.DS_Store | ||
|
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 @@ | ||
# Test utilities | ||
|
||
## Running unit tests | ||
|
||
Run `ng test 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,32 @@ | ||
// Karma configuration file, see link for more information | ||
// https://karma-runner.github.io/1.0/config/configuration-file.html | ||
|
||
module.exports = function (config) { | ||
config.set({ | ||
basePath: '', | ||
frameworks: ['jasmine', '@angular-devkit/build-angular'], | ||
plugins: [ | ||
require('karma-jasmine'), | ||
require('karma-chrome-launcher'), | ||
require('karma-jasmine-html-reporter'), | ||
require('karma-coverage-istanbul-reporter'), | ||
require('@angular-devkit/build-angular/plugins/karma'), | ||
], | ||
client: { | ||
clearContext: false, // leave Jasmine Spec Runner output visible in browser | ||
}, | ||
coverageIstanbulReporter: { | ||
dir: require('path').join(__dirname, '../../../coverage/test-util'), | ||
reports: ['html', 'lcovonly', 'text-summary'], | ||
fixWebpackSourcePaths: true, | ||
}, | ||
reporters: ['progress', 'kjhtml'], | ||
port: 9876, | ||
colors: true, | ||
logLevel: config.LOG_INFO, | ||
autoWatch: true, | ||
browsers: ['Chrome'], | ||
singleRun: false, | ||
restartOnFileChange: true, | ||
}); | ||
}; |
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
28 changes: 28 additions & 0 deletions
28
projects/internal/test-util/src/lib/noop-driver/noop-driver-root.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,28 @@ | ||
import { NgModule, Optional, SkipSelf } from '@angular/core'; | ||
|
||
import { defaultLogDriverConfig, LogDriverConfigToken, LogDriverToken } from '@ngworker/lumberjack'; | ||
|
||
import { NoopDriver } from './noop-driver.service'; | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ | ||
provide: LogDriverConfigToken, | ||
useValue: defaultLogDriverConfig, | ||
}, | ||
{ | ||
provide: LogDriverToken, | ||
useClass: NoopDriver, | ||
multi: true, | ||
}, | ||
], | ||
}) | ||
export class NoopDriverRootModule { | ||
constructor(@Optional() @SkipSelf() maybeNgModuleFromParentInjector?: NoopDriverRootModule) { | ||
if (maybeNgModuleFromParentInjector) { | ||
throw new Error( | ||
'ConsoleDriverModule.forRoot registered in multiple injectors. Only call it from your root injector such as in AppModule.' | ||
); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
projects/internal/test-util/src/lib/noop-driver/noop-driver.module.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,9 @@ | ||
import { expectNgModuleToBeGuarded } from '../expect-ng-module-to-be-guarded'; | ||
|
||
import { NoopDriverModule } from './noop-driver.module'; | ||
|
||
describe(NoopDriverModule.name, () => { | ||
it('is guarded against direct import', () => { | ||
expectNgModuleToBeGuarded(NoopDriverModule); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
projects/internal/test-util/src/lib/noop-driver/noop-driver.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,21 @@ | ||
import { ModuleWithProviders, NgModule } from '@angular/core'; | ||
|
||
import { NoopDriverRootModule } from './noop-driver-root.module'; | ||
|
||
/** | ||
* Service module for `NoopDriver`. | ||
* | ||
* Use `NoopDriverModule.forRoot` to import. | ||
*/ | ||
@NgModule() | ||
export class NoopDriverModule { | ||
static forRoot(): ModuleWithProviders<NoopDriverRootModule> { | ||
return { | ||
ngModule: NoopDriverRootModule, | ||
}; | ||
} | ||
|
||
constructor() { | ||
throw new Error('Do not import NoopDriverModule directly. Use NoopDriverModule.forRoot.'); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
projects/internal/test-util/src/lib/noop-driver/noop-driver.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,21 @@ | ||
import { Inject, Injectable, ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core'; | ||
|
||
import { | ||
defaultLogDriverConfig, | ||
LogDriver, | ||
LogDriverConfig, | ||
LogDriverConfigToken, | ||
LogDriverToken, | ||
} from '@ngworker/lumberjack'; | ||
|
||
/** | ||
* No-op log driver. | ||
*/ | ||
@Injectable() | ||
export class NoopDriver implements LogDriver { | ||
constructor(@Inject(LogDriverConfigToken) public config: LogDriverConfig) {} | ||
logInfo(logEntry: string): void {} | ||
logDebug(logEntry: string): void {} | ||
logError(logEntry: string): void {} | ||
logWarning(logEntry: string): void {} | ||
} |
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,8 @@ | ||
/* | ||
* Public API Surface of test-util | ||
*/ | ||
|
||
export * from './lib/expect-ng-module-to-be-guarded'; | ||
export * from './lib/noop-driver/noop-driver.module'; | ||
export * from './lib/noop-driver/noop-driver.service'; | ||
export * from './lib/resolve-dependency'; |
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"] | ||
}, | ||
"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,7 @@ | ||
{ | ||
"extends": "../../../tslint.json", | ||
"rules": { | ||
"directive-selector": [true, "attribute", "lib", "camelCase"], | ||
"component-selector": [true, "element", "lib", "kebab-case"] | ||
} | ||
} |
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.