[adone] add new and improve existing typings (#18878)

* [adone] introduce typings

* [adone] refactor to module style

* [adone] set strictNullChecks = true, fix utils test

* [adone] rename tests file, change compileOptions.target

* [adone] add interface namespaces

* [adone] add some util typings, fixes
* util.toposort
* util.GlobExp options
* util.ltgt
* util.fakeClock
* fix loadAsset return type

* [adone] create namespaces for tests

* [adone] create interface for util.fakeClock

* [adone] assertion typings
[adone] add possible types for util.typeOf

* [adone] promise

* [adone] add comments for assertion
[adone] add comments for namespaces

* [adone] add assertion.assert aliases

* [adone] assertion fixes

* [adone] shani, assertion, util, promise
* add shani typings, and shani global vars
* assertion fixes, add support for shani spy expectations
* fix util.fakeClock
* fix promise list issues
* disable space-before-function-paren rule

* [adone] fix assertions import

* [adone] shani
* allow user defined variables inside runtime contexts
This commit is contained in:
am
2017-08-14 20:24:35 +02:00
committed by Mohamed Hegazy
parent 3743d1f0eb
commit aa2183e844
16 changed files with 4420 additions and 3 deletions

View File

@@ -73,5 +73,13 @@ export { std };
export * from "./glosses/common";
export * from "./glosses/math";
export * from "./glosses/utils";
export * from "./glosses/assertion";
export * from "./glosses/promise";
export * from "./glosses/shani";
import "./glosses/shani-global";
export const assert: adone.assertion.I.AssertFunction;
export const expect: adone.assertion.I.ExpectFunction;
export as namespace adone;

1074
types/adone/glosses/assertion.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,6 @@
/**
* predicates
*/
export namespace is {
function _null(obj: any): boolean;
export { _null as null };

View File

@@ -1,3 +1,6 @@
/**
* math related things
*/
export namespace math {
namespace I {
interface LowHighBits {

114
types/adone/glosses/promise.d.ts vendored Normal file
View File

@@ -0,0 +1,114 @@
/**
* promise helpers
*/
export namespace promise {
namespace I {
interface Deferred<T> {
/**
* Resolves the promise
*/
resolve(value?: T): void;
/**
* Rejects the promise
*/
reject(value?: any): void;
promise: Promise<T>;
}
}
/**
* Creates a promise and returns an interface to control the state
*/
export function defer<T>(): I.Deferred<T>;
/**
* Creates a promise that will be resolved after given milliseconds
*
* @param ms delay in milliseconds
* @param value resolving value
*/
export function delay<T>(ms: number, value?: T): Promise<T>;
/**
* Creates a promise that will be rejected after given milliseconds if the given promise is not fulfilled
*
* @param ms timeout in milliseconds
*/
export function timeout<T>(promise: Promise<T>, ms: number): Promise<T>;
/**
* Converts a promise to node.js style callback
*/
export function nodeify<T>(promise: Promise<T>, callback: (err?: any, value?: T) => void): Promise<T>;
namespace I {
interface PromisifyOptions {
/**
* Context to bind to new function
*/
context?: object;
}
}
/**
* Converts a callback function to a promise-based function
*/
export function promisify<R>(fn: (callback: (err?: any, result?: R) => void) => void, options?: I.PromisifyOptions): () => Promise<R>;
export function promisify<T, R>(fn: (a: T, callback: (err?: any, result?: R) => void) => void, options?: I.PromisifyOptions): (a: T) => Promise<R>;
export function promisify<T>(fn: (a: T, callback: (err?: any) => void) => void, options?: I.PromisifyOptions): (a: T) => Promise<void>;
export function promisify<T1, T2, R>(fn: (a: T1, b: T2, callback: (err?: any, result?: R) => void) => void, options?: I.PromisifyOptions): (a: T1, b: T2) => Promise<R>;
export function promisify<T1, T2>(fn: (a: T1, b: T2, callback: (err?: any) => void) => void, options?: I.PromisifyOptions): (a: T1, b: T2) => Promise<void>;
export function promisify<T1, T2, T3, R>(fn: (a: T1, b: T2, c: T3, callback: (err?: any, result?: R) => void) => void, options?: I.PromisifyOptions): (a: T1, b: T2, c: T3) => Promise<R>;
export function promisify<T1, T2, T3>(fn: (a: T1, b: T2, c: T3, callback: (err?: any) => void) => void, options?: I.PromisifyOptions): (a: T1, b: T2, c: T3) => Promise<void>;
export function promisify<T1, T2, T3, T4, R>(
fn: (a: T1, b: T2, c: T3, d: T4, callback: (err?: any, result?: R) => void) => void,
options?: I.PromisifyOptions
): (a: T1, b: T2, c: T3, d: T4) => Promise<R>;
export function promisify<T1, T2, T3, T4>(
fn: (a: T1, b: T2, c: T3, d: T4, callback: (err?: any) => void) => void,
options?: I.PromisifyOptions
): (a: T1, b: T2, c: T3, d: T4) => Promise<void>;
export function promisify<T1, T2, T3, T4, T5, R>(
fn: (a: T1, b: T2, c: T3, d: T4, e: T5, callback: (err?: any, result?: R) => void) => void,
options?: I.PromisifyOptions
): (a: T1, b: T2, c: T3, d: T4, e: T5) => Promise<R>;
export function promisify<T1, T2, T3, T4, T5>(
fn: (a: T1, b: T2, c: T3, d: T4, callback: (err?: any) => void) => void,
options?: I.PromisifyOptions
): (a: T1, b: T2, c: T3, d: T4, e: T5) => Promise<void>;
export function promisify(fn: (...args: any[]) => void, options?: I.PromisifyOptions): (...args: any[]) => Promise<any>;
namespace I {
interface PromisifyAllOptions {
/**
* Suffix to use for keys
*/
suffix?: string;
/**
* Function to filter keys
*/
filter?(key: string): boolean;
/**
* Context to bind to new functions
*/
context?: object;
}
}
/**
* Promisifies entire object
*/
export function promisifyAll(source: object, options?: I.PromisifyAllOptions): object;
/**
* Executes a function after promise fulfillment
*
* @returns the original promise
*/
function _finally<T>(promise: Promise<T>, onFinally?: (...args: any[]) => void): Promise<T>;
export { _finally as finally };
}

79
types/adone/glosses/shani-global.d.ts vendored Normal file
View File

@@ -0,0 +1,79 @@
/**
* Defines a tests block
*/
declare const describe: adone.shani.I.DescribeFunction;
/**
* Defines a tests block
*/
declare const context: adone.shani.I.DescribeFunction;
/**
* Defines a test
*/
declare const it: adone.shani.I.TestFunction;
/**
* Defines a test
*/
declare const specify: adone.shani.I.TestFunction;
/**
* Defines a hook that will be called only once before the block's tests
*/
declare const before: adone.shani.I.HookFunction;
/**
* Defines a hook that will be called only once after the block's tests
*/
declare const after: adone.shani.I.HookFunction;
/**
* Defines a hook that will be called before each test
*/
declare const beforeEach: adone.shani.I.HookFunction;
/**
* Defines a hook that will be called after each test
*/
declare const afterEach: adone.shani.I.HookFunction;
/**
* assertion functions
*/
declare const assert: adone.assertion.I.AssertFunction;
/**
* bdd-style assertion functons
*/
declare const expect: adone.assertion.I.ExpectFunction;
/**
* tools for installing controllable timer functions
*/
declare const fakeClock: adone.util.I.fakeClock.FakeClock;
/**
* defines a spy function
*/
declare const spy: typeof adone.shani.util.spy;
/**
* defines a stub function
*/
declare const stub: typeof adone.shani.util.stub;
/**
* defines a mock function
*/
declare const mock: typeof adone.shani.util.mock;
/**
* defines a matcher for spies/stubs/mocks
*/
declare const match: typeof adone.shani.util.match;
/**
* assertion tool for http server responses
*/
declare const request: typeof adone.shani.util.request;

1655
types/adone/glosses/shani.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,6 @@
/**
* various utility functions
*/
export namespace util {
function arrify<T>(val: T[]): T[];
function arrify<T>(val: T): [T];
@@ -184,6 +187,14 @@ export namespace util {
}
function jsesc(argument: any, options?: I.JSEscOptions): string;
namespace I {
type PossibleTypes = "object" | "class" | "null" | "global" | "Array" | "RegExp" | "Date"
| "Promise" | "Set" | "Map" | "WeakSet" | "DataView" | "Map Iterator" | "Set Iterator"
| "Array Iterator" | "String Iterator" | "Object" | "function" | "boolean" | "number"
| "undefined" | "string" | "symbol";
}
function typeOf(obj: any): I.PossibleTypes;
function typeOf(obj: any): string;
namespace memcpy {
@@ -394,7 +405,7 @@ export namespace util {
interface FakeClock {
timers: Timers;
createClock(now?: number, loopLimit?: number): Clock;
install(now: number | Date | InstallOptions): InstalledClock;
install(now?: number | Date | InstallOptions): InstalledClock;
}
}

View File

@@ -0,0 +1,653 @@
namespace assertionTests {
const { assertion } = adone;
namespace assertionInterface {
namespace exception {
const a: adone.x.Exception = new assertion.AssertionError();
const b: adone.x.Exception = new assertion.AssertionError("hello");
const c: adone.x.Exception = new assertion.AssertionError("hello", { actual: 2, expected: 3 }, () => {});
}
namespace config {
assertion.config.includeStack = true;
assertion.config.proxyExcludedKeys = ["a"];
assertion.config.showDiff = false;
assertion.config.truncateThreshold = 20;
assertion.config.useProxy = false;
}
namespace loadInterfaces {
assertion.loadAssertInterface().config.includeStack = true;
assertion.loadExpectInterface().config.includeStack = true;
assertion.loadMockInterface().config.includeStack = true;
}
namespace use {
assertion.use(() => {}).use(() => {}).config.includeStack = true;
}
}
const { assert } = assertion;
namespace assertTests {
assert(1);
assert(1, "hello");
assert.fail();
assert.fail(1);
assert.fail(1, 2);
assert.fail(1, 2, "hello");
assert.fail(1, 2, "hello", "<");
assert.isOk(1);
assert.isOk(1, "hello");
assert.isNotOk(1);
assert.isNotOk(1, "hello");
assert.equal(1, 2);
assert.equal(1, 2, "hello");
assert.notEqual(1, 2);
assert.notEqual(1, 2, "hello");
assert.strictEqual(1, 2);
assert.strictEqual(1, 2, "hello");
assert.notStrictEqual(1, 2);
assert.notStrictEqual(1, 2, "hello");
assert.deepEqual(1, 2);
assert.deepEqual(1, 2, "hello");
assert.deepStrictEqual(1, 2);
assert.deepStrictEqual(1, 2, "hello");
assert.equalArrays([1, 2, 3], [4, 5, 6]);
assert.equalArrays([1, 2, 3], [4, 5, 6], "hello");
assert.notDeepEqual(1, 2);
assert.notDeepEqual(1, 2, "hello");
assert.isAbove(1, 2);
assert.isAbove(1, 2, "hello");
assert.isAtLeast(1, 2);
assert.isAtLeast(1, 2, "hello");
assert.isBelow(1, 2);
assert.isBelow(1, 2, "hello");
assert.isAtMost(1, 2);
assert.isAtMost(1, 2, "hello");
assert.isTrue(1);
assert.isTrue(1, "hello");
assert.isNotTrue(1);
assert.isNotTrue(1, "hello");
assert.isFalse(1);
assert.isFalse(1, "hello");
assert.isNotFalse(1);
assert.isNotFalse(1, "hello");
assert.isNull(1);
assert.isNull(1, "hello");
assert.isNaN(1);
assert.isNaN(1, "hello");
assert.isNotNaN(1);
assert.isNotNaN(1, "hello");
assert.exists(1);
assert.exists(1, "hello");
assert.notExists(1);
assert.notExists(1, "hello");
assert.isUndefined(1);
assert.isUndefined(1, "hello");
assert.isDefined(1);
assert.isDefined(1, "hello");
assert.isFunction(1);
assert.isFunction(1, "hello");
assert.isNotFunction(1);
assert.isNotFunction(1, "hello");
assert.isObject(1);
assert.isObject(1, "hello");
assert.isNotObject(1);
assert.isNotObject(1, "hello");
assert.isArray(1);
assert.isArray(1, "hello");
assert.isNotArray(1);
assert.isNotArray(1, "hello");
assert.isString(1, "hello");
assert.isNotString(1);
assert.isNotString(1, "hello");
assert.isNumber(1);
assert.isNumber(1, "hello");
assert.isNotNumber(1);
assert.isNotNumber(1, "hello");
assert.isFinite(1);
assert.isFinite(1, "hello");
assert.isBoolean(1);
assert.isBoolean(1, "hello");
assert.isNotBoolean(1);
assert.isNotBoolean(1, "hello");
assert.typeOf(1, "string");
assert.typeOf(1, "number", "hello");
assert.notTypeOf(1, "string");
assert.notTypeOf(1, "number", "hello");
assert.instanceOf(1, Date);
class A {}
assert.instanceOf("4", A, "hello");
assert.notInstanceOf(1, Date);
assert.notInstanceOf(Date, A, "hello");
assert.include([1, 2, 3], 4);
assert.include([1, 2, 3], 4, "hello");
assert.include("string", "string");
assert.include("string", "string", "string");
assert.notInclude([1, 2, 3], 4);
assert.notInclude([1, 2, 3], 4, "hello");
assert.notInclude("string", "string");
assert.notInclude("string", "string", "string");
assert.deepInclude([1, 2, 3], 4);
assert.deepInclude([1, 2, 3], 4, "hello");
assert.deepInclude("string", "string");
assert.deepInclude("string", "string", "string");
assert.notDeepInclude([1, 2, 3], 4);
assert.notDeepInclude([1, 2, 3], 4, "hello");
assert.notDeepInclude("string", "string");
assert.notDeepInclude("string", "string", "string");
assert.nestedInclude({ a: 1 }, {});
assert.nestedInclude({ a: 1 }, {}, "hello");
assert.notNestedInclude({ a: 1 }, {});
assert.notNestedInclude({ a: 1 }, {}, "hello");
assert.deepNestedInclude({ a: 1 }, {});
assert.deepNestedInclude({ a: 1 }, {}, "hello");
assert.notDeepNestedInclude({ a: 1 }, {});
assert.notDeepNestedInclude({ a: 1 }, {}, "hello");
assert.ownInclude({ a: 1 }, {});
assert.ownInclude({ a: 1 }, {}, "hello");
assert.notOwnInclude({ a: 1 }, {});
assert.notOwnInclude({ a: 1 }, {}, "hello");
assert.deepOwnInclude({ a: 1 }, {});
assert.deepOwnInclude({ a: 1 }, {}, "hello");
assert.notDeepOwnInclude({ a: 1 }, {});
assert.notDeepOwnInclude({ a: 1 }, {}, "hello");
assert.match("1", /\d+/);
assert.match("1", /\d+/, "hello");
assert.notMatch("1", /\d+/);
assert.notMatch("1", /\d+/, "hello");
assert.property({ a: 1 }, "a");
assert.property({ a: 1 }, "a", "hello");
assert.notProperty({ a: 1 }, "a");
assert.notProperty({ a: 1 }, "a", "hello");
assert.propertyVal({ a: 1 }, "a", 1);
assert.propertyVal({ a: 1 }, "a", 1, "hello");
assert.notPropertyVal({ a: 1 }, "a", 1);
assert.notPropertyVal({ a: 1 }, "a", 1, "hello");
assert.deepPropertyVal({ a: 1 }, "a", 1);
assert.deepPropertyVal({ a: 1 }, "a", 1, "hello");
assert.notDeepPropertyVal({ a: 1 }, "a", 1);
assert.notDeepPropertyVal({ a: 1 }, "a", 1, "hello");
assert.ownProperty({ a: 1 }, "a");
assert.ownProperty({ a: 1 }, "a", "hello");
assert.notOwnProperty({ a: 1 }, "a");
assert.notOwnProperty({ a: 1 }, "a", "hello");
assert.ownPropertyVal({ a: 1 }, "a", 1);
assert.ownPropertyVal({ a: 1 }, "a", 1, "hello");
assert.deepOwnPropertyVal({ a: 1 }, "a", 1);
assert.deepOwnPropertyVal({ a: 1 }, "a", 1, "hello");
assert.notDeepOwnPropertyVal({ a: 1 }, "a", 1);
assert.notDeepOwnPropertyVal({ a: 1 }, "a", 1, "hello");
assert.nestedProperty({ a: 1 }, "a");
assert.nestedProperty({ a: 1 }, "a", "hello");
assert.notNestedProperty({ a: 1 }, "a");
assert.notNestedProperty({ a: 1 }, "a", "hello");
assert.nestedPropertyVal({ a: 1 }, "a", 1);
assert.nestedPropertyVal({ a: 1 }, "a", 1, "hello");
assert.notNestedPropertyVal({ a: 1 }, "a", 1);
assert.notNestedPropertyVal({ a: 1 }, "a", 1, "hello");
assert.deepNestedPropertyVal({ a: 1 }, "a", 1);
assert.deepNestedPropertyVal({ a: 1 }, "a", 1, "hello");
assert.notDeepNestedPropertyVal({ a: 1 }, "a", 1);
assert.notDeepNestedPropertyVal({ a: 1 }, "a", 1, "hello");
assert.lengthOf([1, 2, 3], 3);
assert.lengthOf([1, 2, 3], 3, "hello");
assert.hasAnyKeys({ a: 1 }, "a");
assert.hasAnyKeys({ a: 1 }, ["a"]);
assert.hasAnyKeys({ a: 1 }, ["a"], "hello");
assert.hasAnyKeys({ a: 1 }, { a: 1 });
assert.hasAnyKeys({ a: 1 }, { a: 1 }, "hello");
assert.hasAllKeys({ a: 1 }, "a");
assert.hasAllKeys({ a: 1 }, ["a"]);
assert.hasAllKeys({ a: 1 }, ["a"], "hello");
assert.hasAllKeys({ a: 1 }, { a: 1 });
assert.hasAllKeys({ a: 1 }, { a: 1 }, "hello");
assert.containsAllKeys({ a: 1 }, "a");
assert.containsAllKeys({ a: 1 }, ["a"]);
assert.containsAllKeys({ a: 1 }, ["a"], "hello");
assert.containsAllKeys({ a: 1 }, { a: 1 });
assert.containsAllKeys({ a: 1 }, { a: 1 }, "hello");
assert.doesNotHaveAnyKeys({ a: 1 }, "a");
assert.doesNotHaveAnyKeys({ a: 1 }, ["a"]);
assert.doesNotHaveAnyKeys({ a: 1 }, ["a"], "hello");
assert.doesNotHaveAnyKeys({ a: 1 }, { a: 1 });
assert.doesNotHaveAnyKeys({ a: 1 }, { a: 1 }, "hello");
assert.doesNotHaveAllDeepKeys({ a: 1 }, "a");
assert.doesNotHaveAllDeepKeys({ a: 1 }, ["a"]);
assert.doesNotHaveAllDeepKeys({ a: 1 }, ["a"], "hello");
assert.doesNotHaveAllDeepKeys({ a: 1 }, { a: 1 });
assert.doesNotHaveAllDeepKeys({ a: 1 }, { a: 1 }, "hello");
assert.hasAnyDeepKeys({ a: 1 }, "a");
assert.hasAnyDeepKeys({ a: 1 }, ["a"]);
assert.hasAnyDeepKeys({ a: 1 }, ["a"], "hello");
assert.hasAnyDeepKeys({ a: 1 }, { a: 1 });
assert.hasAnyDeepKeys({ a: 1 }, { a: 1 }, "hello");
assert.hasAllDeepKeys({ a: 1 }, "a");
assert.hasAllDeepKeys({ a: 1 }, ["a"]);
assert.hasAllDeepKeys({ a: 1 }, ["a"], "hello");
assert.hasAllDeepKeys({ a: 1 }, { a: 1 });
assert.hasAllDeepKeys({ a: 1 }, { a: 1 }, "hello");
assert.containsAllDeepKeys({ a: 1 }, "a");
assert.containsAllDeepKeys({ a: 1 }, ["a"]);
assert.containsAllDeepKeys({ a: 1 }, ["a"], "hello");
assert.containsAllDeepKeys({ a: 1 }, { a: 1 });
assert.containsAllDeepKeys({ a: 1 }, { a: 1 }, "hello");
assert.doesNotHaveAnyDeepKeys({ a: 1 }, "a");
assert.doesNotHaveAnyDeepKeys({ a: 1 }, ["a"]);
assert.doesNotHaveAnyDeepKeys({ a: 1 }, ["a"], "hello");
assert.doesNotHaveAnyDeepKeys({ a: 1 }, { a: 1 });
assert.doesNotHaveAnyDeepKeys({ a: 1 }, { a: 1 }, "hello");
assert.doesNotHaveAllDeepKeys({ a: 1 }, "a");
assert.doesNotHaveAllDeepKeys({ a: 1 }, ["a"]);
assert.doesNotHaveAllDeepKeys({ a: 1 }, ["a"], "hello");
assert.doesNotHaveAllDeepKeys({ a: 1 }, { a: 1 });
assert.doesNotHaveAllDeepKeys({ a: 1 }, { a: 1 }, "hello");
assert.throws(() => {});
assert.throws(() => {}, Error);
assert.throws(() => {}, Error, /\d+/);
assert.throws(() => {}, Error, "string");
assert.throws(() => {}, Error, "string", "hello");
assert.throws(async () => {}).then(() => 42);
assert.throws(async () => {}, Error).then(() => 42);
assert.throws(async () => {}, Error, /\d+/).then(() => 42);
assert.throws(async () => {}, Error, "string").then(() => 42);
assert.throws(async () => {}, Error, "string", "hello").then(() => 42);
assert.doesNotThrow(() => {});
assert.doesNotThrow(() => {}, Error);
assert.doesNotThrow(() => {}, Error, /\d+/);
assert.doesNotThrow(() => {}, Error, "string");
assert.doesNotThrow(() => {}, Error, "string", "hello");
assert.doesNotThrow(async () => {}).then(() => 42);
assert.doesNotThrow(async () => {}, Error).then(() => 42);
assert.doesNotThrow(async () => {}, Error, /\d+/).then(() => 42);
assert.doesNotThrow(async () => {}, Error, "string").then(() => 42);
assert.doesNotThrow(async () => {}, Error, "string", "hello").then(() => 42);
assert.operator(1, "<", 2);
assert.operator(1, "<", 2, "hello");
assert.closeTo(1, 2, 1);
assert.closeTo(1, 2, 1, "hello");
assert.approximately(1, 2, 2);
assert.approximately(1, 2, 2, "hello");
assert.sameMembers([1, 2, 3], [4, 5, 6]);
assert.sameMembers([1, 2, 3], [4, 5, 6], "hello");
assert.notSameMembers([1, 2, 3], [4, 5, 6]);
assert.notSameMembers([1, 2, 3], [4, 5, 6], "hello");
assert.sameDeepMembers([1, 2, 3], [4, 5, 6]);
assert.sameDeepMembers([1, 2, 3], [4, 5, 6], "hello");
assert.notSameDeepMembers([1, 2, 3], [4, 5, 6]);
assert.notSameDeepMembers([1, 2, 3], [4, 5, 6], "hello");
assert.sameOrderedMembers([1, 2, 3], [4, 5, 6]);
assert.sameOrderedMembers([1, 2, 3], [4, 5, 6], "hello");
assert.notSameOrderedMembers([1, 2, 3], [4, 5, 6]);
assert.notSameOrderedMembers([1, 2, 3], [4, 5, 6], "hello");
assert.includeMembers([1, 2, 3], [3]);
assert.includeMembers([1, 2, 3], [3], "hello");
assert.notIncludeMembers([1, 2, 3], [3]);
assert.notIncludeMembers([1, 2, 3], [3], "hello");
assert.includeDeepMembers([1, 2, 3], [3]);
assert.includeDeepMembers([1, 2, 3], [3], "hello");
assert.notIncludeDeepMembers([1, 2, 3], [3]);
assert.notIncludeDeepMembers([1, 2, 3], [3], "hello");
assert.includeOrderedMembers([1, 2, 3], [3]);
assert.includeOrderedMembers([1, 2, 3], [3], "hello");
assert.notIncludeOrderedMembers([1, 2, 3], [3]);
assert.notIncludeOrderedMembers([1, 2, 3], [3], "hello");
assert.includeDeepOrderedMembers([1, 2, 3], [3]);
assert.includeDeepOrderedMembers([1, 2, 3], [3], "hello");
assert.notIncludeDeepOrderedMembers([1, 2, 3], [3]);
assert.notIncludeDeepOrderedMembers([1, 2, 3], [3], "hello");
assert.oneOf(1, [1, 2, 3]);
assert.oneOf(1, [1, 2, 3], "hello");
assert.changes(() => {}, {}, "a");
assert.changes(() => {}, {}, "a", "hello");
assert.changesBy(() => {}, {}, "a", 2);
assert.changesBy(() => {}, {}, "a", 2, "hello");
assert.doesNotChange(() => {}, {}, "a");
assert.doesNotChange(() => {}, {}, "a", "hello");
assert.changesButNotBy(() => {}, {}, "a", 20);
assert.changesButNotBy(() => {}, {}, "a", 20, "hello");
assert.increases(() => {}, {}, "a");
assert.increases(() => {}, {}, "a", "hello");
assert.increasesBy(() => {}, {}, "a", 20);
assert.increasesBy(() => {}, {}, "a", 20, "hello");
assert.doesNotIncrease(() => {}, {}, "a");
assert.doesNotIncrease(() => {}, {}, "a", "hello");
assert.increasesButNotBy(() => {}, {}, "a", 20);
assert.increasesButNotBy(() => {}, {}, "a", 20, "hello");
assert.decreases(() => {}, {}, "a");
assert.decreases(() => {}, {}, "a", "hello");
assert.decreasesBy(() => {}, {}, "a", 20);
assert.decreasesBy(() => {}, {}, "a", 20, "hello");
assert.doesNotDecrease(() => {}, {}, "a");
assert.doesNotDecrease(() => {}, {}, "a", "hello");
assert.doesNotDecreaseBy(() => {}, {}, "a", 20);
assert.doesNotDecreaseBy(() => {}, {}, "a", 20, "hello");
assert.decreasesButNotBy(() => {}, {}, "a", 20);
assert.decreasesButNotBy(() => {}, {}, "a", 20, "hello");
assert.ifError(1);
assert.isExtensible({});
assert.isExtensible({}, "hello");
assert.isNotExtensible({});
assert.isNotExtensible({}, "hello");
assert.isSealed({});
assert.isSealed({}, "hello");
assert.isNotSealed({});
assert.isNotSealed({}, "hello");
assert.isFrozen({});
assert.isFrozen({}, "hello");
assert.isNotFrozen({});
assert.isNotFrozen({}, "hello");
assert.isEmpty({});
assert.isEmpty({}, "hello");
}
const { expect } = assertion;
namespace expectTests {
expect(1);
expect(1, "hello");
expect.fail(1, 2);
expect.fail(1, 2, "hello");
expect.fail(1, 2, "hello", "+");
expect(1).to.be.been.is.and.has.have.with.that.which.at.of.same.but.does.not.deep.nested.own.ordered.any.all.a("number");
expect(1).to.be.a("number", "hello").and;
expect(1).to.be.an("array").and;
expect(1).to.be.an("array", "hello").and;
expect(1).to.include(1).and;
expect(1).to.include(1, "hello").and;
expect(1).but.includes(2).and;
expect(1).but.includes(2, "hello").and;
expect(1).to.contain(2).and;
expect(1).to.contain(2, "hello").and;
expect(1).but.contains(2).and;
expect(1).but.contains(2, "hello").and;
expect(1).to.ok.not.ok;
expect(1).to.be.true.but.false;
expect(1).to.be.false.but.true;
expect(1).to.be.null.and.null;
expect(1).to.be.undefined.and.true;
expect(1).to.be.NaN.and.null;
expect(1).to.exist.and.be.null;
expect(1).to.be.empty.and.true;
expect(1).to.be.arguments.and.a("number");
expect(1).to.be.Arguments.and.false;
expect(1).to.be.equal(2).and;
expect(1).to.be.equal(2, "hello").and;
expect(1).but.equals(2).and;
expect(1).but.equals(2, "hello").and;
expect(1).to.eq(2).and;
expect(1).to.eq(2, "hello").and;
expect(1).but.eqls(2).and;
expect(1).but.eqls(2, "hello").and;
expect(1).to.eqlArray([1, 2, 3]).and;
expect(1).to.eqlArray([1, 2, 3], "hello").and;
expect(1).to.be.above(2).and;
expect(1).to.be.above(2, "hello").and;
expect(1).to.be.gt(2).and;
expect(1).to.be.gt(2, "hello").and;
expect(1).to.be.greaterThan(2).and;
expect(1).to.be.greaterThan(2, "hello").and;
expect(1).to.be.at.least(10).and;
expect(1).to.be.at.least(10, "hello").and;
expect(1).to.be.gte(10).and;
expect(1).to.be.gte(10, "hello").and;
expect(1).to.be.below(100).and;
expect(1).to.be.below(100, "hello").and;
expect(1).to.be.lt(10).and;
expect(1).to.be.lt(10, "hello").and;
expect(1).to.be.lessThan(10, "hello").and;
expect(1).to.be.at.most(10).and;
expect(1).to.be.at.most(10, "hello").and;
expect(1).to.be.lte(10).and;
expect(1).to.be.lte(10, "hello").and;
expect(1).to.be.within(1, 10).and;
expect(1).to.be.within(1, 10, "hello").and;
expect(1).to.be.instanceof(Number).and;
expect(1).to.be.instanceof(Number, "hello").and;
expect(1).to.be.instanceOf(Number).and;
expect(1).to.be.instanceOf(Number, "hello").and;
expect(1).to.have.property("a").and;
expect(1).to.have.property("a", 1).and;
expect(1).to.have.property("a", 1, "hello").and;
expect(1).to.have.ownProperty("a").and;
expect(1).to.have.ownProperty("a", 1).and;
expect(1).to.have.ownProperty("a", 1, "hello").and;
expect(1).to.haveOwnProperty("a").and;
expect(1).to.haveOwnProperty("a", 1).and;
expect(1).to.haveOwnProperty("a", 1, "hello").and;
expect(1).to.have.ownPropertyDescriptor("a").and;
expect(1).to.have.ownPropertyDescriptor("a", {}).and;
expect(1).to.have.ownPropertyDescriptor("a", {}, "hello").and;
expect(1).to.haveOwnPropertyDescriptor("a").and;
expect(1).to.haveOwnPropertyDescriptor("a", {}).and;
expect(1).to.haveOwnPropertyDescriptor("a", {}, "hello").and;
expect("a").to.have.length(1).and;
expect("a").to.have.length(1, "hello").and;
expect("a").to.have.lengthOf(1).and;
expect("a").to.have.lengthOf(1, "hello").and;
expect(1).to.match(/\d+/).and;
expect(1).to.match(/\d+/, "hello").and;
expect(1).to.have.string("1230").and;
expect(1).to.have.string("1230", "hello").and;
expect(1).to.have.key("a").and;
expect(1).to.have.key("a", "b").and;
expect(1).to.have.key(["a", "b"]).and;
expect(1).to.have.key({ a: 1, b: 2 }).and;
expect(1).to.have.keys("a").and;
expect(1).to.have.keys("a", "b").and;
expect(1).to.have.keys(["a", "b"]).and;
expect(1).to.have.keys({ a: 1, b: 2 }).and;
expect(() => {}).to.throw().and;
expect(() => {}).to.throw(Error).and;
expect(() => {}).to.throw(Error, "string").and;
expect(() => {}).to.throw(Error, "string", "hello").and;
expect(() => {}).to.throw(Error, /\d+/).and;
expect(() => {}).to.throw(Error, /\d+/, "hello").and;
expect(() => {}).but.throws().and;
expect(() => {}).but.throws(Error).and;
expect(() => {}).but.throws(Error, "string").and;
expect(() => {}).but.throws(Error, "string", "hello").and;
expect(() => {}).but.throws(Error, /\d+/).and;
expect(() => {}).but.throws(Error, /\d+/, "hello").and;
expect(1).to.respondTo("a").and;
expect(1).to.respondTo("a", "hello").and;
expect(1).to.respondsTo("a").and;
expect(1).to.respondsTo("a", "hello").and;
expect(1).itself.to.respondsTo("a").and;
expect(1).to.satisfy(() => true).and;
expect(1).to.satisfy(() => true, "hello").and;
expect(1).but.satisfies(() => true).and;
expect(1).but.satisfies(() => true, "hello").and;
expect(1).to.be.closeTo(2, 1).and;
expect(1).to.be.closeTo(2, 1, "hello").and;
expect(1).to.be.approximately(1, 2).and;
expect(1).to.be.approximately(1, 2, "hello").and;
expect(1).to.have.members([1, 2, 3]).and;
expect(1).to.have.members([1, 2, 3], "hello").and;
expect(1).to.be.oneOf([1, 2, 3]).and;
expect(1).to.be.oneOf([1, 2, 3], "hello").and;
expect(() => {}).to.change(() => {}).and;
expect(() => {}).to.change({}, "a").and;
expect(() => {}).to.change({}, "a", "hello").and;
expect(() => {}).but.changes(() => {}).and;
expect(() => {}).but.changes({}, "a").and;
expect(() => {}).but.changes({}, "a", "hello").and;
expect(() => {}).to.increase({}).and;
expect(() => {}).to.increase({}, "a").and;
expect(() => {}).to.increase({}, "a", "hello").and;
expect(() => {}).but.increases({}).and;
expect(() => {}).but.increases({}, "a").and;
expect(() => {}).but.increases({}, "a", "hello").and;
expect(() => {}).to.decrease({}).and;
expect(() => {}).to.decrease({}, "a").and;
expect(() => {}).to.decrease({}, "a", "hello").and;
expect(() => {}).but.decreases({}).and;
expect(() => {}).but.decreases({}, "a").and;
expect(() => {}).but.decreases({}, "a", "hello").and;
expect(() => {}).to.decreases({}).by(2).and;
expect(() => {}).to.decreases({}).by(2, "hello").and;
expect({}).to.be.extensible.and;
expect({}).to.be.sealed.and;
expect({}).to.be.frozen.and;
expect({}).to.be.finite.and;
namespace mockTests {
const s1 = adone.shani.util.spy();
const s2 = adone.shani.util.spy();
expect(s1).to.have.been.called;
expect(s1).to.have.been.calledOnce;
expect(s1).to.have.been.calledTwice;
expect(s1).to.have.been.calledThrice;
expect(s1).to.have.callCount(100);
expect(s1).to.have.been.calledBefore(s2);
expect(s1).to.have.been.calledAfter(s2);
expect(s1).to.have.been.calledImmediatelyAfter(s2);
expect(s1).to.have.been.calledImmediatelyBefore(s2);
expect(s1).to.have.been.calledOn({});
expect(s1).to.have.been.calledOn({});
expect(s1).to.have.been.calledWith(1, 2, 3);
expect(s1).to.have.been.calledWithExactly(1, 2, 3);
expect(s1).to.have.returned(1);
expect(s1).to.have.thrown({});
}
}
}

View File

@@ -0,0 +1,97 @@
namespace promiseTests {
const { promise } = adone;
namespace defer {
const a = promise.defer();
a.promise.then((x) => 2);
a.resolve(2);
a.reject(3);
const b = promise.defer<string>();
b.resolve("3");
b.reject(2);
b.promise.then((x: string) => x);
}
namespace delay {
const a: Promise<any> = promise.delay(10);
const b: Promise<number> = promise.delay(10, 2);
promise.delay(20, "3").then((x: string) => x);
}
namespace timeout {
promise.timeout(Promise.resolve(2), 100).then((x: number) => x);
}
namespace nodeify {
promise.nodeify(Promise.resolve(2), (err: any, value: number) => value).then((x: number) => x);
promise.nodeify(Promise.resolve(2), () => 42).then((x: number) => x);
}
namespace promisify {
type Callback<T> = (err?: any, result?: T) => void;
namespace noargs {
const f = (cb: Callback<number>) => {
cb(null, 32);
};
promise.promisify(f)().then((x: number) => { });
}
namespace nargs1 {
const f = (a: number, cb: Callback<number>) => {
cb(null, 32);
};
promise.promisify(f)(1).then((x: number) => { });
}
namespace nargs2 {
const f = (a: number, b: string, cb: Callback<number>) => {
cb(null, 32);
};
promise.promisify(f)(1, "1").then((x: number) => { });
}
namespace nargs3 {
const f = (a: number, b: string, c: number, cb: Callback<number>) => {
cb(null, 32);
};
promise.promisify(f)(1, "1", 1).then((x: number) => { });
}
namespace nargs4 {
const f = (a: number, b: string, c: number, d: string, cb: Callback<number>) => {
cb(null, 32);
};
promise.promisify(f)(1, "1", 1, "1").then((x: number) => { });
}
namespace nargs5 {
const f = (a: number, b: string, c: number, d: string, e: number, cb: Callback<number>) => {
cb(null, 32);
};
promise.promisify(f)(1, "1", 1, "1", 1).then((x: number) => { });
}
namespace moreargs {
const f = (a: number, b: string, c: number, d: string, e: number, f: string, cb: Callback<number>) => {
cb(null, 32);
};
promise.promisify(f)(1, 2, 3).then((x) => x);
}
namespace options {
promise.promisify((cb: Callback<number>) => cb(null, 42), {});
promise.promisify((cb: Callback<number>) => cb(null, 42), { context: {} });
}
}
namespace promisifyAll {
const a: object = promise.promisifyAll({});
promise.promisifyAll({}, {});
promise.promisifyAll({}, { context: {} });
promise.promisifyAll({}, { filter: () => true });
promise.promisifyAll({}, { suffix: "Async" });
}
namespace _finally {
promise.finally(Promise.resolve(2), () => 2).then((x: number) => {});
}
}

View File

@@ -0,0 +1,163 @@
namespace shaniGlobalTests {
namespace describeTests {
describe("hello", () => {});
describe("hello", function () {
this.skip();
this.timeout(10);
this.a;
});
describe("1", "2", "3", "4", "45", function () {
this.skip();
this.timeout(10);
this.a;
});
describe("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", function () {
this.skip();
this.timeout(10);
this.a;
});
context("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", function () {
this.skip();
this.timeout(10);
this.a;
});
}
namespace itTests {
it("should be here", () => {});
it("should be here", function () {
this.timeout(100);
this.skip();
this.a;
});
it("should be here", function (done: () => void) {
this.timeout(1000);
done();
this.a;
});
it("hello", {}, () => {});
it("hello", {
skip: true
}, () => {});
it("hello", {
skip: () => true
}, () => {});
it("hello", {
timeout: () => 1202
}, () => {});
it("hello", {
timeout: 1010
}, () => {});
it("hello", {
before() {}
}, () => {});
it("hello", {
before: ["hello", () => {}]
}, () => {});
it("hello", {
after() {}
}, () => {});
it("hello", {
after: ["hello", () => {}]
}, () => {});
specify("hello", {
after: ["hello", () => {}]
}, () => {});
}
namespace beforeTests {
before(function() {
this.timeout(100);
this.a;
});
before("description", function () {
this.timeout(100);
this.a;
});
before("description", function (done) {
this.timeout(100);
done();
this.a;
});
}
namespace afterTests {
after(function () {
this.timeout(10);
this.a;
});
after("description", function () {
this.timeout(10);
this.a;
});
after("description", function (done) {
this.timeout(10);
this.a;
});
}
namespace beforeEachTests {
beforeEach(function () {
this.timeout(100);
this.a;
});
beforeEach("hello", function () {
this.timeout(100);
this.a;
});
beforeEach("hello", function (done) {
this.timeout(100);
done();
this.a;
});
}
namespace afterEachTests {
afterEach(function () {
this.timeout(100);
this.a;
});
afterEach("asd", function () {
this.timeout(100);
this.a;
});
afterEach("asd", function (done) {
this.timeout(100);
done();
this.a;
});
}
expect(1).to.be.a("number");
assert.equal(1, 1);
fakeClock.install().tick(100);
stub()(1, 2, 3);
expect(spy()).to.have.been.calledOnce;
match(2).and(match(2));
mock().alwaysCalledOn({});
request({}).expectBody("");
}

View File

@@ -0,0 +1,544 @@
namespace shaniTests {
const { shani } = adone;
namespace engineOptionsTests {
new shani.Engine();
new shani.Engine({});
new shani.Engine({ callGc: true });
new shani.Engine({ defaultTimeout: 1000 });
new shani.Engine({ defaultHookTimeout: 1000 });
new shani.Engine({ transpilerOptions: {} });
}
namespace contextTests {
const e = new adone.shani.Engine();
const c = e.context();
namespace describeTests {
c.describe("hello", () => {});
c.describe("hello", function () {
this.skip();
this.timeout(10);
this.a;
});
c.describe("1", "2", "3", "4", "45", function () {
this.skip();
this.timeout(10);
this.a;
});
c.describe("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", function () {
this.skip();
this.timeout(10);
this.a;
});
c.context("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", function () {
this.skip();
this.timeout(10);
this.a;
});
}
namespace itTests {
c.it("should be here", () => {});
c.it("should be here", function () {
this.timeout(100);
this.skip();
this.a;
});
c.it("should be here", function (done) {
this.timeout(100);
this.skip();
done();
this.a;
});
c.it("hello", {}, () => { });
c.it("hello", {
skip: true
}, () => { });
c.it("hello", {
skip: () => true
}, () => { });
c.it("hello", {
timeout: () => 1202
}, () => { });
c.it("hello", {
timeout: 1010
}, () => { });
c.it("hello", {
before() { }
}, () => { });
c.it("hello", {
before: ["hello", () => { }]
}, () => { });
c.it("hello", {
after() { }
}, () => { });
c.it("hello", {
after: ["hello", () => { }]
}, () => { });
c.specify("hello", {
after: ["hello", () => { }]
}, () => { });
}
namespace beforeTests {
c.before(function () {
this.timeout(100);
this.a;
});
c.before("description", function () {
this.timeout(100);
this.a;
});
c.before("description", function (done) {
this.timeout(100);
done();
this.a;
});
}
namespace afterTests {
c.after(function () {
this.timeout(10);
this.a;
});
c.after("description", function () {
this.timeout(10);
this.a;
});
c.after("description", function (done) {
this.timeout(10);
done();
this.a;
});
}
namespace beforeEachTests {
c.beforeEach(function () {
this.timeout(100);
this.a;
});
c.beforeEach("hello", function () {
this.timeout(100);
this.a;
});
c.beforeEach("hello", function (done) {
this.timeout(100);
done();
this.a;
});
}
namespace afterEachTests {
c.afterEach(function () {
this.timeout(100);
this.a;
});
c.afterEach("asd", function () {
this.timeout(100);
this.a;
});
c.afterEach("asd", function (done) {
this.timeout(100);
done();
this.a;
});
}
namespace rootTests {
const { root } = c;
root.children[0];
root.prepare().then((x) => { });
root.addChild(root);
const check = (hook: adone.shani.I.Hook) => {
hook.run().then((x) => x);
hook.cause();
hook.failed() === true;
hook.timeout() + 2;
hook.timeout(10).timeout(10).timeout() + 2;
};
for (const hook of root.beforeHooks()) {
check(hook);
}
for (const hook of root.afterHooks()) {
check(hook);
}
for (const hook of root.beforeEachHooks()) {
check(hook);
}
for (const hook of root.afterEachHooks()) {
check(hook);
}
root.isInclusive() === true;
root.isExclusive() === false;
root.hasInclusive() === true;
root.skip().only().skip();
const a: number | null = root.timeout();
root.timeout(100).timeout(100);
root.level() + 2;
root.level(2).level() + 2;
root.chain().toLowerCase();
root.blockChain()[0].blockChain()[0].addChild(root);
}
namespace eventEmitterTests {
const a = c.start();
a.on("enter block", ({ block }) => {
block.addChild(block);
}).on("exit block", ({ block }) => {
block.addChild(block);
}).on("start test", ({ block, test }) => {
block.addChild(test);
test.chain();
}).on("end test", ({ block, test, meta }) => {
block.addChild(test);
test.chain();
meta.err;
meta.elapsed + 2;
}).on("start before hook", ({ block, hook }) => {
block.addChild(block);
hook.desctiption;
}).on("end before hook", ({ block, hook, meta }) => {
block.addChild(block);
hook.desctiption;
meta.err;
meta.elapsed;
}).on("start after hook", ({ block, hook }) => {
block.addChild(block);
hook.desctiption;
}).on("end after hook", ({ block, hook, meta }) => {
block.addChild(block);
hook.desctiption;
meta.err;
meta.elapsed;
}).on("start before each hook", ({ block, hook }) => {
block.addChild(block);
hook.desctiption;
}).on("end before each hook", ({ block, hook, meta }) => {
block.addChild(block);
hook.desctiption;
meta.err;
meta.elapsed;
}).on("start after each hook", ({ block, hook }) => {
block.addChild(block);
hook.desctiption;
}).on("end after each hook", ({ block, hook, meta }) => {
block.addChild(block);
hook.desctiption;
meta.err;
meta.elapsed;
}).on("start before test hook", ({ block, hook }) => {
block.addChild(block);
hook.desctiption;
}).on("end before test hook", ({ block, hook, meta }) => {
block.addChild(block);
hook.desctiption;
meta.err;
meta.elapsed;
}).on("start after test hook", ({ block, hook }) => {
block.addChild(block);
hook.desctiption;
}).on("end after test hook", ({ block, hook, meta }) => {
block.addChild(block);
hook.desctiption;
meta.err;
meta.elapsed;
}).on("error", (err) => {}).on("done", () => {}).stop();
}
}
namespace utilTests {
const { util } = shani;
namespace spyCallTests {
const call = util.spy().firstCall;
call.calledBefore(call) === true;
call.calledAfter(call) === true;
call.calledWithNew(call) === true;
call.thisValue;
call.args[0];
call.exception;
call.returnValue;
call.calledOn({}) === true;
call.calledWith(1, 2, 3) === true;
call.calledWithExactly(1, 2, 3) === true;
call.calledWithMatch(1, 2, 3) === true;
call.notCalledWith(1, 2, 3) === true;
call.notCalledWithMatch(1, 2, 3) === true;
call.returned(1) === true;
call.threw() === true;
call.threw("12") === true;
call.threw({}) === true;
call.callArg(1);
call.callArgOn(1, {});
call.callArgWith(1, 1, 2, 3);
call.callArgOnWith(1, {}, 1, 2, 3);
call.yield(1, 2, 3);
call.yieldOn({}, 1, 2, 3);
call.yieldToOn("a", {}, 1, 2, 3);
}
namespace spyTests {
util.spy().alwaysCalledOn({});
util.spy(() => { }).alwaysCalledOn({});
const a: number = util.spy().callCount;
const s = util.spy();
s.called === true;
s.notCalled === true;
s.calledOnce === true;
s.calledTwice === true;
s.calledThrice === true;
s.firstCall.args;
s.secondCall.args;
s.thirdCall.args;
s.lastCall.args;
s.thisValues[0];
s.args[0][0];
s.exceptions[0];
s.returnValues[0];
s(1, 2, 3);
s.calledBefore(s);
s.calledAfter(s);
s.calledImmediatelyAfter(s);
s.calledImmediatelyBefore(s);
s.calledWithNew() === true;
s.withArgs(1, 2, 3).firstCall.args;
s.alwaysCalledOn({}) === true;
s.alwaysCalledWith(1, 2, 3) === true;
s.alwaysCalledWithExactly(1, 2, 3) === true;
s.alwaysCalledWithMatch(1, 2, 3) === true;
s.neverCalledWith(1, 2, 3) === true;
s.neverCalledWithMatch(1, 2, 3) === true;
s.alwaysThrew() === true;
s.alwaysThrew("a") === true;
s.alwaysThrew({}) === true;
s.alwaysReturned({}) === true;
s.invokeCallback(1, 2, 3);
s.getCall(0).args;
s.getCalls()[0].args;
s.reset();
s.printf("%s", "1").toLowerCase();
s.restore();
}
namespace stubTests {
util.stub({});
class A {
a() {}
}
util.stub(new A(), "a").resetHistory();
const s = util.stub();
s.resetBehavior();
s.resetHistory();
s.usingPromise({}).alwaysCalledOn(2);
s.returns({}).resetBehavior();
s.returnsArg(1).resetBehavior();
s.returnsThis().resetBehavior();
s.resolves().resetBehavior();
s.resolves(1).resetBehavior();
s.throws().resetBehavior();
s.throws("1").resetBehavior();
s.throwsArg(1).resetBehavior();
s.throwsException().resetBehavior();
s.throwsException("1").resetBehavior();
s.throwsException({}).resetBehavior();
s.rejects().resetBehavior();
s.rejects("string").resetBehavior();
s.rejects(1).resetBehavior();
s.callsArg(1).resetBehavior();
s.callThrough().resetBehavior();
s.callsArgOn(1, {}).resetBehavior();
s.callsArgOnWith(1, {}, 123).resetBehavior();
s.callsArgAsync(1).resetBehavior();
s.callsArgOnAsync(1, {}).resetBehavior();
s.callsArgOnWithAsync(1, {}, 1, 2, 3).resetBehavior();
s.callsFake(() => { }).resetBehavior();
s.get(() => { }).resetBehavior();
s.set((v) => 1).resetBehavior();
s.onCall(1).resetBehavior();
s.onFirstCall().resetBehavior();
s.onSecondCall().resetBehavior();
s.onThirdCall().resetBehavior();
s.value(1).resetBehavior();
s.yields(1, 2, 3).resetBehavior();
s.yieldsOn({}, 1, 2).resetBehavior();
s.yieldsRight(1, 2, 3).resetBehavior();
s.yieldsTo("a", 1, 2, 3).resetBehavior();
s.yieldsToOn("a", {}, 1, 2, 3).resetBehavior();
s.yieldsAsync(1, 2, 3).resetBehavior();
s.yieldsOnAsync({}, 1, 2, 3).resetBehavior();
s.yieldsToAsync("a", 1, 2, 3).resetBehavior();
s.yieldsToOnAsync("1", {}, 1, 2, 3).resetBehavior();
s.withArgs(1, 2, 3).resetBehavior();
}
namespace expectationTests {
util.expectation.create("");
const e = util.expectation.create();
e.atLeast(1).never();
e.atMost(2).never();
e.never().never();
e.once().never();
e.twice().never();
e.thrice().never();
e.exactly(1).never();
e.withArgs(1, 2, 3).never();
e.withExactArgs(1, 2, 3).never();
e.on({}).never();
e.verify().never();
e.restore();
}
namespace mockTests {
util.mock().never();
util.mock({}).expects("").restore();
util.mock({}).verify();
}
namespace assertTests {
util.assert.failException;
util.assert.fail();
util.assert.fail("1");
util.assert.pass(1);
const s = util.spy();
util.assert.notCalled(s);
util.assert.called(s);
util.assert.calledOnce(s);
util.assert.calledTwice(s);
util.assert.calledThrice(s);
util.assert.callCount(s, 10);
util.assert.callOrder(s, s, s, s);
util.assert.calledOn(s, {});
util.assert.calledOn(s, {});
util.assert.alwaysCalledOn(s, {});
util.assert.calledWith(s, {});
util.assert.neverCalledWith(s, {});
util.assert.calledWithExactly(s, {});
util.assert.alwaysCalledWithExactly(s, {});
util.assert.calledWithMatch(s, {});
util.assert.alwaysCalledWithMatch(s, {});
util.assert.neverCalledWithMatch(s, {});
util.assert.threw(s);
util.assert.threw(s, "a");
util.assert.threw(s, {});
util.assert.alwaysThrew(s);
util.assert.alwaysThrew(s, "");
util.assert.alwaysThrew(s, {});
util.assert.expose({});
util.assert.expose({}, { includeFail: true });
util.assert.expose({}, { prefix: "a" });
}
namespace matchTests {
util.match(1).and(util.match(1));
util.match("1").and(util.match(1));
util.match(/1/).and(util.match(1));
util.match({}).and(util.match(1));
util.match((v: any) => true).and(util.match(1));
util.match((v: any) => true, "a").and(util.match(1));
util.match.any.and;
util.match.defined.and;
util.match.truthy.and;
util.match.falsy.and;
util.match.bool.and;
util.match.number.and;
util.match.string.and;
util.match.object.and;
util.match.func.and;
util.match.map.contains(new Map());
util.match.map.deepEquals(new Map());
util.match.set.contains(new Set());
util.match.array.contains([]);
util.match.array.deepEquals([]);
util.match.array.endsWith([]);
util.match.array.startsWith([]);
util.match.regexp.and;
util.match.date.and;
util.match.symbol.and;
util.match.same({}).and;
util.match.typeOf("string").and;
util.match.instanceOf({}).and;
util.match.has("a").and;
util.match.has("a", {}).and;
util.match.hasOwn("a").and;
util.match.hasOwn("a", {}).and;
}
namespace sandboxTests {
util.sandbox.create();
util.sandbox.create({});
util.sandbox.create({ injectInto: {} });
util.sandbox.create({ properties: ["a"] });
const s = util.sandbox.create();
s.assert.alwaysCalledOn(s.spy(), {});
s.spy().args;
s.stub().args;
s.mock().args;
s.restore();
s.reset();
s.resetHistory();
s.resetBehavior();
s.usingPromise({}).reset();
s.verify();
s.verifyAndRestore();
}
}
namespace requestTests {
const r = request({});
r.get("/").head("/").post("/").put("/").options("/");
r.attach("fname", "hello");
r.attach("fname", "hello", {});
r.attach("fname", "hello", { type: "application/javascript" });
r.attach("fname", "hello", { filename: "a.js" });
r.field("a", "basd");
r.send("asd");
r.setHeader("Cookie", "key=value");
r.auth("user", "pass");
r.expect(() => true);
r.expect(async () => true);
r.expect((response) => {
assert.equal(response.statusCode, 200);
return response.body.length === 0;
});
r.expectStatus(200);
r.expectStatusMessage("OK");
r.expectBody("body");
r.expectBody(Buffer.from("body"));
r.expectBody(/body/);
r.expectBody({ a: 1 });
r.expectBody("body", {});
r.expectBody("body", { decompress: true });
r.expectEmptyBody();
r.expectHeader("Cookie", "key=value");
r.expectHeaderExists("Cookie");
r.then((x: adone.shani.util.I.Response) => {
x.statusCode === 200;
x.body.fill(0);
});
}
}

View File

@@ -580,6 +580,7 @@ namespace utilTests {
}
namespace install {
util.fakeClock.install();
util.fakeClock.install(100);
util.fakeClock.install(new Date());
util.fakeClock.install({});

View File

@@ -66,4 +66,6 @@ namespace AdoneRootTests {
{ const a: Buffer | string = adone.loadAsset("asset"); }
{ const a: object = adone.require("path"); }
{ const a: object = adone.package; }
{ const a: typeof adone.assertion.assert = adone.assert; }
{ const a: typeof adone.assertion.expect = adone.expect; }
}

View File

@@ -23,12 +23,20 @@
"glosses/math.d.ts",
"glosses/std.d.ts",
"glosses/utils.d.ts",
"glosses/assertion.d.ts",
"glosses/promise.d.ts",
"glosses/shani.d.ts",
"glosses/shani-global.d.ts",
"adone-tests.ts",
"test/index.ts",
"test/index-import.ts",
"test/glosses/common.ts",
"test/glosses/math.ts",
"test/glosses/std.ts",
"test/glosses/utils.ts"
"test/glosses/utils.ts",
"test/glosses/assertion.ts",
"test/glosses/promise.ts",
"test/glosses/shani.ts",
"test/glosses/shani-global.ts"
]
}

View File

@@ -3,6 +3,8 @@
"rules": {
"no-namespace": false,
"strict-export-declare-modifiers": false,
"no-single-declare-module": false
"no-single-declare-module": false,
"unified-signatures": false,
"space-before-function-paren": false
}
}