Skip to content

Commit

Permalink
test(api): fix nest api linting and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlking committed Sep 30, 2018
1 parent d193fc2 commit 9fbf962
Show file tree
Hide file tree
Showing 18 changed files with 638 additions and 445 deletions.
2 changes: 0 additions & 2 deletions PLAYBOOK-NEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ npm i -D @types/helmet

#### Generate Artifacts
```bash
cd apps/api

# scaffold core module
nest g module core --dry-run
nest g guard auth core --dry-run
Expand Down
28 changes: 27 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"baseline": "10mb",
"maximumError": "20%",
"maximumWarning": "10%"
},
}
]
},
"mock": {
Expand Down Expand Up @@ -225,6 +225,32 @@
}
}
},
"api": {
"root": "apps/api",
"sourceRoot": "apps/api/src",
"projectType": "application",
"architect": {
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"apps/api/tsconfig.json",
"apps/api/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"test": {
"builder": "@nrwl/builders:jest",
"options": {
"jestConfig": "apps/api/jest.config.js",
"tsConfig": "apps/api/tsconfig.spec.json"
}
}
}
},
"navigator": {
"root": "libs/navigator",
"sourceRoot": "libs/navigator/src",
Expand Down
4 changes: 0 additions & 4 deletions apps/api/.nestcli.json

This file was deleted.

16 changes: 4 additions & 12 deletions apps/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ npm run api:webpack -- -p
# check of nest installed
nest info

cd apps/api
# scaffold project module
nest generate module project --dry-run
nest generate controller project --dry-run
Expand All @@ -100,23 +99,16 @@ nest g exception auth --dry-run
```

### Test
> coverage will be generate in dist/api/coverage
> coverage will be generate in coverage/apps/api
```bash
# unit tests
npm run api:test
# for api project
npx jest --projects=apps/api --roots=src


# e2e tests
npm run api:test:e2e
# for api project
npx jest --projects=apps/api --roots=e2e

# test coverage
npm run api:test:cov
# for api project
npx jest --projects=apps/api --coverage

# e2e tests
npm run api:e2e
```


Expand Down
4 changes: 4 additions & 0 deletions apps/api/e2e/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ describe('AppController (e2e)', () => {
.expect(200)
.expect(/Welcome to Sumo API/);
});

afterAll(async () => {
await app.close();
});
});
6 changes: 3 additions & 3 deletions apps/api/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const jestBase = require('../../jest.config.base.js');
module.exports = {
...jestBase,
"coverageDirectory": "../../dist/apps/api/coverage",
name: 'api',
preset: '../../jest.config.nest.js',
"coverageDirectory": "../../coverage/apps/api",
};
4 changes: 2 additions & 2 deletions apps/api/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Test, TestingModule } from '@nestjs/testing';

import { AppController } from './app.controller';
import { CoreModule } from './core';
import { ConfigModule } from './config';

describe('AppController', () => {
let app: TestingModule;

beforeAll(async () => {
app = await Test.createTestingModule({
controllers: [AppController],
imports: [CoreModule],
imports: [ConfigModule.forRoot()],
}).compile();
});

Expand Down
1 change: 1 addition & 0 deletions apps/api/src/config/config.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { parse, config } from 'dotenv';
import * as fs from 'fs';
import { Injectable } from '@nestjs/common';
// tslint:disable-next-line
const packageJson = require('../../../../package.json');

@Injectable()
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/core/context/request-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class RequestContext {
const requestContext = RequestContext.currentRequestContext();

if (requestContext) {
// tslint:disable-next-line
const user: any = requestContext.request['user'];
if (user) {
return user;
Expand All @@ -54,6 +55,7 @@ export class RequestContext {
const requestContext = RequestContext.currentRequestContext();

if (requestContext) {
// tslint:disable-next-line
return requestContext.request['token'];
}

Expand Down
13 changes: 2 additions & 11 deletions apps/api/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"types": [
"jest",
"node"
]
"types": ["jest", "node"]
},
"include": [
"**/*.spec.ts",
"**/*.d.ts"
],
"exclude": [
"node_modules"
]
"include": ["**/*.spec.ts", "**/*.d.ts"]
}
34 changes: 0 additions & 34 deletions jest.config.base.js

This file was deleted.

6 changes: 0 additions & 6 deletions jest.config.js.ori

This file was deleted.

10 changes: 10 additions & 0 deletions jest.config.nest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
"moduleFileExtensions": ["js", "json", "ts"],
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
collectCoverage: true,
coverageReporters: ['html'],
"testEnvironment": "node"
};
1 change: 0 additions & 1 deletion libs/home/src/lib/containers/about/about.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ROUTE_ANIMATIONS_ELEMENTS } from '@ngx-starter-kit/animations';
// import * as Trianglify from 'trianglify';
declare var Trianglify: any;
import { fromEvent, Subject, Subscription } from 'rxjs';
import 'rxjs/add/observable/fromEvent';
import { map, debounceTime, distinctUntilChanged, takeUntil } from 'rxjs/operators';

@Component({
Expand Down
5 changes: 5 additions & 0 deletions nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"language": "ts",
"collection": "@nestjs/schematics",
"sourceRoot": "apps/api/src"
}
5 changes: 5 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"webapp"
]
},
"api": {
"tags": [
"api-module"
]
},
"navigator": {
"tags": [
"private-module",
Expand Down

0 comments on commit 9fbf962

Please sign in to comment.