File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -133,11 +133,12 @@ example_integration_test(
133133example_integration_test (
134134 name = "examples_nestjs" ,
135135 bazel_commands = [
136- "build ..." ,
136+ "test ..." ,
137137 # Test cross-platform build
138138 "build --platforms=@build_bazel_rules_nodejs//toolchains/node:linux_amd64 //src:docker" ,
139139 ],
140140 npm_packages = {
141+ "//packages/jasmine:npm_package" : "@bazel/jasmine" ,
141142 "//packages/typescript:npm_package" : "@bazel/typescript" ,
142143 },
143144 owners = [
Original file line number Diff line number Diff line change 11{
22 "private" : true ,
33 "dependencies" : {
4+ "@bazel/bazel" : " ^2.0.0" ,
5+ "@bazel/ibazel" : " ^0.11.0" ,
6+ "@bazel/jasmine" : " ^1.0.0" ,
47 "@nestjs/common" : " 6.5.2" ,
58 "@nestjs/core" : " 6.5.2" ,
69 "@nestjs/platform-express" : " 6.5.2" ,
10+ "@types/jasmine" : " ^3.5.0" ,
11+ "@types/supertest" : " ^2.0.8" ,
712 "minimist" : " 1.2.0" ,
813 "reflect-metadata" : " 0.1.13" ,
9- "rxjs" : " 6.5.2"
14+ "rxjs" : " 6.5.2" ,
15+ "supertest" : " ^4.0.2"
1016 },
1117 "devDependencies" : {
1218 "@bazel/typescript" : " ^1.0.1" ,
1319 "@types/node" : " 12.6.3" ,
1420 "typescript" : " 3.5.3"
1521 },
1622 "scripts" : {
17- "test" : " bazel build ... && bazel build --platforms=@build_bazel_rules_nodejs//toolchains/node:linux_amd64 //src:docker"
23+ "test" : " bazel test ... && bazel build --platforms=@build_bazel_rules_nodejs//toolchains/node:linux_amd64 //src:docker"
1824 }
1925}
Original file line number Diff line number Diff line change 1414
1515package (default_visibility = ["//visibility:public" ])
1616
17+ load ("@build_bazel_rules_nodejs//:index.bzl" , "nodejs_binary" )
18+ load ("@npm_bazel_jasmine//:index.bzl" , "jasmine_node_test" )
1719load ("@npm_bazel_typescript//:index.bzl" , "ts_library" )
1820
1921ts_library (
2022 name = "app" ,
21- srcs = glob (["*.ts" ]),
23+ srcs = glob (
24+ ["*.ts" ],
25+ exclude = ["*.spec.ts" ],
26+ ),
2227 deps = [
2328 "@npm//@nestjs/common" ,
2429 "@npm//@nestjs/core" ,
30+ "@npm//@nestjs/platform-express" ,
2531 "@npm//@types/node" ,
2632 "@npm//tslib" ,
2733 ],
2834)
2935
30- load ("@build_bazel_rules_nodejs//:index.bzl" , "nodejs_binary" )
36+ ts_library (
37+ name = "test_lib" ,
38+ srcs = glob (["*.spec.ts" ]),
39+ deps = [
40+ ":app" ,
41+ "@npm//@nestjs/common" ,
42+ "@npm//@types/jasmine" ,
43+ "@npm//@types/supertest" ,
44+ "@npm//jasmine" ,
45+ "@npm//supertest" ,
46+ ],
47+ )
3148
3249# bazel run //src:server -- --port=4000
3350# TODO(gregmagolan): add test for nest server with protractor rule once it is brought in
@@ -37,12 +54,18 @@ nodejs_binary(
3754 ":app" ,
3855 "@npm//@nestjs/common" ,
3956 "@npm//@nestjs/core" ,
40- "@npm//@nestjs/platform-express" ,
4157 "@npm//minimist" ,
4258 ],
4359 entry_point = ":main.ts" ,
4460)
4561
62+ jasmine_node_test (
63+ name = "test" ,
64+ deps = [
65+ ":test_lib" ,
66+ ],
67+ )
68+
4669load ("@io_bazel_rules_docker//nodejs:image.bzl" , "nodejs_image" )
4770
4871# bazel build --platforms=@build_bazel_rules_nodejs//toolchains/node:linux_amd64 //src:docker
Original file line number Diff line number Diff line change @@ -2,8 +2,8 @@ import {Controller, Get} from '@nestjs/common';
22
33@Controller ( )
44export class AppController {
5- @Get ( )
6- getGreeting ( ) : string {
7- return 'Hello world!' ;
5+ @Get ( 'hello' )
6+ getGreeting ( ) : { message : string } {
7+ return { message : 'Hello world!' } ;
88 }
99}
Original file line number Diff line number Diff line change 1+ import { INestApplication } from '@nestjs/common' ;
2+ import * as request from 'supertest' ;
3+
4+ import { bootstrap } from './main' ;
5+
6+ describe ( 'App' , ( ) => {
7+ let server : INestApplication ;
8+
9+ beforeAll ( async ( ) => {
10+ server = await bootstrap ( 3000 ) ;
11+ } ) ;
12+ afterAll ( async ( ) => {
13+ await server . close ( ) ;
14+ } )
15+
16+ it ( `GET /` , ( ) => {
17+ return request ( server . getHttpServer ( ) ) . get ( '/hello' ) . expect ( 200 ) . expect ( {
18+ message : 'Hello world!'
19+ } ) ;
20+ } ) ;
21+ } ) ;
Original file line number Diff line number Diff line change 1- import { Logger } from '@nestjs/common' ;
1+ import { INestApplication , Logger } from '@nestjs/common' ;
22import { NestFactory } from '@nestjs/core' ;
3+ import { ExpressAdapter } from '@nestjs/platform-express' ;
34
45import { AppModule } from './app.module' ;
56
6- async function bootstrap ( port : number ) {
7- const app = await NestFactory . create ( AppModule ) ;
7+ export async function bootstrap ( port : number ) : Promise < INestApplication > {
8+ const app = await NestFactory . create ( AppModule , new ExpressAdapter ( ) ) ;
89 await app . listen ( port ) ;
910 Logger . log ( `Application served at http://localhost:${ port } ` ) ;
11+ return app ;
1012}
1113
1214if ( require . main === module ) {
You can’t perform that action at this time.
0 commit comments