Add more tests files.

This commit is contained in:
rafaelsouzaf
2017-12-09 12:03:06 -03:00
parent b453000bc5
commit 6fd4625f82
4 changed files with 59 additions and 1 deletions
+2
View File
@@ -19,6 +19,8 @@ export * from './reply/reply';
export * from './reply/state_cookie';
export * from './request/event-types';
export * from './request/get-log';
export * from './request/query';
export * from './response/error';
@@ -1,7 +1,6 @@
// from https://hapijs.com/tutorials/cookies?lang=en_US
import {Request, ResponseToolkit, Server, ServerOptions, ServerRoute, ServerStateCookieOptions} from "hapi";
const options: ServerOptions = {
port: 8000,
};
+30
View File
@@ -0,0 +1,30 @@
// From https://github.com/hapijs/hapi/blob/master/API.md#-requestlogtags-data
import {Lifecycle, Request, ResponseToolkit, Server, ServerOptions, ServerRoute} from "hapi";
const options: ServerOptions = {
port: 8000,
};
const handler: Lifecycle.Method = function(request: Request, h: ResponseToolkit) {
request.log(['test', 'error'], 'Test event');
return 'path: ' + request.path;
};
const serverRoute: ServerRoute = {
path: '/',
method: 'GET',
handler: handler
};
const server = new Server(options);
server.route(serverRoute);
server.start();
console.log('Server started at: ' + server.info.uri);
server.events.on('request', (request: Request, event: any, tags: any) => {
console.log(event);
console.log(tags);
if (tags.error) {
console.log(event);
}
});
+27
View File
@@ -0,0 +1,27 @@
// Added test in addition to docs, for request.query
import {Request, ResponseToolkit, Lifecycle, Server, ServerOptions, ServerRoute} from "hapi";
const options: ServerOptions = {
port: 8000,
};
const handler: Lifecycle.Method = function(request: Request, h: ResponseToolkit) {
const query = request.query as GetThingQuery;
// http://localhost:8000/?name=test
return `You asked for ${query.name}`
};
const serverRoute: ServerRoute = {
path: '/',
method: 'GET',
handler: handler
};
interface GetThingQuery {
name: string;
}
const server = new Server(options);
server.route(serverRoute);
server.start();
console.log('Server started at: ' + server.info.uri);