diff --git a/types/kraken-js/index.d.ts b/types/kraken-js/index.d.ts index 776228f0ac..0980e31eb1 100644 --- a/types/kraken-js/index.d.ts +++ b/types/kraken-js/index.d.ts @@ -5,22 +5,24 @@ // TypeScript Version: 2.2 import { Express } from 'express'; +import { EventEmitter } from 'events'; declare function k(options?: k.Options | string): Express; declare namespace k { - interface Kraken extends Express { - once(name: string, cb: (err: Error | null, result?: any) => any): void; + interface Kraken extends Express, EventEmitter { kraken: Kraken; } interface Options { protocols?: object; basedir?: string; + configdir?: string; mountpath?: string; inheritViews?: boolean; - startupHeaders?: Map; - onconfig?(config: object, next: (err: Error | null, config?: object) => any): any; + startupHeaders?: { [key: string]: string; }; + onconfig?(config: Map, next: (err: Error | null, config?: object) => any): any; + uncaughtException?(err: Error): any; } } diff --git a/types/kraken-js/kraken-js-tests.ts b/types/kraken-js/kraken-js-tests.ts index 86e44caae1..f3b7eea8c7 100644 --- a/types/kraken-js/kraken-js-tests.ts +++ b/types/kraken-js/kraken-js-tests.ts @@ -2,6 +2,7 @@ import express = require('express'); import kraken = require('kraken-js'); import * as http from 'http'; import * as https from 'https'; +import { readFile } from 'fs'; const app = express() as kraken.Kraken; @@ -13,16 +14,55 @@ kraken('path/to/options'); // $ExpectType Express kraken({ - onconfig: (config, next) => { + basedir: __dirname, + onconfig(config, next) { + config.get('view engines:js:renderer:arguments').push(app); + config.set('some:string', '/foo'); + config.set('some:complex:type', [{ + uncaughtException(error: Error) { + next(error); + } + }]); next(null, config); + }, + protocols: { + file(value: string, callback: any) { + readFile(value, 'utf8', callback); + } + }, + startupHeaders: { + 'Custom-Header1': 'Header1', + 'Custom-Header2': 'Header2' + }, + uncaughtException(err) { + console.error(err); } }); // $ExpectType Kraken app.use(kraken()); -// $ExpectType void -app.once('event', (err, result) => {}); +// $ExpectType Kraken +app.use(kraken(__dirname)); + +// $ExpectType Kraken +app.use(kraken({ + configdir: 'config', + protocols: { + custom(value: any) { + return `Hello, ${ value }!`; + } + } +})); + +app.listen(8080, (err?: Error) => { + console.log('[%s] Listening on http://localhost:%d', app.settings.env, 8080); +}); + +new Promise(resolve => { + // $ExpectType Kraken + app.once('event', resolve); +}); // $ExpectType any app.kraken.get('configProp');