forked from kanongil/exiting
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: 💍 add lab typescript tests although it is giving issues that seem to be unrelated to the actual typings and related to @types/node
- Loading branch information
Showing
4 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,15 @@ | |
"test": "lab -a @hapi/code -t 100 -L", | ||
"test-cov-html": "lab -a @hapi/code -r html -o coverage.html" | ||
}, | ||
"types": "./types.d.ts", | ||
"author": "Gil Pedersen <[email protected]>", | ||
"license": "BSD-2-Clause", | ||
"devDependencies": { | ||
"@hapi/code": "^8.0.1", | ||
"@hapi/hapi": "^19.0.4", | ||
"@hapi/lab": "^22.0.3" | ||
"@hapi/lab": "^22.0.3", | ||
"@types/hapi__hapi": "^20.0.10", | ||
"typescript": "^4.5.5" | ||
}, | ||
"dependencies": { | ||
"@hapi/bounce": "^2.0.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Server } from '@hapi/hapi'; | ||
import { ExitingManagerOptions, createManager, Manager, ProcessExitError } from '..'; | ||
|
||
(async () => { | ||
|
||
const manager = createManager(new Server, { | ||
exitTimeout: 30 * 1000 | ||
}); | ||
|
||
|
||
const x = new ProcessExitError(); | ||
|
||
if (x instanceof TypeError) { | ||
|
||
console.log('error!'); | ||
} | ||
|
||
await manager.start(); | ||
await manager.stop(); | ||
|
||
await manager.deactive(); | ||
|
||
|
||
const options: ExitingManagerOptions = { | ||
exitTimeout: 30 * 1000 | ||
}; | ||
|
||
const manager2 = new Manager(new Server, options); | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": ["es6"], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictFunctionTypes": true, | ||
"strictNullChecks": true, | ||
"typeRoots": [ | ||
"./node_modules/@types" | ||
], | ||
// "types": ["node"], | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true, | ||
}, | ||
"include": [ | ||
"./types.d.ts", | ||
"./test" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Server } from '@hapi/hapi'; | ||
|
||
export interface ExitingManagerOptions { | ||
exitTimeout: number | ||
} | ||
|
||
export class Manager<S = Server | Server[], O = ExitingManagerOptions> { | ||
|
||
exitTimeout: number; | ||
servers: Server[]; | ||
state: 'starting' | 'started' | 'stopping' | 'prestopped' | 'stopped' | 'startAborted' | 'errored' | 'timeout'; | ||
exitTimer: number; | ||
exitCode: number; | ||
active: boolean | ||
|
||
constructor(servers: S, options: O) | ||
|
||
/** | ||
* Starts the Hapi servers. | ||
* Returns manager if the server starts succcessfully. | ||
*/ | ||
start(): Promise<Manager | void> | ||
|
||
/** | ||
* Stops the Hapi servers. | ||
* Throws if any server fails to stop. | ||
*/ | ||
stop(): Promise<Error | void> | ||
|
||
/** | ||
* Removes process listeners and resets process exit | ||
*/ | ||
deactive(): Promise<void> | ||
} | ||
|
||
/** | ||
* Creates a new manager for given servers | ||
* @param servers | ||
* @param options | ||
*/ | ||
export function createManager < | ||
S = Server | Server[], | ||
O = ExitingManagerOptions | ||
>( | ||
servers: S, | ||
options: O | ||
): Manager<S, O> | ||
|
||
/** | ||
* Console.error helper | ||
* @param args log arguments | ||
*/ | ||
export function log (...args: any[]): void; | ||
|
||
/** | ||
* Deactivates the existing manager | ||
*/ | ||
export function reset(): void | ||
|
||
/** | ||
* Custom exiting error thrown when process.exit() is called | ||
*/ | ||
export class ProcessExitError extends TypeError {} | ||
|