Skip to content

Commit

Permalink
Moved tests to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
noctifer20 committed Feb 12, 2019
1 parent 323c531 commit 67eb9a5
Show file tree
Hide file tree
Showing 22 changed files with 5,549 additions and 5,417 deletions.
216 changes: 111 additions & 105 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,105 +1,111 @@
/*
* Copyright (c) 2016-2018 Untu, Inc.
* This code is licensed under Eclipse Public License - v 1.0.
* The full license text can be found in LICENSE.txt file and
* on the Eclipse official site (https://www.eclipse.org/legal/epl-v10.html).
*/

import {EventEmitter} from 'events';

export interface Logger {
isDebug(): boolean;

debug(...messages: any[]): void;

info(...messages: any[]): void;

warn(...messages: any[]): void;

error(...messages: any[]): void;
}

export interface ParentActorRef {
getId(): string;

send(topic: string, ...message: any[]): Promise<void>;

sendAndReceive(topic: string, ...message: any[]): Promise<any>;
}

export interface SystemBus extends EventEmitter {
}

export interface ActorRef extends EventEmitter {
getId(): string;

getName(): string;

getLog(): Logger;

getSystem(): ActorSystem;

getMode(): string;

getState(): string;

getCustomParameters(): any;

changeConfiguration(config: object): Promise<void>;

changeGlobalConfiguration(config: object): Promise<void>;

send(topic: string, ...message: any[]): Promise<void>;

sendAndReceive(topic: string, ...message: any[]): Promise<any>;

broadcast(topic: string, ...message: any[]): Promise<void>;

broadcastAndReceive(topic: string, ...message: any[]): Promise<any[]>;

forwardToParent(...topics: Array<string|RegExp>): void;

forwardToChild(child: ActorRef, ...topics: Array<string|RegExp>): void;

metrics(): Promise<Object>;

destroy(): Promise<void>;

getBus(): SystemBus;

tree(): Promise<Object>;
}

export interface Actor extends ActorRef {
getParent(): ParentActorRef;

createChild(behaviour: ActorDefinition|Object, options?: Object): Promise<ActorRef>;

createChildren(modulePath: string): Promise<ActorRef[]>;
}

export interface ActorDefinition {
initialize(selfActor: Actor): Promise<void>|void;

destroy(): Promise<void>|void;
}

export interface ResourceDefinition<T> {
initialize(system: ActorSystem): Promise<void>|void;

destroy(): Promise<void>|void;

getResource(): T;
}

export interface ActorSystem {
rootActor(): Promise<Actor>;

destroy(): Promise<void>;

getBus(): SystemBus;

listen(port?: number, host?: string): Promise<void>;
}

export function createSystem(options: Object): ActorSystem;
/*
* Copyright (c) 2016-2018 Untu, Inc.
* This code is licensed under Eclipse Public License - v 1.0.
* The full license text can be found in LICENSE.txt file and
* on the Eclipse official site (https://www.eclipse.org/legal/epl-v10.html).
*/

import {EventEmitter} from 'events';
import * as P from 'bluebird';

export interface Logger {
isDebug(): boolean;

debug(...messages: any[]): void;

info(...messages: any[]): void;

warn(...messages: any[]): void;

error(...messages: any[]): void;
getImplementation(): any;
}

export interface ParentActorRef {
getId(): string;

send(topic: string, ...message: any[]): Promise<void>;

sendAndReceive(topic: string, ...message: any[]): P<any>;
}

export interface SystemBus extends EventEmitter {
}

export interface ActorRef extends EventEmitter {
getId(): string;

getName(): string;

getLog(): Logger;

getSystem(): ActorSystem;

getMode(): string;

getState(): string;

getCustomParameters(): any;

changeConfiguration(config: object): Promise<void>;

changeGlobalConfiguration(config: object): Promise<void>;

send(topic: string, ...message: any[]): Promise<void>;

sendAndReceive(topic: string, ...message: any[]): P<any>;

broadcast(topic: string, ...message: any[]): Promise<void>;

broadcastAndReceive(topic: string, ...message: any[]): Promise<any[]>;

forwardToParent(...topics: Array<string|RegExp>): void;

forwardToChild(child: ActorRef, ...topics: Array<string|RegExp>): void;

metrics(): Promise<{summary: { count: Number }}>;

destroy(): Promise<void>;

getBus(): SystemBus;

tree(): Promise<Object>;
}

export interface Actor extends ActorRef {
getParent(): ParentActorRef;

createChild(behaviour: ActorDefinition|Object, options?: Object): Promise<ActorRef>;

createChildren(modulePath: string, options?: Object): Promise<ActorRef[]>;
}

export interface ActorDefinition {
initialize(selfActor: Actor): Promise<void>|void;

destroy(): Promise<void>|void;
}

export interface ResourceDefinition<T> {
initialize(system: ActorSystem): Promise<void>|void;

destroy(): Promise<void>|void;

getResource(): T;
}

export interface ActorSystem {
rootActor(): Promise<Actor>;

destroy(): Promise<void>;

getBus(): SystemBus;

listen(port?: number, host?: string): Promise<void>;

getLog(): Logger;
}

export function createSystem(options: Object): ActorSystem;

export function inherits(subClass: any, superClass: any): void;
27 changes: 27 additions & 0 deletions lib/net/message-socket.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2016-2018 Untu, Inc.
* This code is licensed under Eclipse Public License - v 1.0.
* The full license text can be found in LICENSE.txt file and
* on the Eclipse official site (https://www.eclipse.org/legal/epl-v10.html).
*/

import { EventEmitter } from 'events';
import {Socket} from 'net';

export class MessageSocket extends EventEmitter {

constructor(socket: Socket);
// @ts-ignore
on(event: string | symbol, listener: (...args: any[]) => void): void;
// @ts-ignore
once(event: string | symbol, listener: (...args: any[]) => void): void;
// @ts-ignore
removeListener(event: string | symbol, listener: (...args: any[]) => void): void;

write(message: object, cb: Function): void;
send(message: object, cb?: Function): void;
makePacket(message: object): Buffer;
end(): void;
destroy(): void;
_handleIncomingData(data: Buffer): void;
}
3 changes: 2 additions & 1 deletion lib/net/message-socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,5 @@ class MessageSocket extends EventEmitter {
}
}

module.exports = MessageSocket;
module.exports = MessageSocket;
module.exports.MessageSocket = MessageSocket;
7 changes: 5 additions & 2 deletions lib/utils/common.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export function transformObject(input: Object, transformer: (value: any, key: string) => any): Object;
export function transformObjectRecursive(input: Object, transformer: (value: any, key: string) => any): Object;
export function transformObject(input: Object, transformer: (value: any, key: string) => any): Object;
export function transformObjectRecursive(input: Object, transformer: (value: any, key: string) => any): Object;
export function isPlainObject(input: any): boolean;
export function flatten(obj: object|undefined, options?: object): Object|undefined;
export function getNodeJsVersions(): { major: number, minor: number, revision: number };
3 changes: 3 additions & 0 deletions lib/utils/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
* The full license text can be found in LICENSE.txt file and
* on the Eclipse official site (https://www.eclipse.org/legal/epl-v10.html).
*/
import * as P from 'bluebird';

export function logStub(): Object;

export function waitForCondition(condition: any, deadline?: number, checkPeriod?: number): P<any>;
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
},
"homepage": "https://github.com/untu/comedy#readme",
"devDependencies": {
"@types/bson": "^1.0.11",
"@types/supertest": "^2.0.7",
"chai": "^3.5.0",
"chai-like": "^0.1.10",
"eslint": "4.3.0",
Expand All @@ -53,8 +55,8 @@
"np": "^2.13.1",
"nyc": "^11.0.3",
"supertest": "^3.0.0",
"tslint": "5.10.0",
"ts-node": "8.0.2",
"tslint": "5.10.0",
"typescript": "3.0.3"
},
"dependencies": {
Expand Down
19 changes: 19 additions & 0 deletions test-resources/ts-resources/types/chai-like.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Type definitions for chai-like 0.1.10
// Project: https://github.com/zation/chai-like
// Definitions by: noctifer20 <https://github.com/noctifer20>,

/// <reference types="chai" />

declare module 'chai-like' {
function chaiLike(chai: any, utils: any): void;
namespace chaiLike {

}
export = chaiLike;
}

declare namespace Chai {
interface Assertion extends LanguageChains, NumericComparison, TypeComparison {
like(toMatch: object|object[]): Assertion;
}
}
9 changes: 9 additions & 0 deletions test-resources/ts-resources/types/is-running.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Type definitions for is-running 2.1.0
// Project: https://github.com/nisaacson/is-running
// Definitions by: noctifer20 <https://github.com/noctifer20>,

declare module 'is-running' {
function isRunning(pid: number): boolean;
namespace isRunning {}
export = isRunning;
}
Loading

0 comments on commit 67eb9a5

Please sign in to comment.