Skip to content
This repository was archived by the owner on Feb 7, 2021. It is now read-only.

Commit 81bb374

Browse files
authored
refactor: schematics cleanup & increase test coverage (#91)
* refactor: schematics cleanup * tests: increase test coverage
1 parent b2fa181 commit 81bb374

15 files changed

+183
-105
lines changed

.gitignore

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ npm-debug.log
1616
/.nyc_output
1717

1818
# dist
19-
dist
20-
node_modules
19+
/dist
2120

2221
# schematics
23-
schematics/**/*.js
24-
schematics/**/*.d.ts
22+
/schematics/**/*.js
23+
/schematics/**/*.d.ts
24+
25+
# jest snapshots
26+
__snapshots__/

jest.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
moduleFileExtensions: ['js', 'json', 'ts'],
3+
rootDir: '.',
4+
testEnvironment: 'node',
5+
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
6+
transform: {
7+
'^.+\\.(ts|js|html)$': 'ts-jest',
8+
},
9+
collectCoverage: true,
10+
collectCoverageFrom: [
11+
'<rootDir>/lib/**/*.ts',
12+
'!<rootDir>/lib/index.ts',
13+
'!<rootDir>/schematics/**/*.ts',
14+
],
15+
coverageThreshold: {
16+
global: {
17+
statements: 80,
18+
branches: 80,
19+
functions: 80,
20+
lines: 80,
21+
},
22+
},
23+
};

jest.json

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Inject } from '@nestjs/common';
2+
import { InjectInMemoryDBService } from './in-memory-db.decorators';
3+
4+
describe('InjectInMemoryDBService', () => {
5+
// TODO: Implement test of decorator
6+
it('should', () => {
7+
InjectInMemoryDBService('feature');
8+
});
9+
});

lib/in-memory-db.module.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { Test } from '@nestjs/testing';
2+
import { InMemoryDBModule } from './in-memory-db.module';
3+
4+
describe('InMemoryDBModule', () => {
5+
describe('forRoot', () => {
6+
beforeEach(async () => {
7+
await Test.createTestingModule({
8+
imports: [InMemoryDBModule.forRoot({})],
9+
}).compile();
10+
});
11+
12+
it('should create', () => {
13+
expect(InMemoryDBModule).toBeDefined();
14+
});
15+
});
16+
describe('forRoot - no object', () => {
17+
beforeEach(async () => {
18+
await Test.createTestingModule({
19+
imports: [InMemoryDBModule.forRoot()],
20+
}).compile();
21+
});
22+
23+
it('should create', () => {
24+
expect(InMemoryDBModule).toBeDefined();
25+
});
26+
});
27+
describe('forFeature', () => {
28+
beforeEach(async () => {
29+
await Test.createTestingModule({
30+
imports: [InMemoryDBModule.forFeature('feature', {})],
31+
}).compile();
32+
});
33+
34+
it('should create', () => {
35+
expect(InMemoryDBModule).toBeDefined();
36+
});
37+
});
38+
describe('forFeature - no object', () => {
39+
beforeEach(async () => {
40+
await Test.createTestingModule({
41+
imports: [InMemoryDBModule.forFeature('feature')],
42+
}).compile();
43+
});
44+
45+
it('should create', () => {
46+
expect(InMemoryDBModule).toBeDefined();
47+
});
48+
});
49+
});

lib/providers/in-memory-db-for-feature.providers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { FactoryProvider } from '@nestjs/common/interfaces';
55

66
export function createInMemoryDBForFeatureProviders(
77
featureName: string,
8-
featureConfig: Partial<InMemoryDBConfig> = {},
8+
featureConfig: Partial<InMemoryDBConfig>,
99
) {
1010
const providers: FactoryProvider[] = [
1111
{

lib/providers/in-memory-db-for-root.providers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getInMemoryDBServiceToken } from '../common';
55
import { InMemoryDBConfig } from '../interfaces';
66

77
export function createInMemoryDBForRootProviders(
8-
featureConfig: Partial<InMemoryDBConfig> = {},
8+
featureConfig: Partial<InMemoryDBConfig>,
99
) {
1010
const providers: FactoryProvider[] = [
1111
{

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@
77
"repository": "https://github.com/nestjs-addons/in-memory-db",
88
"schematics": "./dist/schematics/collection.json",
99
"scripts": {
10-
"build": "tsc -p tsconfig.json && npm run build:schematics",
10+
"build": "npm run build:lib && npm run build:schematics",
1111
"build:dev": "tsc-watch -p tsconfig.json",
12+
"build:lib": "tsc -p tsconfig.json",
1213
"build:schematics": "tsc -p tsconfig.schematics.json && npm run copy:files",
1314
"copy:files": "copyfiles schematics/collection.json schematics/nest-add/schema.json dist",
1415
"watch:schematics": "npm link && npm run build:schematics -- --watch",
1516
"format": "prettier lib/**/*.ts --write",
1617
"format:verify": "prettier lib/**/*.ts --check",
1718
"lint": "npx tslint -p tsconfig.json -c tslint.json \"lib/**/*.ts\" -e \"*.spec.ts\" --force",
18-
"test": "jest --config jest.json",
19+
"test": "jest",
1920
"semantic-release": "semantic-release"
2021
},
2122
"devDependencies": {
2223
"@nestjs/common": "6.7.2",
2324
"@nestjs/core": "6.7.2",
25+
"@nestjs/testing": "6.7.2",
2426
"rxjs": "6.5.3",
2527
"@semantic-release/changelog": "3.0.4",
2628
"@types/jest": "24.0.18",

schematics/collection.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
3-
"schematics": {
4-
"nest-add": {
5-
"description": "Schematics to add In memory DB module.",
6-
"factory": "./nest-add/",
7-
"schema": "./nest-add/schema.json"
8-
}
2+
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
3+
"schematics": {
4+
"nest-add": {
5+
"description": "Schematics to add In-Memory DB Module.",
6+
"factory": "./nest-add",
7+
"schema": "./nest-add/schema.json"
98
}
109
}
10+
}

0 commit comments

Comments
 (0)