Merge pull request #22471 from darkwebdev/kraken-js

@types/kraken-js - Fix callback arguments type, add tests
This commit is contained in:
Paul van Brenk
2017-12-29 12:18:12 -08:00
committed by GitHub
2 changed files with 49 additions and 7 deletions
+6 -4
View File
@@ -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<string, string>;
onconfig?(config: object, next: (err: Error | null, config?: object) => any): any;
startupHeaders?: { [key: string]: string; };
onconfig?(config: Map<string, any>, next: (err: Error | null, config?: object) => any): any;
uncaughtException?(err: Error): any;
}
}
+43 -3
View File
@@ -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');