Optional callback is different definition + writing tests

This commit is contained in:
Jean-Philipe Pellerin
2016-02-24 15:49:42 -05:00
parent 5d90e28c18
commit 78b5a657f9
2 changed files with 50 additions and 36 deletions

View File

@@ -23,9 +23,16 @@ plugin.register.attributes = {
// optional options parameter
server.register({}, function (err) {});
// optional callback function with and without options
server.register({}).then((res: any) => {
console.log(res);
});
server.register({}, { select: "api", routes: { prefix: "/prefix" } }).then((res: any) => {
console.log(res);
});
// optional options.routes.vhost parameter
server.register({}, { select: 'api', routes: { prefix: '/prefix' } }, function (err) {});
server.register({}, { select: "api", routes: { prefix: "/prefix" } }, function (err) {});
//server.pack.register(plugin, (err: Object) => {
// if (err) { throw err; }

77
hapi/hapi.d.ts vendored
View File

@@ -959,40 +959,40 @@ declare module "hapi" {
}
export interface IServerInject {
(options: string | {
/** the request HTTP method (e.g. 'POST'). Defaults to 'GET'.*/
method: string;
/** the request URL. If the URI includes an authority (e.g. 'example.com:8080'), it is used to automatically set an HTTP 'Host' header, unless one was specified in headers.*/
url: string;
/** an object with optional request headers where each key is the header name and the value is the header content. Defaults to no additions to the default Shot headers.*/
headers?: IDictionary<string>;
/** n optional string, buffer or object containing the request payload. In case of an object it will be converted to a string for you. Defaults to no payload. Note that payload processing defaults to 'application/json' if no 'Content-Type' header provided.*/
payload?: string | {} | Buffer;
/** an optional credentials object containing authentication information. The credentials are used to bypass the default authentication strategies, and are validated directly as if they were received via an authentication scheme. Defaults to no credentials.*/
credentials?: any;
/** an optional artifacts object containing authentication artifact information. The artifacts are used to bypass the default authentication strategies, and are validated directly as if they were received via an authentication scheme. Ignored if set without credentials. Defaults to no artifacts.*/
artifacts?: any;
/** sets the initial value of request.app*/
app?: any;
/** sets the initial value of request.plugins*/
plugins?: any;
/** allows access to routes with config.isInternal set to true. Defaults to false.*/
allowInternals?: boolean;
/** sets the remote address for the incoming connection.*/
remoteAddress?: boolean;
/**object with options used to simulate client request stream conditions for testing:
error - if true, emits an 'error' event after payload transmission (if any). Defaults to false.
close - if true, emits a 'close' event after payload transmission (if any). Defaults to false.
end - if false, does not end the stream. Defaults to true.*/
simulate?: {
error: boolean;
close: boolean;
end: boolean;
};
},
callback?: (res: IServerInjectResponse) => void
): IPromise<IServerInjectResponse>;
(options: string | IServerInjectOptions, callback: (res: IServerInjectResponse) => void): void;
(options: string | IServerInjectOptions): IPromise<IServerInjectResponse>;
}
export interface IServerInjectOptions {
/** the request HTTP method (e.g. 'POST'). Defaults to 'GET'.*/
method: string;
/** the request URL. If the URI includes an authority (e.g. 'example.com:8080'), it is used to automatically set an HTTP 'Host' header, unless one was specified in headers.*/
url: string;
/** an object with optional request headers where each key is the header name and the value is the header content. Defaults to no additions to the default Shot headers.*/
headers?: IDictionary<string>;
/** n optional string, buffer or object containing the request payload. In case of an object it will be converted to a string for you. Defaults to no payload. Note that payload processing defaults to 'application/json' if no 'Content-Type' header provided.*/
payload?: string | {} | Buffer;
/** an optional credentials object containing authentication information. The credentials are used to bypass the default authentication strategies, and are validated directly as if they were received via an authentication scheme. Defaults to no credentials.*/
credentials?: any;
/** an optional artifacts object containing authentication artifact information. The artifacts are used to bypass the default authentication strategies, and are validated directly as if they were received via an authentication scheme. Ignored if set without credentials. Defaults to no artifacts.*/
artifacts?: any;
/** sets the initial value of request.app*/
app?: any;
/** sets the initial value of request.plugins*/
plugins?: any;
/** allows access to routes with config.isInternal set to true. Defaults to false.*/
allowInternals?: boolean;
/** sets the remote address for the incoming connection.*/
remoteAddress?: boolean;
/**object with options used to simulate client request stream conditions for testing:
error - if true, emits an 'error' event after payload transmission (if any). Defaults to false.
close - if true, emits a 'close' event after payload transmission (if any). Defaults to false.
end - if false, does not end the stream. Defaults to true.*/
simulate?: {
error: boolean;
close: boolean;
end: boolean;
};
}
@@ -2225,9 +2225,16 @@ Notes: 1. Default value. 2. Proposed code, not supported by all clients. */
routes: {
prefix: string; vhost?: string | string[]
};
}, callback?: (err: any) => void): IPromise<any>;
}, callback: (err: any) => void): void;
register(plugins: any | any[], options: {
select: string | string[];
routes: {
prefix: string; vhost?: string | string[]
};
}): IPromise<any>;
register(plugins: any | any[], callback?: (err: any) => void): IPromise<any>;
register(plugins: any | any[], callback: (err: any) => void): void;
register(plugins: any | any[]): IPromise<any>;
/**server.render(template, context, [options], callback)
Utilizes the server views manager to render a template where: