New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

alsatian

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alsatian - npm Package Compare versions

Comparing version 1.0.0-alpha.16 to 1.0.0-alpha.17

.nyc_output/17241a5cda63c93df72c727f0272b939.json

3

cli/alsatian-cli-options.d.ts

@@ -6,7 +6,10 @@ export declare class AlsatianCliOptions {

readonly timeout: number;
private _tap;
readonly tap: boolean;
constructor(args: Array<string>);
private _extractFileGlobs(args);
private _extractTimeout(args);
private _extractTap(args);
private _getArgumentIndexFromArgumentList(args, argumentName, argumentShorthand?);
private _getArgumentValueFromArgumentList(args, argumentName, argumentShorthand?);
}

@@ -9,4 +9,6 @@ "use strict";

this._timeout = null;
this._tap = false;
args = this._extractFileGlobs(args);
args = this._extractTimeout(args);
args = this._extractTap(args);
if (args.length > 0) {

@@ -30,2 +32,9 @@ throw new invalid_argument_names_error_1.InvalidArgumentNamesError(args);

});
Object.defineProperty(AlsatianCliOptions.prototype, "tap", {
get: function () {
return this._tap;
},
enumerable: true,
configurable: true
});
AlsatianCliOptions.prototype._extractFileGlobs = function (args) {

@@ -51,2 +60,3 @@ var _this = this;

var argumentIndex_1 = this._getArgumentIndexFromArgumentList(args, "timeout", "t");
// filter out the timeout argument and its value
return args.filter(function (value, index) {

@@ -58,2 +68,11 @@ return index !== argumentIndex_1 && index !== argumentIndex_1 + 1;

};
AlsatianCliOptions.prototype._extractTap = function (args) {
var argumentIndex = this._getArgumentIndexFromArgumentList(args, "tap", "T");
// if we found the tap argument, we want to enable tap output
this._tap = (argumentIndex !== -1);
// filter out the tap argument and return the other args
return args.filter(function (value, index) {
return index !== argumentIndex;
});
};
AlsatianCliOptions.prototype._getArgumentIndexFromArgumentList = function (args, argumentName, argumentShorthand) {

@@ -60,0 +79,0 @@ var matchingArguments = args.filter(function (value, index) { return value === "--" + argumentName || value === "-" + argumentShorthand; });

@@ -18,2 +18,7 @@ import { InvalidArgumentNamesError } from "./errors/invalid-argument-names-error";

private _tap: boolean = false;
public get tap(): boolean {
return this._tap;
}
public constructor(args: Array<string>) {

@@ -23,2 +28,3 @@

args = this._extractTimeout(args);
args = this._extractTap(args);

@@ -59,2 +65,3 @@ if (args.length > 0) {

// filter out the timeout argument and its value
return args.filter((value, index) => {

@@ -68,2 +75,14 @@ return index !== argumentIndex && index !== argumentIndex + 1;

private _extractTap(args: Array<string>): Array<string> {
const argumentIndex = this._getArgumentIndexFromArgumentList(args, "tap", "T");
// if we found the tap argument, we want to enable tap output
this._tap = (argumentIndex !== -1);
// filter out the tap argument and return the other args
return args.filter((value, index) => {
return index !== argumentIndex;
});
}
private _getArgumentIndexFromArgumentList(args: Array<string>, argumentName: string, argumentShorthand?: string): number {

@@ -70,0 +89,0 @@

@@ -6,2 +6,3 @@ #! /usr/bin/env node

var alsatian_cli_options_1 = require("./alsatian-cli-options");
var TapBark = require("tap-bark").TapBark;
// get all arguments from the user

@@ -12,4 +13,15 @@ var userArguments = new alsatian_cli_options_1.AlsatianCliOptions(process.argv.slice(2));

testSet.addTestsFromFiles(userArguments.fileGlobs);
var outputStream = new alsatian_core_1.TestOutputStream();
if (userArguments.tap) {
// if they want TAP output then just write to stdout directly
outputStream.pipe(process.stdout);
}
else {
// otherwise create the tap bark reporter
var bark = TapBark.create();
// pipe the reporter into stdout
outputStream.pipe(bark.getPipeable()).pipe(process.stdout);
}
// create alsatian test runner
var testRunner = new alsatian_core_1.TestRunner();
var testRunner = new alsatian_core_1.TestRunner(outputStream);
// run the test set

@@ -16,0 +28,0 @@ var cliTestRunner = new cli_test_runner_1.CliTestRunner(testRunner);

#! /usr/bin/env node
import { createTestSet, TestRunner } from "../core/alsatian-core";
import { createTestSet, TestRunner, TestOutputStream } from "../core/alsatian-core";
import { CliTestRunner } from "./cli-test-runner";
import { AlsatianCliOptions } from "./alsatian-cli-options";
import { Writable, Readable } from "stream";
const {
TapBark
} = require("tap-bark");
// get all arguments from the user

@@ -14,4 +19,18 @@ let userArguments = new AlsatianCliOptions(process.argv.slice(2));

let outputStream = new TestOutputStream();
if (userArguments.tap) {
// if they want TAP output then just write to stdout directly
outputStream.pipe(process.stdout);
}
else {
// otherwise create the tap bark reporter
const bark = TapBark.create();
// pipe the reporter into stdout
outputStream.pipe(bark.getPipeable()).pipe(process.stdout);
}
// create alsatian test runner
let testRunner = new TestRunner();
let testRunner = new TestRunner(outputStream);

@@ -18,0 +37,0 @@ // run the test set

11

cli/cli-test-runner.js
"use strict";
var alsatian_core_1 = require("../core/alsatian-core");
var CliTestRunner = (function () {

@@ -13,11 +12,3 @@ function CliTestRunner(_testRunner) {

var testRunPromise = this._testRunner.run(testSet, timeout);
testRunPromise.then(function (results) {
if (results.outcome === alsatian_core_1.TestOutcome.Error || results.outcome === alsatian_core_1.TestOutcome.Fail) {
process.exit(1);
}
else {
process.exit(0);
}
})
.catch(this._handleTestSetRunError);
testRunPromise.catch(this._handleTestSetRunError);
}

@@ -24,0 +15,0 @@ catch (error) {

@@ -16,11 +16,3 @@ import { TestRunner, TestSet, TestSetResults, TestOutcome } from "../core/alsatian-core";

testRunPromise.then((results: TestSetResults) => {
if (results.outcome === TestOutcome.Error || results.outcome === TestOutcome.Fail) {
process.exit(1);
}
else {
process.exit(0);
}
})
.catch(this._handleTestSetRunError);
testRunPromise.catch(this._handleTestSetRunError);
}

@@ -27,0 +19,0 @@ catch (error) {

@@ -8,3 +8,3 @@ import { Expect } from "./expect";

import { TestFixture } from "./test-fixture";
import { TestOutput } from "./test-output";
export { createTestSet, Expect, TestSet, TestLoader, FileRequirer, GlobHelper, TestFixture, TestOutput };
import { TestOutputStream } from "./test-output-stream";
export { createTestSet, Expect, TestSet, TestLoader, FileRequirer, GlobHelper, TestFixture, TestOutputStream };

@@ -16,4 +16,4 @@ "use strict";

exports.TestFixture = test_fixture_1.TestFixture;
var test_output_1 = require("./test-output");
exports.TestOutput = test_output_1.TestOutput;
var test_output_stream_1 = require("./test-output-stream");
exports.TestOutputStream = test_output_stream_1.TestOutputStream;
//# sourceMappingURL=_core.js.map

@@ -8,3 +8,3 @@ import { Expect } from "./expect";

import { TestFixture } from "./test-fixture";
import { TestOutput } from "./test-output";
import { TestOutputStream } from "./test-output-stream";

@@ -19,3 +19,3 @@ export {

TestFixture,
TestOutput
TestOutputStream
};

@@ -1,2 +0,2 @@

import { createTestSet, Expect, TestSet, TestFixture, TestOutput } from "./_core";
import { createTestSet, Expect, TestSet, TestFixture, TestOutputStream } from "./_core";
import { AsyncTest, FocusTest, FocusTests, IgnoreTest, IgnoreTests, Setup, Teardown, Test, TestCase, Timeout } from "./_decorators";

@@ -8,2 +8,2 @@ import { FunctionSpy, SpyOn, SpyOnProperty } from "./_spying";

import { TestRunner } from "./_running";
export { AsyncTest, createTestSet, Expect, FocusTest, FocusTests, IgnoreTest, IgnoreTests, Setup, FunctionSpy, SpyOn, SpyOnProperty, Teardown, Test, TestCase, TestRunner, TestSet, Timeout, TestSetResults, TestOutcome, METADATA_KEYS, TestFixture, TestOutput, MatchError, TestFixtureResults, TestResults, TestCaseResult, TestTimeoutError };
export { AsyncTest, createTestSet, Expect, FocusTest, FocusTests, IgnoreTest, IgnoreTests, Setup, FunctionSpy, SpyOn, SpyOnProperty, Teardown, Test, TestCase, TestRunner, TestSet, Timeout, TestSetResults, TestOutcome, METADATA_KEYS, TestFixture, TestOutputStream, MatchError, TestFixtureResults, TestResults, TestCaseResult, TestTimeoutError };

@@ -7,3 +7,3 @@ "use strict";

exports.TestFixture = _core_1.TestFixture;
exports.TestOutput = _core_1.TestOutput;
exports.TestOutputStream = _core_1.TestOutputStream;
var _decorators_1 = require("./_decorators");

@@ -10,0 +10,0 @@ exports.AsyncTest = _decorators_1.AsyncTest;

@@ -6,3 +6,3 @@ import {

TestFixture,
TestOutput
TestOutputStream
} from "./_core";

@@ -70,3 +70,3 @@

TestFixture,
TestOutput,
TestOutputStream,
MatchError,

@@ -73,0 +73,0 @@ TestFixtureResults,

@@ -5,5 +5,5 @@ import { MatchError } from "../_errors";

public constructor(actualValue: any, expectedContent: any, shouldMatch: boolean) {
super(actualValue, expectedContent, `Expected ${JSON.stringify(actualValue)} ${!shouldMatch ? "not " : ""}to contain ${JSON.stringify(expectedContent)}.`);
}
public constructor(actualValue: any, expectedContent: any, shouldMatch: boolean) {
super(actualValue, expectedContent, `Expected ${JSON.stringify(actualValue)} ${!shouldMatch ? "not " : ""}to contain ${JSON.stringify(expectedContent)}.`);
}
}

@@ -5,2 +5,3 @@ /// <reference types="node" />

constructor(actualError: Error, shouldMatch: boolean, expectedErrorType?: new (...args: Array<any>) => Error, expectedErrorMessage?: string);
private _setErrorMessage(actualError, shouldMatch, expectedErrorType?, expectedErrorMessage?);
private _setWrongSpecificErrorMessage(actualError, shouldMatch, expectedErrorType?, expectedErrorMessage?);

@@ -7,0 +8,0 @@ private _setWrongMessageMessage(shouldMatch, expectedErrorMessage?);

@@ -11,3 +11,6 @@ "use strict";

function ErrorMatchError(actualError, shouldMatch, expectedErrorType, expectedErrorMessage) {
_super.call(this, actualError, expectedErrorMessage, "");
_super.call(this, (actualError ? actualError.constructor.name + " " : "") + "error was " + (!actualError ? "not " : "") + "thrown" + (actualError ? " with message \"" + actualError.message + "\"" : "") + ".", (expectedErrorType ? expectedErrorType.name + " " : "") + "error " + (!shouldMatch ? "not " : "") + "to be thrown" + (expectedErrorMessage ? " with message \"" + expectedErrorMessage + "\"" : "") + ".", "");
this._setErrorMessage(actualError, shouldMatch, expectedErrorType, expectedErrorMessage);
}
ErrorMatchError.prototype._setErrorMessage = function (actualError, shouldMatch, expectedErrorType, expectedErrorMessage) {
if (expectedErrorType || expectedErrorMessage) {

@@ -24,3 +27,3 @@ this._setWrongSpecificErrorMessage(actualError, shouldMatch, expectedErrorType, expectedErrorMessage);

}
}
};
ErrorMatchError.prototype._setWrongSpecificErrorMessage = function (actualError, shouldMatch, expectedErrorType, expectedErrorMessage) {

@@ -27,0 +30,0 @@ if (!expectedErrorType || (expectedErrorMessage && actualError instanceof expectedErrorType && expectedErrorMessage !== actualError.message)) {

@@ -6,4 +6,10 @@ import { MatchError } from "../_errors";

public constructor(actualError: Error, shouldMatch: boolean, expectedErrorType?: new (...args: Array<any>) => Error, expectedErrorMessage?: string) {
super(actualError, expectedErrorMessage, "");
super(`${actualError ? (<any>actualError.constructor).name + " " : ""}error was ${!actualError ? "not " : ""}thrown${actualError ? " with message \"" + actualError.message + "\"" : ""}.`,
`${expectedErrorType ? (<any>expectedErrorType).name + " " : ""}error ${!shouldMatch ? "not " : ""}to be thrown${expectedErrorMessage ? " with message \"" + expectedErrorMessage + "\"" : ""}.`,
"");
this._setErrorMessage(actualError, shouldMatch, expectedErrorType, expectedErrorMessage);
}
private _setErrorMessage(actualError: Error, shouldMatch: boolean, expectedErrorType?: new (...args: Array<any>) => Error, expectedErrorMessage?: string) {
if (expectedErrorType || expectedErrorMessage) {

@@ -10,0 +16,0 @@ this._setWrongSpecificErrorMessage(actualError, shouldMatch, expectedErrorType, expectedErrorMessage);

import { MatchError } from "../_errors";
import { FunctionSpy } from "../_spying";
export declare class FunctionCallMatchError extends MatchError {
constructor(actualValue: any, shouldMatch: boolean, args?: Array<any>);
constructor(actualValue: FunctionSpy, shouldMatch: boolean, args?: Array<any>);
}

@@ -11,3 +11,3 @@ "use strict";

function FunctionCallMatchError(actualValue, shouldMatch, args) {
_super.call(this, actualValue, "function to be called", "Expected function " + (!shouldMatch ? "not " : "") + "to be called" + (args ? " with [" + args.map(function (arg) { return JSON.stringify(arg); }).join(", ") + "]" : "") + ".");
_super.call(this, "function was " + (shouldMatch && !(args && actualValue.calls.length) ? "not " : "") + "called" + (args && actualValue.calls.length ? " with " + actualValue.calls.map(function (call) { return JSON.stringify(call.args); }).join(", ") : "") + ".", "function " + (!shouldMatch ? "not " : "") + "to be called" + (args ? " with " + JSON.stringify(args) : "") + ".", "Expected function " + (!shouldMatch ? "not " : "") + "to be called" + (args ? " with [" + args.map(function (arg) { return JSON.stringify(arg); }).join(", ") + "]" : "") + ".");
}

@@ -14,0 +14,0 @@ return FunctionCallMatchError;

import { MatchError } from "../_errors";
import { FunctionSpy } from "../_spying";
export class FunctionCallMatchError extends MatchError {
public constructor(actualValue: any, shouldMatch: boolean, args?: Array<any>) {
super(actualValue, "function to be called", `Expected function ${!shouldMatch ? "not " : ""}to be called${args ? " with [" + args.map(arg => JSON.stringify(arg)).join(", ") + "]" : ""}.`);
public constructor(actualValue: FunctionSpy, shouldMatch: boolean, args?: Array<any>) {
super(`function was ${shouldMatch && !(args && actualValue.calls.length) ? "not " : ""}called${args && actualValue.calls.length ? " with " + actualValue.calls.map(call => JSON.stringify(call.args)).join(", ") : ""}.`,
`function ${!shouldMatch ? "not " : ""}to be called${args ? " with " + JSON.stringify(args) : ""}.`,
`Expected function ${!shouldMatch ? "not " : ""}to be called${args ? " with [" + args.map(arg => JSON.stringify(arg)).join(", ") + "]" : ""}.`);
}
}

@@ -11,3 +11,3 @@ "use strict";

function GreaterThanMatchError(actualValue, lowerLimit, shouldMatch) {
_super.call(this, actualValue, lowerLimit, "Expected " + actualValue + " " + (!shouldMatch ? "not " : "") + "to be greater than " + lowerLimit + ".");
_super.call(this, actualValue, "a number " + (shouldMatch ? "" : "not ") + "greater than " + lowerLimit, "Expected " + actualValue + " " + (!shouldMatch ? "not " : "") + "to be greater than " + lowerLimit + ".");
}

@@ -14,0 +14,0 @@ return GreaterThanMatchError;

@@ -5,5 +5,5 @@ import { MatchError } from "../_errors";

public constructor(actualValue: number, lowerLimit: number, shouldMatch: boolean) {
super(actualValue, lowerLimit, `Expected ${actualValue} ${!shouldMatch ? "not " : ""}to be greater than ${lowerLimit}.`);
}
public constructor(actualValue: number, lowerLimit: number, shouldMatch: boolean) {
super(actualValue, `a number ${shouldMatch ? "" : "not "}greater than ${lowerLimit}`, `Expected ${actualValue} ${!shouldMatch ? "not " : ""}to be greater than ${lowerLimit}.`);
}
}

@@ -11,3 +11,3 @@ "use strict";

function LessThanMatchError(actualValue, upperLimit, shouldMatch) {
_super.call(this, actualValue, upperLimit, "Expected " + actualValue + " " + (!shouldMatch ? "not " : "") + "to be less than " + upperLimit + ".");
_super.call(this, actualValue, "a number " + (shouldMatch ? "" : "not ") + "less than " + upperLimit, "Expected " + actualValue + " " + (!shouldMatch ? "not " : "") + "to be less than " + upperLimit + ".");
}

@@ -14,0 +14,0 @@ return LessThanMatchError;

@@ -5,5 +5,5 @@ import { MatchError } from "../_errors";

public constructor(actualValue: number, upperLimit: number, shouldMatch: boolean) {
super(actualValue, upperLimit, `Expected ${actualValue} ${!shouldMatch ? "not " : ""}to be less than ${upperLimit}.`);
}
public constructor(actualValue: number, upperLimit: number, shouldMatch: boolean) {
super(actualValue, `a number ${shouldMatch ? "" : "not "}less than ${upperLimit}`, `Expected ${actualValue} ${!shouldMatch ? "not " : ""}to be less than ${upperLimit}.`);
}
}

@@ -11,3 +11,3 @@ "use strict";

function PropertySetMatchError(actualValue, shouldMatch, value) {
_super.call(this, actualValue, "property to be set", "Expected property " + (!shouldMatch ? "not " : "") + "to be set" + (arguments.length === 3 ? " to " + JSON.stringify(value) + "" : "") + ".");
_super.call(this, "property was " + (shouldMatch && !(arguments.length === 3 && actualValue.setCalls.length) ? "not " : "") + "set" + (arguments.length === 3 && actualValue.setCalls.length ? " to " + actualValue.setCalls.map(function (call) { return JSON.stringify(call.args[0]); }).join(", ") : "") + ".", "property " + (!shouldMatch ? "not " : "") + "to be set" + (arguments.length === 3 ? " to " + JSON.stringify(value) : "") + ".", "Expected property " + (!shouldMatch ? "not " : "") + "to be set" + (arguments.length === 3 ? " to " + JSON.stringify(value) + "" : "") + ".");
}

@@ -14,0 +14,0 @@ return PropertySetMatchError;

@@ -6,4 +6,7 @@ import { MatchError } from "../_errors";

public constructor(actualValue: any, shouldMatch: boolean, value?: any) {
super(actualValue, "property to be set", `Expected property ${!shouldMatch ? "not " : ""}to be set${arguments.length === 3 ? " to " + JSON.stringify(value) + "" : ""}.`);
super(`property was ${shouldMatch && !(arguments.length === 3 && actualValue.setCalls.length) ? "not " : ""}set${arguments.length === 3 && actualValue.setCalls.length ? " to " + actualValue.setCalls.map((call: any) => JSON.stringify(call.args[0])).join(", ") : ""}.`,
`property ${!shouldMatch ? "not " : ""}to be set${arguments.length === 3 ? " to " + JSON.stringify(value) : ""}.`,
`Expected property ${!shouldMatch ? "not " : ""}to be set${arguments.length === 3 ? " to " + JSON.stringify(value) + "" : ""}.`);
}
}

@@ -11,3 +11,3 @@ "use strict";

function TruthyMatchError(actualValue, shouldMatch) {
_super.call(this, actualValue, true, "Expected " + JSON.stringify(actualValue) + " " + (!shouldMatch ? "not " : "") + "to be truthy.");
_super.call(this, actualValue, "" + (shouldMatch ? "truthy" : "falsy"), "Expected " + JSON.stringify(actualValue) + " " + (!shouldMatch ? "not " : "") + "to be truthy.");
}

@@ -14,0 +14,0 @@ return TruthyMatchError;

@@ -6,4 +6,4 @@ import { MatchError } from "../_errors";

public constructor(actualValue: any, shouldMatch: boolean) {
super(actualValue, true, `Expected ${JSON.stringify(actualValue)} ${!shouldMatch ? "not " : ""}to be truthy.`);
super(actualValue, `${shouldMatch ? "truthy" : "falsy"}`, `Expected ${JSON.stringify(actualValue)} ${!shouldMatch ? "not " : ""}to be truthy.`);
}
}
/// <reference types="node" />
/**
* Allows checking of test outcomes
* @param actualValue - the value or function under test
*/
* Allows checking of test outcomes
* @param actualValue - the value or function under test
*/
export declare function Expect(actualValue: any): Matcher;
/**
* Gives functionality to ensure the outcome of a test is as expected
*/
* Gives functionality to ensure the outcome of a test is as expected
*/
export declare class Matcher {

@@ -15,76 +15,77 @@ private _actualValue;

/**
* Any subsequent matcher function will be looking for the opposite criteria
*/
* Any subsequent matcher function will be looking for the opposite criteria
*/
readonly not: Matcher;
/**
* Checks that a value is identical to another
* @param expectedValue - the value that will be used to match
*/
* Checks that a value is identical to another
* @param expectedValue - the value that will be used to match
*/
toBe(expectedValue: any): void;
/**
* Checks that a value is equal to another (for objects the function will check for deep equality)
* @param expectedValue - the value that will be used to match
*/
* Checks that a value is equal to another (for objects the function will check for deep equality)
* @param expectedValue - the value that will be used to match
*/
toEqual(expectedValue: any): void;
private _checkObjectsAreDeepEqual(objectA, objectB);
/**
* Checks that a value conforms to a regular expression
* @param regex - the regular expression that the actual value should match
*/
* Checks that a value conforms to a regular expression
* @param regex - the regular expression that the actual value should match
*/
toMatch(regex: RegExp): void;
/**
* Checks that a value is not undefined
*/
* Checks that a value is not undefined
*/
toBeDefined(): void;
/**
* Checks that a value is null
*/
* Checks that a value is null
*/
toBeNull(): void;
/**
* Checks that a value is equivalent to boolean true
*/
* Checks that a value is equivalent to boolean true
*/
toBeTruthy(): void;
/**
* Checks that a string contains another string or an array contains a specific item
* @param expectedContent - the string or array item that the value should contain
*/
* Checks that a string contains another string or an array contains a specific item
* @param expectedContent - the string or array item that the value should contain
*/
toContain(expectedContent: any): void;
/**
* Checks that a number is less than a given limit
* @param upperLimit - the number that the number under test should be less than
*/
* Checks that a number is less than a given limit
* @param upperLimit - the number that the number under test should be less than
*/
toBeLessThan(upperLimit: number): void;
/**
* Checks that a number is greater than a given limit
* @param lowerLimit - the number that the number under test should be greater than
*/
* Checks that a number is greater than a given limit
* @param lowerLimit - the number that the number under test should be greater than
*/
toBeGreaterThan(lowerLimit: number): void;
/**
* Checks that a function throws an error when executed
*/
* Checks that a function throws an error when executed
*/
toThrow(): void;
/**
* Checks that a function throws a specific error
* @param errorType - the type of error that should be thrown
* @param errorMessage - the message that the error should have
*/
* Checks that a function throws a specific error
* @param errorType - the type of error that should be thrown
* @param errorMessage - the message that the error should have
*/
toThrowError(errorType: new (...args: Array<any>) => Error, errorMessage: string): void;
/**
* Checks that a spy has been called
*/
* Checks that a spy has been called
*/
toHaveBeenCalled(): void;
/**
* Checks that a spy has been called with the specified arguments
* @param args - a list of arguments that the spy should have been called with
*/
* Checks that a spy has been called with the specified arguments
* @param args - a list of arguments that the spy should have been called with
*/
toHaveBeenCalledWith(...args: Array<any>): void;
private _isFunctionSpyOrSpiedOnFunction(value);
/**
* Checks that a property spy has been set
*/
* Checks that a property spy has been set
*/
toHaveBeenSet(): void;
/**
* Checks that a property spy has been set to a specific value
* @param value - a value to which the property should be set to
*/
* Checks that a property spy has been set to a specific value
* @param value - a value to which the property should be set to
*/
toHaveBeenSetTo(value: any): void;
}
"use strict";
var _errors_1 = require("./_errors");
var _spying_1 = require("./_spying");
/**
* Allows checking of test outcomes
* @param actualValue - the value or function under test
*/
* Allows checking of test outcomes
* @param actualValue - the value or function under test
*/
function Expect(actualValue) {

@@ -12,4 +13,4 @@ return new Matcher(actualValue);

/**
* Gives functionality to ensure the outcome of a test is as expected
*/
* Gives functionality to ensure the outcome of a test is as expected
*/
var Matcher = (function () {

@@ -22,4 +23,4 @@ function Matcher(actualValue) {

/**
* Any subsequent matcher function will be looking for the opposite criteria
*/
* Any subsequent matcher function will be looking for the opposite criteria
*/
get: function () {

@@ -33,5 +34,5 @@ this._shouldMatch = !this._shouldMatch;

/**
* Checks that a value is identical to another
* @param expectedValue - the value that will be used to match
*/
* Checks that a value is identical to another
* @param expectedValue - the value that will be used to match
*/
Matcher.prototype.toBe = function (expectedValue) {

@@ -43,5 +44,5 @@ if (expectedValue !== this._actualValue === this._shouldMatch) {

/**
* Checks that a value is equal to another (for objects the function will check for deep equality)
* @param expectedValue - the value that will be used to match
*/
* Checks that a value is equal to another (for objects the function will check for deep equality)
* @param expectedValue - the value that will be used to match
*/
Matcher.prototype.toEqual = function (expectedValue) {

@@ -83,6 +84,12 @@ // exclude the double equals in this case from review as this is what we want to do

/**
* Checks that a value conforms to a regular expression
* @param regex - the regular expression that the actual value should match
*/
* Checks that a value conforms to a regular expression
* @param regex - the regular expression that the actual value should match
*/
Matcher.prototype.toMatch = function (regex) {
if (regex === null || regex === undefined) {
throw new TypeError("toMatch regular expression must not be null or undefined.");
}
if (typeof this._actualValue !== "string") {
throw new TypeError("toMatch must only be used to match on strings.");
}
if (!regex.test(this._actualValue) === this._shouldMatch) {

@@ -93,4 +100,4 @@ throw new _errors_1.RegexMatchError(this._actualValue, regex, this._shouldMatch);

/**
* Checks that a value is not undefined
*/
* Checks that a value is not undefined
*/
Matcher.prototype.toBeDefined = function () {

@@ -102,4 +109,4 @@ if (this._actualValue === undefined === this._shouldMatch) {

/**
* Checks that a value is null
*/
* Checks that a value is null
*/
Matcher.prototype.toBeNull = function () {

@@ -111,4 +118,4 @@ if (this._actualValue !== null === this._shouldMatch) {

/**
* Checks that a value is equivalent to boolean true
*/
* Checks that a value is equivalent to boolean true
*/
Matcher.prototype.toBeTruthy = function () {

@@ -120,6 +127,12 @@ if ((this._actualValue && !this._shouldMatch) || (!this._actualValue && this._shouldMatch)) {

/**
* Checks that a string contains another string or an array contains a specific item
* @param expectedContent - the string or array item that the value should contain
*/
* Checks that a string contains another string or an array contains a specific item
* @param expectedContent - the string or array item that the value should contain
*/
Matcher.prototype.toContain = function (expectedContent) {
if (this._actualValue instanceof Array === false && typeof this._actualValue !== "string") {
throw new TypeError("toContain must only be used to check whether strings or arrays contain given contents.");
}
if (typeof this._actualValue === "string" && typeof expectedContent !== "string") {
throw new TypeError("toContain cannot check whether a string contains a non string value.");
}
if (this._actualValue.indexOf(expectedContent) === -1 === this._shouldMatch) {

@@ -130,6 +143,12 @@ throw new _errors_1.ContentsMatchError(this._actualValue, expectedContent, this._shouldMatch);

/**
* Checks that a number is less than a given limit
* @param upperLimit - the number that the number under test should be less than
*/
* Checks that a number is less than a given limit
* @param upperLimit - the number that the number under test should be less than
*/
Matcher.prototype.toBeLessThan = function (upperLimit) {
if (upperLimit === null || upperLimit === undefined) {
throw new TypeError("toBeLessThan upper limit must not be null or undefined.");
}
if (typeof this._actualValue !== "number") {
throw new TypeError("toBeLessThan can only check numbers.");
}
if (this._actualValue < upperLimit !== this._shouldMatch) {

@@ -140,6 +159,12 @@ throw new _errors_1.LessThanMatchError(this._actualValue, upperLimit, this._shouldMatch);

/**
* Checks that a number is greater than a given limit
* @param lowerLimit - the number that the number under test should be greater than
*/
* Checks that a number is greater than a given limit
* @param lowerLimit - the number that the number under test should be greater than
*/
Matcher.prototype.toBeGreaterThan = function (lowerLimit) {
if (lowerLimit === null || lowerLimit === undefined) {
throw new TypeError("toBeGreaterThan lower limit must not be null or undefined.");
}
if (typeof this._actualValue !== "number") {
throw new TypeError("toBeGreaterThan can only check numbers.");
}
if (this._actualValue > lowerLimit !== this._shouldMatch) {

@@ -150,5 +175,8 @@ throw new _errors_1.GreaterThanMatchError(this._actualValue, lowerLimit, this._shouldMatch);

/**
* Checks that a function throws an error when executed
*/
* Checks that a function throws an error when executed
*/
Matcher.prototype.toThrow = function () {
if (this._actualValue instanceof Function === false) {
throw new TypeError("toThrow requires value passed in to Expect to be a function.");
}
var errorThrown;

@@ -159,17 +187,17 @@ try {

catch (error) {
if (!this._shouldMatch) {
throw new _errors_1.ErrorMatchError(error, this._shouldMatch);
}
errorThrown = error;
}
if (this._shouldMatch && errorThrown === undefined) {
throw new _errors_1.ErrorMatchError(undefined, this._shouldMatch);
if (errorThrown === undefined === this._shouldMatch) {
throw new _errors_1.ErrorMatchError(errorThrown, this._shouldMatch);
}
};
/**
* Checks that a function throws a specific error
* @param errorType - the type of error that should be thrown
* @param errorMessage - the message that the error should have
*/
* Checks that a function throws a specific error
* @param errorType - the type of error that should be thrown
* @param errorMessage - the message that the error should have
*/
Matcher.prototype.toThrowError = function (errorType, errorMessage) {
if (this._actualValue instanceof Function === false) {
throw new TypeError("toThrowError requires value passed in to Expect to be a function.");
}
var threwRightError = false;

@@ -186,3 +214,3 @@ var actualError;

}
if (!threwRightError === this._shouldMatch) {
if (threwRightError !== this._shouldMatch) {
throw new _errors_1.ErrorMatchError(actualError, this._shouldMatch, errorType, errorMessage);

@@ -192,5 +220,8 @@ }

/**
* Checks that a spy has been called
*/
* Checks that a spy has been called
*/
Matcher.prototype.toHaveBeenCalled = function () {
if (this._isFunctionSpyOrSpiedOnFunction(this._actualValue) === false) {
throw new TypeError("toHaveBeenCalled requires value passed in to Expect to be a FunctionSpy or a spied on function.");
}
if (this._actualValue.calls.length === 0 === this._shouldMatch) {

@@ -201,5 +232,5 @@ throw new _errors_1.FunctionCallMatchError(this._actualValue, this._shouldMatch);

/**
* Checks that a spy has been called with the specified arguments
* @param args - a list of arguments that the spy should have been called with
*/
* Checks that a spy has been called with the specified arguments
* @param args - a list of arguments that the spy should have been called with
*/
Matcher.prototype.toHaveBeenCalledWith = function () {

@@ -210,2 +241,5 @@ var args = [];

}
if (this._isFunctionSpyOrSpiedOnFunction(this._actualValue) === false) {
throw new TypeError("toHaveBeenCalledWith requires value passed in to Expect to be a FunctionSpy or a spied on function.");
}
if (this._actualValue.calls.filter(function (call) {

@@ -218,6 +252,12 @@ return call.args.filter(function (arg, index) { return arg === args[index]; }).length === args.length &&

};
Matcher.prototype._isFunctionSpyOrSpiedOnFunction = function (value) {
return value instanceof _spying_1.FunctionSpy || (value instanceof Function && value.calls !== undefined);
};
/**
* Checks that a property spy has been set
*/
* Checks that a property spy has been set
*/
Matcher.prototype.toHaveBeenSet = function () {
if (this._actualValue instanceof _spying_1.PropertySpy === false) {
throw new TypeError("toHaveBeenSet requires value passed in to Expect to be a PropertySpy.");
}
if (this._actualValue.setCalls.length === 0 === this._shouldMatch) {

@@ -228,6 +268,9 @@ throw new _errors_1.PropertySetMatchError(this._actualValue, this._shouldMatch);

/**
* Checks that a property spy has been set to a specific value
* @param value - a value to which the property should be set to
*/
* Checks that a property spy has been set to a specific value
* @param value - a value to which the property should be set to
*/
Matcher.prototype.toHaveBeenSetTo = function (value) {
if (this._actualValue instanceof _spying_1.PropertySpy === false) {
throw new TypeError("toHaveBeenSetTo requires value passed in to Expect to be a PropertySpy.");
}
if (this._actualValue.setCalls.filter(function (call) { return call.args[0] === value; }).length === 0 === this._shouldMatch) {

@@ -234,0 +277,0 @@ throw new _errors_1.PropertySetMatchError(this._actualValue, this._shouldMatch, value);

import {
MatchError,
ExactMatchError,
EqualMatchError,
RegexMatchError,
TruthyMatchError,
ContentsMatchError,
LessThanMatchError,
GreaterThanMatchError,
ErrorMatchError,
FunctionCallMatchError,
PropertySetMatchError
MatchError,
ExactMatchError,
EqualMatchError,
RegexMatchError,
TruthyMatchError,
ContentsMatchError,
LessThanMatchError,
GreaterThanMatchError,
ErrorMatchError,
FunctionCallMatchError,
PropertySetMatchError
} from "./_errors";
import {
FunctionSpy,
PropertySpy
} from "./_spying";
/**
* Allows checking of test outcomes
* @param actualValue - the value or function under test
*/
* Allows checking of test outcomes
* @param actualValue - the value or function under test
*/
export function Expect(actualValue: any) {
return new Matcher(actualValue);
return new Matcher(actualValue);
}
/**
* Gives functionality to ensure the outcome of a test is as expected
*/
* Gives functionality to ensure the outcome of a test is as expected
*/
export class Matcher {
private _actualValue: any;
private _shouldMatch: boolean = true;
private _actualValue: any;
private _shouldMatch: boolean = true;
public constructor(actualValue: any) {
this._actualValue = actualValue;
}
public constructor(actualValue: any) {
this._actualValue = actualValue;
}
/**
/**
* Any subsequent matcher function will be looking for the opposite criteria
*/
public get not(): Matcher {
this._shouldMatch = !this._shouldMatch;
return this;
}
public get not(): Matcher {
this._shouldMatch = !this._shouldMatch;
return this;
}
/**
/**
* Checks that a value is identical to another
* @param expectedValue - the value that will be used to match
*/
public toBe(expectedValue: any) {
if (expectedValue !== this._actualValue === this._shouldMatch) {
throw new ExactMatchError(this._actualValue, expectedValue, this._shouldMatch);
}
}
public toBe(expectedValue: any) {
if (expectedValue !== this._actualValue === this._shouldMatch) {
throw new ExactMatchError(this._actualValue, expectedValue, this._shouldMatch);
}
}
/**
/**
* Checks that a value is equal to another (for objects the function will check for deep equality)
* @param expectedValue - the value that will be used to match
*/
public toEqual(expectedValue: any) {
// exclude the double equals in this case from review as this is what we want to do
if (expectedValue != this._actualValue === this._shouldMatch) { // tslint:disable-line:triple-equals
public toEqual(expectedValue: any) {
// exclude the double equals in this case from review as this is what we want to do
if (expectedValue != this._actualValue === this._shouldMatch) { // tslint:disable-line:triple-equals
if (typeof expectedValue !== "object" || this._checkObjectsAreDeepEqual(expectedValue, this._actualValue) !== this._shouldMatch) {
throw new EqualMatchError(this._actualValue, expectedValue, this._shouldMatch);
if (typeof expectedValue !== "object" || this._checkObjectsAreDeepEqual(expectedValue, this._actualValue) !== this._shouldMatch) {
throw new EqualMatchError(this._actualValue, expectedValue, this._shouldMatch);
}
}
}
}
}
private _checkObjectsAreDeepEqual(objectA: any, objectB: any): boolean {
private _checkObjectsAreDeepEqual(objectA: any, objectB: any): boolean {
// if one object is an array and the other is not then they are not equal
if (Array.isArray(objectA) !== Array.isArray(objectB)) {
return false;
}
// if one object is an array and the other is not then they are not equal
if (Array.isArray(objectA) !== Array.isArray(objectB)) {
return false;
}
// get all the property keys for each object
let objectAKeys = Object.keys(objectA);
let objectBKeys = Object.keys(objectB);
// get all the property keys for each object
let objectAKeys = Object.keys(objectA);
let objectBKeys = Object.keys(objectB);
// if they don't have the same amount of properties then clearly not
if (objectAKeys.length !== objectBKeys.length) {
return false;
}
// if they don't have the same amount of properties then clearly not
if (objectAKeys.length !== objectBKeys.length) {
return false;
}
// check all the properties of each object
for (let i = 0; i < objectAKeys.length; i++) {
let objectAKey = objectAKeys[i];
// check all the properties of each object
for (let i = 0; i < objectAKeys.length; i++) {
let objectAKey = objectAKeys[i];
// if the property values are not the same
if (objectA[objectAKey] !== objectB[objectAKey]) {
// if the property values are not the same
if (objectA[objectAKey] !== objectB[objectAKey]) {
// and it's not an object or the objects are not equal
if (typeof(objectA[objectAKey]) !== "object" || this._checkObjectsAreDeepEqual(objectA[objectAKey], objectB[objectAKey]) === false) {
// then not deep equal
return false;
}
}
}
// and it's not an object or the objects are not equal
if (typeof(objectA[objectAKey]) !== "object" || this._checkObjectsAreDeepEqual(objectA[objectAKey], objectB[objectAKey]) === false) {
// then not deep equal
return false;
}
}
}
// all properties match so all is good
return true;
}
// all properties match so all is good
return true;
}
/**
/**
* Checks that a value conforms to a regular expression
* @param regex - the regular expression that the actual value should match
*/
public toMatch(regex: RegExp) {
if (!regex.test(this._actualValue) === this._shouldMatch) {
throw new RegexMatchError(this._actualValue, regex, this._shouldMatch);
}
}
public toMatch(regex: RegExp) {
if (regex === null || regex === undefined) {
throw new TypeError("toMatch regular expression must not be null or undefined.");
}
/**
if (typeof this._actualValue !== "string") {
throw new TypeError("toMatch must only be used to match on strings.");
}
if (!regex.test(this._actualValue) === this._shouldMatch) {
throw new RegexMatchError(this._actualValue, regex, this._shouldMatch);
}
}
/**
* Checks that a value is not undefined
*/
public toBeDefined() {
if (this._actualValue === undefined === this._shouldMatch) {
throw new ExactMatchError(this._actualValue, undefined, !this._shouldMatch);
}
}
public toBeDefined() {
if (this._actualValue === undefined === this._shouldMatch) {
throw new ExactMatchError(this._actualValue, undefined, !this._shouldMatch);
}
}
/**
/**
* Checks that a value is null
*/
public toBeNull() {
if (this._actualValue !== null === this._shouldMatch) {
throw new ExactMatchError(this._actualValue, null, this._shouldMatch);
}
}
public toBeNull() {
if (this._actualValue !== null === this._shouldMatch) {
throw new ExactMatchError(this._actualValue, null, this._shouldMatch);
}
}
/**
/**
* Checks that a value is equivalent to boolean true
*/
public toBeTruthy() {
if ((this._actualValue && !this._shouldMatch) || (!this._actualValue && this._shouldMatch)) {
throw new TruthyMatchError(this._actualValue, this._shouldMatch);
}
}
public toBeTruthy() {
if ((this._actualValue && !this._shouldMatch) || (!this._actualValue && this._shouldMatch)) {
throw new TruthyMatchError(this._actualValue, this._shouldMatch);
}
}
/**
/**
* Checks that a string contains another string or an array contains a specific item
* @param expectedContent - the string or array item that the value should contain
*/
public toContain(expectedContent: any) {
if (this._actualValue.indexOf(expectedContent) === -1 === this._shouldMatch) {
throw new ContentsMatchError(this._actualValue, expectedContent, this._shouldMatch);
}
}
public toContain(expectedContent: any) {
/**
if (this._actualValue instanceof Array === false && typeof this._actualValue !== "string") {
throw new TypeError("toContain must only be used to check whether strings or arrays contain given contents.");
}
if (typeof this._actualValue === "string" && typeof expectedContent !== "string") {
throw new TypeError("toContain cannot check whether a string contains a non string value.");
}
if (this._actualValue.indexOf(expectedContent) === -1 === this._shouldMatch) {
throw new ContentsMatchError(this._actualValue, expectedContent, this._shouldMatch);
}
}
/**
* Checks that a number is less than a given limit
* @param upperLimit - the number that the number under test should be less than
*/
public toBeLessThan(upperLimit: number) {
if (this._actualValue < upperLimit !== this._shouldMatch) {
throw new LessThanMatchError(this._actualValue, upperLimit, this._shouldMatch);
}
}
public toBeLessThan(upperLimit: number) {
if (upperLimit === null || upperLimit === undefined) {
throw new TypeError("toBeLessThan upper limit must not be null or undefined.");
}
/**
if (typeof this._actualValue !== "number") {
throw new TypeError("toBeLessThan can only check numbers.");
}
if (this._actualValue < upperLimit !== this._shouldMatch) {
throw new LessThanMatchError(this._actualValue, upperLimit, this._shouldMatch);
}
}
/**
* Checks that a number is greater than a given limit
* @param lowerLimit - the number that the number under test should be greater than
*/
public toBeGreaterThan(lowerLimit: number) {
if (this._actualValue > lowerLimit !== this._shouldMatch) {
throw new GreaterThanMatchError(this._actualValue, lowerLimit, this._shouldMatch);
}
}
public toBeGreaterThan(lowerLimit: number) {
if (lowerLimit === null || lowerLimit === undefined) {
throw new TypeError("toBeGreaterThan lower limit must not be null or undefined.");
}
/**
if (typeof this._actualValue !== "number") {
throw new TypeError("toBeGreaterThan can only check numbers.");
}
if (this._actualValue > lowerLimit !== this._shouldMatch) {
throw new GreaterThanMatchError(this._actualValue, lowerLimit, this._shouldMatch);
}
}
/**
* Checks that a function throws an error when executed
*/
public toThrow() {
let errorThrown: Error;
public toThrow() {
try {
this._actualValue();
}
catch (error) {
if (!this._shouldMatch) {
throw new ErrorMatchError(error, this._shouldMatch);
if (this._actualValue instanceof Function === false) {
throw new TypeError("toThrow requires value passed in to Expect to be a function.");
}
errorThrown = error;
}
let errorThrown: Error;
if (this._shouldMatch && errorThrown === undefined) {
throw new ErrorMatchError(undefined, this._shouldMatch);
}
}
try {
this._actualValue();
}
catch (error) {
errorThrown = error;
}
/**
if (errorThrown === undefined === this._shouldMatch) {
throw new ErrorMatchError(errorThrown, this._shouldMatch);
}
}
/**
* Checks that a function throws a specific error

@@ -196,62 +235,87 @@ * @param errorType - the type of error that should be thrown

*/
public toThrowError(errorType: new (...args: Array<any>) => Error, errorMessage: string) {
let threwRightError = false;
let actualError: Error;
public toThrowError(errorType: new (...args: Array<any>) => Error, errorMessage: string) {
try {
this._actualValue();
}
catch (error) {
actualError = error;
if (this._actualValue instanceof Function === false) {
throw new TypeError("toThrowError requires value passed in to Expect to be a function.");
}
if (error instanceof errorType && error.message === errorMessage) {
threwRightError = true;
let threwRightError = false;
let actualError: Error;
try {
this._actualValue();
}
}
catch (error) {
actualError = error;
if (!threwRightError === this._shouldMatch) {
throw new ErrorMatchError(actualError, this._shouldMatch, (<any>errorType), errorMessage);
}
}
if (error instanceof errorType && error.message === errorMessage) {
threwRightError = true;
}
}
/**
if (threwRightError !== this._shouldMatch) {
throw new ErrorMatchError(actualError, this._shouldMatch, (<any>errorType), errorMessage);
}
}
/**
* Checks that a spy has been called
*/
public toHaveBeenCalled() {
if (this._actualValue.calls.length === 0 === this._shouldMatch) {
throw new FunctionCallMatchError(this._actualValue, this._shouldMatch);
}
}
public toHaveBeenCalled() {
if (this._isFunctionSpyOrSpiedOnFunction(this._actualValue) === false) {
throw new TypeError("toHaveBeenCalled requires value passed in to Expect to be a FunctionSpy or a spied on function.");
}
/**
if (this._actualValue.calls.length === 0 === this._shouldMatch) {
throw new FunctionCallMatchError(this._actualValue, this._shouldMatch);
}
}
/**
* Checks that a spy has been called with the specified arguments
* @param args - a list of arguments that the spy should have been called with
*/
public toHaveBeenCalledWith(...args: Array<any>) {
if (this._actualValue.calls.filter((call: any) => {
return call.args.filter((arg: any, index: number) => arg === args[index]).length === args.length && // all call arguments match expected arguments
call.args.length === args.length; // and the call has the same amount of arguments
}).length === 0 === this._shouldMatch) {
throw new FunctionCallMatchError(this._actualValue, this._shouldMatch, args);
}
}
public toHaveBeenCalledWith(...args: Array<any>) {
if (this._isFunctionSpyOrSpiedOnFunction(this._actualValue) === false) {
throw new TypeError("toHaveBeenCalledWith requires value passed in to Expect to be a FunctionSpy or a spied on function.");
}
/**
if (this._actualValue.calls.filter((call: any) => {
return call.args.filter((arg: any, index: number) => arg === args[index]).length === args.length && // all call arguments match expected arguments
call.args.length === args.length; // and the call has the same amount of arguments
}).length === 0 === this._shouldMatch) {
throw new FunctionCallMatchError(this._actualValue, this._shouldMatch, args);
}
}
private _isFunctionSpyOrSpiedOnFunction(value: any) {
return value instanceof FunctionSpy || (value instanceof Function && value.calls !== undefined);
}
/**
* Checks that a property spy has been set
*/
public toHaveBeenSet() {
if (this._actualValue.setCalls.length === 0 === this._shouldMatch) {
throw new PropertySetMatchError(this._actualValue, this._shouldMatch);
}
}
public toHaveBeenSet() {
if (this._actualValue instanceof PropertySpy === false) {
throw new TypeError("toHaveBeenSet requires value passed in to Expect to be a PropertySpy.");
}
/**
if (this._actualValue.setCalls.length === 0 === this._shouldMatch) {
throw new PropertySetMatchError(this._actualValue, this._shouldMatch);
}
}
/**
* Checks that a property spy has been set to a specific value
* @param value - a value to which the property should be set to
*/
public toHaveBeenSetTo(value: any) {
if (this._actualValue.setCalls.filter((call: any) => call.args[0] === value).length === 0 === this._shouldMatch) {
throw new PropertySetMatchError(this._actualValue, this._shouldMatch, value);
}
}
public toHaveBeenSetTo(value: any) {
if (this._actualValue instanceof PropertySpy === false) {
throw new TypeError("toHaveBeenSetTo requires value passed in to Expect to be a PropertySpy.");
}
if (this._actualValue.setCalls.filter((call: any) => call.args[0] === value).length === 0 === this._shouldMatch) {
throw new PropertySetMatchError(this._actualValue, this._shouldMatch, value);
}
}
}

@@ -65,21 +65,25 @@ "use strict";

var timeoutExpired = false;
var testPromise = _this._testFixture.fixture[_this._test.key].apply(_this._testFixture.fixture, _this._testCase.arguments);
var timeoutCheck = null;
testPromise.then(function () {
if (!timeoutExpired) {
try {
var testPromise = _this._testFixture.fixture[_this._test.key].apply(_this._testFixture.fixture, _this._testCase.arguments);
testPromise.then(function () {
if (!timeoutExpired) {
clearTimeout(timeoutCheck);
_this._reportResult(resolve);
}
})
.catch(function (error) {
clearTimeout(timeoutCheck);
_this._reportResult(resolve);
}
})
.catch(function (error) {
console.log(error);
clearTimeout(timeoutCheck);
_this._reportResult(resolve, error);
});
var testTimeout_1 = _this._test.timeout || timeout;
timeoutCheck = setTimeout(function () {
timeoutExpired = true;
var error = new _errors_1.TestTimeoutError(testTimeout_1);
_this._reportResult(resolve, error);
}, testTimeout_1);
}
catch (error) {
_this._reportResult(resolve, error);
});
var testTimeout = _this._test.timeout || timeout;
timeoutCheck = setTimeout(function () {
timeoutExpired = true;
var error = new _errors_1.TestTimeoutError(testTimeout);
_this._reportResult(resolve, error);
}, testTimeout);
}
});

@@ -86,0 +90,0 @@ };

@@ -57,25 +57,29 @@ import { ITestFixture, ITest, ITestCase } from "../_interfaces";

let timeoutExpired = false;
let testPromise: any = this._testFixture.fixture[this._test.key].apply(this._testFixture.fixture, this._testCase.arguments);
let timeoutCheck: NodeJS.Timer = null;
testPromise.then(() => {
if (!timeoutExpired) {
try {
let testPromise: any = this._testFixture.fixture[this._test.key].apply(this._testFixture.fixture, this._testCase.arguments);
testPromise.then(() => {
if (!timeoutExpired) {
clearTimeout(timeoutCheck);
this._reportResult(resolve);
}
})
.catch((error: Error) => {
clearTimeout(timeoutCheck);
this._reportResult(resolve);
}
})
.catch((error: Error) => {
console.log(error);
clearTimeout(timeoutCheck);
this._reportResult(resolve, error);
});
this._reportResult(resolve, error);
});
const testTimeout: number = this._test.timeout || timeout;
const testTimeout: number = this._test.timeout || timeout;
timeoutCheck = setTimeout(() => {
timeoutExpired = true;
let error = new TestTimeoutError(testTimeout);
timeoutCheck = setTimeout(() => {
timeoutExpired = true;
let error = new TestTimeoutError(testTimeout);
this._reportResult(resolve, error);
}, testTimeout);
}
catch (error) {
this._reportResult(resolve, error);
}, testTimeout);
}
});

@@ -82,0 +86,0 @@ }

import { Promise } from "../../promise/promise";
import { TestSetResults, TestSet, TestOutput } from "../alsatian-core";
import { TestSetResults, TestSet, TestOutputStream } from "../alsatian-core";
import "reflect-metadata";
export declare class TestRunner {
private _output;
constructor(output?: TestOutput);
private _outputStream;
constructor(outputStream?: TestOutputStream);
run(testSet: TestSet, timeout?: number): Promise<TestSetResults>;

@@ -8,0 +8,0 @@ private _createResultAndRunNextTest(testSetRunInfo, resolve, error?);

@@ -8,9 +8,9 @@ "use strict";

var TestRunner = (function () {
function TestRunner(output) {
function TestRunner(outputStream) {
// If we were given a TestOutput, use it, otherwise make one
if (output !== undefined) {
this._output = output;
if (outputStream !== undefined) {
this._outputStream = outputStream;
}
else {
this._output = new alsatian_core_1.TestOutput(process.stdout);
this._outputStream = new alsatian_core_1.TestOutputStream();
}

@@ -28,4 +28,4 @@ }

var testSetResults = new alsatian_core_1.TestSetResults();
this._output.emitVersion();
this._output.emitPlan(testPlan.testItems.length);
this._outputStream.emitVersion();
this._outputStream.emitPlan(testPlan.testItems.length);
return new promise_1.Promise(function (resolve, reject) {

@@ -44,3 +44,3 @@ var testSetRunInfo = new test_set_run_info_1.TestSetRunInfo(testPlan, testSetResults, timeout);

var result = currentTestResults.addTestCaseResult(testItem.testCase.arguments, error);
this._output.emitResult(testSetRunInfo.testPlan.testItems.indexOf(testItem) + 1, result);
this._outputStream.emitResult(testSetRunInfo.testPlan.testItems.indexOf(testItem) + 1, result);
this._scheduleNextTestPlanItem(testSetRunInfo, resolve);

@@ -58,3 +58,3 @@ };

if (!currentTestFixtureResults || currentTestFixtureResults.fixture !== nextTestPlanItem.testFixture) {
this._output.emitFixture(nextTestPlanItem.testFixture);
this._outputStream.emitFixture(nextTestPlanItem.testFixture);
currentTestFixtureResults = testSetResults.addTestFixtureResult(nextTestPlanItem.testFixture);

@@ -72,3 +72,3 @@ }

.catch(function (error) {
console.log(error);
_this._createResultAndRunNextTest(testSetRunInfo, resolve, error);
});

@@ -78,2 +78,3 @@ }

resolve(testSetRunInfo.testSetResults);
this._outputStream.end();
}

@@ -80,0 +81,0 @@ };

import { ITestFixture, ITest } from "../_interfaces";
import { Promise } from "../../promise/promise";
import { MatchError, TestSetResults, TestFixtureResults, TestResults, TestSet, TestOutput, TestTimeoutError } from "../alsatian-core";
import { MatchError, TestSetResults, TestFixtureResults, TestResults, TestSet, TestOutputStream, TestTimeoutError } from "../alsatian-core";
import { TestPlan } from "./test-plan";

@@ -11,10 +11,10 @@ import { TestItem } from "./test-item";

private _output: TestOutput;
private _outputStream: TestOutputStream;
constructor (output?: TestOutput) {
constructor (outputStream?: TestOutputStream) {
// If we were given a TestOutput, use it, otherwise make one
if (output !== undefined) {
this._output = output;
if (outputStream !== undefined) {
this._outputStream = outputStream;
} else {
this._output = new TestOutput(process.stdout);
this._outputStream = new TestOutputStream();
}

@@ -36,4 +36,4 @@ }

this._output.emitVersion();
this._output.emitPlan(testPlan.testItems.length);
this._outputStream.emitVersion();
this._outputStream.emitPlan(testPlan.testItems.length);

@@ -64,3 +64,3 @@ return new Promise<TestSetResults>((resolve, reject) => {

let result = currentTestResults.addTestCaseResult(testItem.testCase.arguments, error);
this._output.emitResult(testSetRunInfo.testPlan.testItems.indexOf(testItem) + 1, result);
this._outputStream.emitResult(testSetRunInfo.testPlan.testItems.indexOf(testItem) + 1, result);
this._scheduleNextTestPlanItem(testSetRunInfo, resolve);

@@ -84,3 +84,3 @@ }

if (!currentTestFixtureResults || currentTestFixtureResults.fixture !== nextTestPlanItem.testFixture) {
this._output.emitFixture(nextTestPlanItem.testFixture);
this._outputStream.emitFixture(nextTestPlanItem.testFixture);
currentTestFixtureResults = testSetResults.addTestFixtureResult(nextTestPlanItem.testFixture);

@@ -101,3 +101,3 @@ }

.catch((error: Error) => {
console.log(error);
this._createResultAndRunNextTest(testSetRunInfo, resolve, error);
});

@@ -107,4 +107,5 @@ }

resolve(testSetRunInfo.testSetResults);
this._outputStream.end();
}
};
}
{
"name": "alsatian",
"version": "1.0.0-alpha.16",
"version": "1.0.0-alpha.17",
"description": "TypeScript testing framework with test cases",

@@ -27,14 +27,13 @@ "author": "James Richford <=> (=)",

"postpublish": "node ./scripts/tag-release",
"review": "npm run review-code & npm run review-tests",
"review": "npm run review-code & npm run review-tests & npm run check-coverage",
"review-code": "tslint \"./cli/**/*.ts\" \"./core/**/*.ts\" --exclude \"./**/*.d.ts\"",
"review-tests": "tslint \"./test/**/*.ts\" --exclude \"./**/*.d.ts\"",
"test": "npm run unit-tests",
"test-dot": "node ./cli/alsatian-cli.js ./test/**/*.spec.js | tap-dot",
"test-spec": "node ./cli/alsatian-cli.js ./test/**/*.spec.js | tap-spec",
"unit-tests": "istanbul cover ./cli/alsatian-cli.js \"./test/unit-tests/**/*.spec.js\" && npm run remap-coverage",
"unit-tests": "node ./cli/alsatian-cli.js \"./test/unit-tests/**/*.spec.js\"",
"check-coverage": "npm run build & nyc --reporter=lcov --reporter=html npm run unit-tests && npm run output-test-coverage",
"output-test-coverage": "nyc report",
"integration-tests": "npm link && npm run cli-integration-tests && npm run node-integration-tests",
"cli-integration-tests": "alsatian \"./test/integration-tests/*.spec.js\"",
"node-integration-tests": "tsc -p \"./test/integration-tests/node\" && node \"./test/integration-tests/node/runner\"",
"debug-unit-tests": "node-debug ./cli/alsatian-cli.js \"./test/unit-tests/**/*.spec.js\"",
"remap-coverage": "remap-istanbul -i coverage/coverage.json --output coverage/report --type html"
"debug-unit-tests": "node-debug ./cli/alsatian-cli.js \"./test/unit-tests/**/*.spec.js\""
},

@@ -65,7 +64,6 @@ "repository": {

"devDependencies": {
"codeclimate-test-reporter": "^0.3.3",
"codeclimate-test-reporter": "^0.4.0",
"coveralls": "^2.11.9",
"istanbul": "^0.4.3",
"node-inspector": "^0.12.8",
"remap-istanbul": "^0.6.4",
"nyc": "^8.3.1",
"tslint": "^3.13.0",

@@ -78,4 +76,5 @@ "typescript": "^2.0.3"

"glob": "^7.0.3",
"reflect-metadata": "^0.1.3"
"reflect-metadata": "^0.1.3",
"tap-bark": "^1.0.0-beta.6"
}
}
# alsatian
[![NPM Version](https://img.shields.io/npm/v/alsatian.svg)](https://www.npmjs.com/package/alsatian)
[![License](https://img.shields.io/github/license/alsatian-test/alsatian.svg)](https://www.github.com/alsatian-test/alsatian/blob/master/license)
[![Build Status](https://travis-ci.org/alsatian-test/alsatian.svg?branch=master)](https://travis-ci.org/alsatian-test/alsatian)

@@ -49,2 +50,10 @@ [![Code Climate](https://codeclimate.com/github/alsatian-test/alsatian/badges/gpa.svg)](https://codeclimate.com/github/alsatian-test/alsatian)

#### TAP
The default reporter is the super snazzy [tap-bark](http://github.com/alsatian-test/tap-bark). If you want raw TAP output (so that it can be piped into a reporter of your choice), you can use the `tap` argument.
```
alsatian --tap
```
## Using alsatian

@@ -51,0 +60,0 @@

@@ -21,3 +21,3 @@ {

"./test/integration-tests/node**/*.ts",
"./node_modules/**/*.*"
"node_modules"
],

@@ -30,160 +30,5 @@ "filesGlob": [

],
"files": [
"./cli/alsatian-cli-options.ts",
"./cli/alsatian-cli.ts",
"./cli/cli-test-runner.ts",
"./cli/errors/duplicate-cli-argument-error.ts",
"./cli/errors/invalid-argument-names-error.ts",
"./cli/errors/invalid-timeout-value-error.ts",
"./cli/errors/missing-argument-value-error.ts",
"./core/_core.ts",
"./core/_decorators.ts",
"./core/_errors.ts",
"./core/_interfaces.ts",
"./core/_interfaces/test-case.i.ts",
"./core/_interfaces/test-fixture.i.ts",
"./core/_interfaces/test.i.ts",
"./core/_results.ts",
"./core/_running.ts",
"./core/_spying.ts",
"./core/alsatian-core.ts",
"./core/create-test-set.ts",
"./core/decorators/_metadata-keys.ts",
"./core/decorators/async-test-decorator.ts",
"./core/decorators/focus-test-decorator.ts",
"./core/decorators/focus-tests-decorator.ts",
"./core/decorators/ignore-test-decorator.ts",
"./core/decorators/ignore-tests-decorator.ts",
"./core/decorators/setup-decorator.ts",
"./core/decorators/teardown-decorator.ts",
"./core/decorators/test-case-decorator.ts",
"./core/decorators/test-decorator.ts",
"./core/decorators/timeout-decorator.ts",
"./core/errors/contents-match-error.ts",
"./core/errors/equal-match-error.ts",
"./core/errors/error-match-error.ts",
"./core/errors/exact-match-error.ts",
"./core/errors/function-call-match-error.ts",
"./core/errors/greater-than-match-error.ts",
"./core/errors/less-than-match-error.ts",
"./core/errors/match-error.ts",
"./core/errors/property-set-match-error.ts",
"./core/errors/regex-match-error.ts",
"./core/errors/test-timeout-error.ts",
"./core/errors/truthy-match-error.ts",
"./core/expect.ts",
"./core/file-requirer.ts",
"./core/glob-helper.ts",
"./core/results/test-case-result.ts",
"./core/results/test-fixture-results.ts",
"./core/results/test-outcome.ts",
"./core/results/test-results.ts",
"./core/results/test-set-results.ts",
"./core/running/test-item.ts",
"./core/running/test-plan.ts",
"./core/running/test-runner.ts",
"./core/running/test-set-run-info.ts",
"./core/spying/function-spy.ts",
"./core/spying/property-spy.ts",
"./core/spying/restorable-function-spy.ts",
"./core/spying/spy-call.ts",
"./core/spying/spy-on-property.ts",
"./core/spying/spy-on.ts",
"./core/test-fixture.ts",
"./core/test-loader.ts",
"./core/test-output.ts",
"./core/test-set.ts",
"./test/builders/output-stream-builder.ts",
"./test/builders/test-builder.ts",
"./test/builders/test-case-builder.ts",
"./test/builders/test-fixture-builder.ts",
"./test/integration-tests/node/tests/to-be.spec.ts",
"./test/integration-tests/to-be.spec.ts",
"./test/unit-tests/alsatian-core.spec.ts",
"./test/unit-tests/cli/alsatian-cli-options/file-globs.spec.ts",
"./test/unit-tests/cli/alsatian-cli-options/timeout-option.spec.ts",
"./test/unit-tests/cli/alsatian-cli-options/unknown-arguments.spec.ts",
"./test/unit-tests/cli/cli-test-runner.spec.ts",
"./test/unit-tests/decorators/async-test-decorator.spec.ts",
"./test/unit-tests/decorators/focus-test.spec.ts",
"./test/unit-tests/decorators/focus-tests.spec.ts",
"./test/unit-tests/decorators/ignore-test.spec.ts",
"./test/unit-tests/decorators/ignore-tests.spec.ts",
"./test/unit-tests/decorators/setup.spec.ts",
"./test/unit-tests/decorators/teardown.spec.ts",
"./test/unit-tests/decorators/test-case.spec.ts",
"./test/unit-tests/decorators/test.spec.ts",
"./test/unit-tests/decorators/timeout.spec.ts",
"./test/unit-tests/errors/contents-match-error.spec.ts",
"./test/unit-tests/errors/equal-match-error.spec.ts",
"./test/unit-tests/errors/error-match-error.spec.ts",
"./test/unit-tests/errors/exact-match-error.spec.ts",
"./test/unit-tests/errors/function-call-match-error.spec.ts",
"./test/unit-tests/errors/greater-than-match-error.spec.ts",
"./test/unit-tests/errors/less-than-match-error.spec.ts",
"./test/unit-tests/errors/match-error.spec.ts",
"./test/unit-tests/errors/property-set-match-error.spec.ts",
"./test/unit-tests/errors/regex-match-error.spec.ts",
"./test/unit-tests/errors/test-timeout-error.spec.ts",
"./test/unit-tests/errors/truthy-match-error.spec.ts",
"./test/unit-tests/expect-tests/to-be-defined.spec.ts",
"./test/unit-tests/expect-tests/to-be-greater-than.spec.ts",
"./test/unit-tests/expect-tests/to-be-less-than.spec.ts",
"./test/unit-tests/expect-tests/to-be-null.spec.ts",
"./test/unit-tests/expect-tests/to-be-truthy.spec.ts",
"./test/unit-tests/expect-tests/to-be.spec.ts",
"./test/unit-tests/expect-tests/to-contain.spec.ts",
"./test/unit-tests/expect-tests/to-equal.spec.ts",
"./test/unit-tests/expect-tests/to-have-been-called-with.spec.ts",
"./test/unit-tests/expect-tests/to-have-been-called.spec.ts",
"./test/unit-tests/expect-tests/to-have-been-set-to.spec.ts",
"./test/unit-tests/expect-tests/to-have-been-set.spec.ts",
"./test/unit-tests/expect-tests/to-match.spec.ts",
"./test/unit-tests/expect-tests/to-throw-error.spec.ts",
"./test/unit-tests/expect-tests/to-throw.spec.ts",
"./test/unit-tests/promise/promise.spec.ts",
"./test/unit-tests/results/test-case-result.spec.ts",
"./test/unit-tests/results/test-fixture-results.spec.ts",
"./test/unit-tests/results/test-results.spec.ts",
"./test/unit-tests/results/test-set-results.spec.ts",
"./test/unit-tests/running/test-set-run-info.spec.ts",
"./test/unit-tests/spying/function-spy/and-call.spec.ts",
"./test/unit-tests/spying/function-spy/and-return.spec.ts",
"./test/unit-tests/spying/function-spy/call.spec.ts",
"./test/unit-tests/spying/property-spy/and-call-getter.spec.ts",
"./test/unit-tests/spying/property-spy/and-call-setter.spec.ts",
"./test/unit-tests/spying/property-spy/and-return-value.spec.ts",
"./test/unit-tests/spying/property-spy/constructor.spec.ts",
"./test/unit-tests/spying/property-spy/restore.spec.ts",
"./test/unit-tests/spying/restorable-function-spy/and-call-through.spec.ts",
"./test/unit-tests/spying/restorable-function-spy/and-call.spec.ts",
"./test/unit-tests/spying/restorable-function-spy/and-return.spec.ts",
"./test/unit-tests/spying/restorable-function-spy/and-stub.spec.ts",
"./test/unit-tests/spying/restorable-function-spy/call.spec.ts",
"./test/unit-tests/spying/restorable-function-spy/restore.spec.ts",
"./test/unit-tests/spying/spy-call.spec.ts",
"./test/unit-tests/spying/spy-on-property.spec.ts",
"./test/unit-tests/spying/spy-on.spec.ts",
"./test/unit-tests/test-fixture/add-test.spec.ts",
"./test/unit-tests/test-loader/load-test-fixture.spec.ts",
"./test/unit-tests/test-loader/load-test-fixtures-tests/default-export-fixture.spec.ts",
"./test/unit-tests/test-loader/load-test-fixtures-tests/focussed-test.spec.ts",
"./test/unit-tests/test-loader/load-test-fixtures-tests/ignored-test.spec.ts",
"./test/unit-tests/test-loader/load-test-fixtures-tests/test-timeout.spec.ts",
"./test/unit-tests/test-output/emit-fixture.spec.ts",
"./test/unit-tests/test-output/emit-plan.spec.ts",
"./test/unit-tests/test-output/emit-result.spec.ts",
"./test/unit-tests/test-output/emit-version.spec.ts",
"./test/unit-tests/test-runner/async-test.spec.ts",
"./test/unit-tests/test-runner/failing-tests.spec.ts",
"./test/unit-tests/test-runner/fixture-info.spec.ts",
"./test/unit-tests/test-runner/focussed-test.spec.ts",
"./test/unit-tests/test-runner/no-tests-error.spec.ts",
"./test/unit-tests/test-runner/pre-test.spec.ts",
"./test/unit-tests/test-set/load-test.spec.ts",
"./scripts/tag-release.ts"
],
"atom": {
"rewriteTsconfig": true
"rewriteTsconfig": false
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc