Comparing version 1.0.0-beta.3 to 1.0.0-beta.4
@@ -8,5 +8,6 @@ import { AsyncTest } from "./decorators/async-test-decorator"; | ||
import { Teardown } from "./decorators/teardown-decorator"; | ||
import { TestFixture } from "./decorators/test-fixture-decorator"; | ||
import { Test } from "./decorators/test-decorator"; | ||
import { TestCase } from "./decorators/test-case-decorator"; | ||
import { Timeout } from "./decorators/timeout-decorator"; | ||
export { AsyncTest, FocusTest, FocusTests, IgnoreTest, IgnoreTests, Setup, Teardown, Test, TestCase, Timeout }; | ||
export { AsyncTest, FocusTest, FocusTests, IgnoreTest, IgnoreTests, Setup, Teardown, TestFixture, Test, TestCase, Timeout }; |
@@ -16,2 +16,4 @@ "use strict"; | ||
exports.Teardown = teardown_decorator_1.Teardown; | ||
var test_fixture_decorator_1 = require("./decorators/test-fixture-decorator"); | ||
exports.TestFixture = test_fixture_decorator_1.TestFixture; | ||
var test_decorator_1 = require("./decorators/test-decorator"); | ||
@@ -18,0 +20,0 @@ exports.Test = test_decorator_1.Test; |
@@ -1,3 +0,3 @@ | ||
import { Expect, TestSet, TestFixture, TestOutputStream } from "./_core"; | ||
import { AsyncTest, FocusTest, FocusTests, IgnoreTest, IgnoreTests, Setup, Teardown, Test, TestCase, Timeout } from "./_decorators"; | ||
import { Expect, TestSet, TestOutputStream } from "./_core"; | ||
import { AsyncTest, FocusTest, FocusTests, IgnoreTest, IgnoreTests, Setup, Teardown, TestFixture, Test, TestCase, Timeout } from "./_decorators"; | ||
import { Any, FunctionSpy, SpyOn, SpyOnProperty } from "./_spying"; | ||
@@ -4,0 +4,0 @@ import { TestSetResults, TestOutcome, TestFixtureResults, TestResults, TestCaseResult } from "./_results"; |
@@ -5,3 +5,2 @@ "use strict"; | ||
exports.TestSet = _core_1.TestSet; | ||
exports.TestFixture = _core_1.TestFixture; | ||
exports.TestOutputStream = _core_1.TestOutputStream; | ||
@@ -16,2 +15,3 @@ var _decorators_1 = require("./_decorators"); | ||
exports.Teardown = _decorators_1.Teardown; | ||
exports.TestFixture = _decorators_1.TestFixture; | ||
exports.Test = _decorators_1.Test; | ||
@@ -18,0 +18,0 @@ exports.TestCase = _decorators_1.TestCase; |
@@ -0,1 +1,2 @@ | ||
declare const TEST_FIXTURE: string; | ||
declare const TESTS: string; | ||
@@ -9,2 +10,2 @@ declare const FOCUS: string; | ||
declare const TIMEOUT: string; | ||
export { TESTS, FOCUS, IGNORE, IGNORE_REASON, SETUP, TEARDOWN, TEST_CASES, TIMEOUT }; | ||
export { TEST_FIXTURE, TESTS, FOCUS, IGNORE, IGNORE_REASON, SETUP, TEARDOWN, TEST_CASES, TIMEOUT }; |
"use strict"; | ||
var TEST_FIXTURE = "alsatian:test-fixture"; | ||
exports.TEST_FIXTURE = TEST_FIXTURE; | ||
var TESTS = "alsatian:tests"; | ||
@@ -3,0 +5,0 @@ exports.TESTS = TESTS; |
@@ -7,3 +7,3 @@ import { ITestFixture } from "./_interfaces"; | ||
loadTestFixture(filePath: string): Array<ITestFixture>; | ||
private _loadTestFixture(testFixtureConstructor, name); | ||
private _loadTestFixture(testFixtureConstructor, defaultFixtureDescription); | ||
} |
"use strict"; | ||
var _core_1 = require("./_core"); | ||
var alsatian_core_1 = require("./alsatian-core"); | ||
@@ -31,4 +32,9 @@ var TestLoader = (function () { | ||
}; | ||
TestLoader.prototype._loadTestFixture = function (testFixtureConstructor, name) { | ||
var testFixture = new alsatian_core_1.TestFixture(name); | ||
TestLoader.prototype._loadTestFixture = function (testFixtureConstructor, defaultFixtureDescription) { | ||
// get test fixture metadata or create new metadata | ||
// to support not requiring the TestFixture decorator. | ||
// This functionality will be removed in 2.0.0 where | ||
// TestFixture decorator will become mandatory | ||
var testFixture = Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.TEST_FIXTURE, testFixtureConstructor) | ||
|| new _core_1.TestFixture(defaultFixtureDescription); | ||
testFixture.ignored = false; | ||
@@ -35,0 +41,0 @@ if (Reflect.getMetadata(alsatian_core_1.METADATA_KEYS.IGNORE, testFixtureConstructor)) { |
@@ -18,3 +18,5 @@ /// <reference types="node" /> | ||
private _getArgumentDescription(argument); | ||
private _getErrorYaml(error); | ||
private _writeMatchErrorOutput(error); | ||
private _writeUnhandledErrorOutput(error); | ||
private _writeFailure(message, actual, expected, stack?); | ||
} |
@@ -65,6 +65,9 @@ "use strict"; | ||
this._writeOut("not ok " + testId + " " + description + "\n"); | ||
if (error instanceof _errors_1.MatchError === false) { | ||
error = new _errors_1.MatchError("the test threw an error", "the test to run", "Test threw " + error.constructor.name + " with message \"" + error.message + "\""); | ||
// if it's a match error then log it properly, otherwise log it as unhandled | ||
if (error instanceof _errors_1.MatchError) { | ||
this._writeMatchErrorOutput(error); | ||
} | ||
this._writeOut(this._getErrorYaml(error)); | ||
else { | ||
this._writeUnhandledErrorOutput(error); | ||
} | ||
}; | ||
@@ -94,9 +97,24 @@ TestOutputStream.prototype._getTestDescription = function (test, testCaseArguments) { | ||
}; | ||
TestOutputStream.prototype._getErrorYaml = function (error) { | ||
return " ---\n" + | ||
" message: \"" + error.message.replace(/\\/g, "\\\\").replace(/"/g, "\\\"") + "\"\n" + | ||
TestOutputStream.prototype._writeMatchErrorOutput = function (error) { | ||
var sanitisedMessage = error.message.replace(/\\/g, "\\\\").replace(/"/g, "\\\""); | ||
var sanitisedActual = JSON.stringify(error.actualValue); | ||
var sanitisedExpected = JSON.stringify(error.expectedValue); | ||
this._writeFailure(sanitisedMessage, sanitisedActual, sanitisedExpected); | ||
}; | ||
TestOutputStream.prototype._writeUnhandledErrorOutput = function (error) { | ||
this._writeFailure("The test threw an unhandled error.", "an unhandled error", "no unhandled errors to be thrown", error.stack); | ||
}; | ||
TestOutputStream.prototype._writeFailure = function (message, actual, expected, stack) { | ||
var output = " ---\n" + | ||
" message: \"" + message + "\"\n" + | ||
" severity: fail\n" + | ||
" data:\n" + | ||
" got: " + JSON.stringify(error.actualValue) + "\n" + | ||
" expect: " + JSON.stringify(error.expectedValue) + "\n ...\n"; | ||
" got: " + actual + "\n" + | ||
" expect: " + expected + "\n"; | ||
if (stack) { | ||
output = output + " stack: |\n"; | ||
output = output + stack.split("\n").map(function (l) { return " " + l; }).join("\n") + "\n"; | ||
} | ||
output = output + " ...\n"; | ||
this._writeOut(output); | ||
}; | ||
@@ -103,0 +121,0 @@ return TestOutputStream; |
{ | ||
"name": "alsatian", | ||
"version": "1.0.0-beta.3", | ||
"version": "1.0.0-beta.4", | ||
"description": "TypeScript testing framework with test cases", | ||
@@ -25,8 +25,9 @@ "author": "James Richford <=> (=)", | ||
"clean": "git clean -X -d -f", | ||
"prepublish": "npm run review && npm run build-publish && npm test", | ||
"prepublish": "in-publish && npm test && npm run build-publish || not-in-publish", | ||
"postpublish": "node ./scripts/tag-release", | ||
"review": "npm run review-code & npm run review-tests & npm run check-coverage", | ||
"review": "npm run review-code & npm run review-tests", | ||
"review-code": "tslint \"./cli/**/*.ts\" \"./core/**/*.ts\" --exclude \"./**/*.d.ts\"", | ||
"review-tests": "tslint \"./test/**/*.ts\" --exclude \"./**/*.d.ts\"", | ||
"test": "npm run unit-tests", | ||
"pretest": "npm run build", | ||
"test": "npm run review && npm run check-coverage && npm run integration-tests", | ||
"unit-tests": "node ./cli/alsatian-cli.js \"./test/unit-tests/**/*.spec.js\"", | ||
@@ -69,2 +70,3 @@ "check-coverage": "npm run build & nyc --reporter=lcov --reporter=html npm run unit-tests && npm run output-test-coverage", | ||
"gulp": "^3.9.1", | ||
"in-publish": "^2.0.0", | ||
"node-inspector": "^0.12.8", | ||
@@ -80,4 +82,4 @@ "nyc": "^8.3.1", | ||
"reflect-metadata": "^0.1.3", | ||
"tap-bark": "1.0.0-beta.10" | ||
"tap-bark": "1.0.0-beta.11" | ||
} | ||
} |
182
README.md
@@ -1,14 +0,35 @@ | ||
# 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) | ||
[![Code Climate](https://codeclimate.com/github/alsatian-test/alsatian/badges/gpa.svg)](https://codeclimate.com/github/alsatian-test/alsatian) | ||
[![Coverage Status](https://coveralls.io/repos/github/alsatian-test/alsatian/badge.svg?branch=master)](https://coveralls.io/github/alsatian-test/alsatian?branch=master) | ||
[![Issue Count](https://codeclimate.com/github/alsatian-test/alsatian/badges/issue_count.svg)](https://codeclimate.com/github/alsatian-test/alsatian) | ||
[![bitHound Code](https://www.bithound.io/github/alsatian-test/alsatian/badges/code.svg)](https://www.bithound.io/github/alsatian-test/alsatian) | ||
[![bitHound Dependencies](https://www.bithound.io/github/alsatian-test/alsatian/badges/dependencies.svg)](https://www.bithound.io/github/alsatian-test/alsatian/master/dependencies/npm) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/alsatian-test/alsatian/badge.svg)](https://snyk.io/test/github/alsatian-test/alsatian) | ||
<p id="banner" align="center"> | ||
<img src="/documentation/images/alsatian-mascot-logo.png?raw=true" alt="Alsatian Mascot Logo" /> | ||
<p id="tag-line" align="center">Awesomely easy and useful TypeScript testing framework with test cases, compatible with istanbul and tap reporters.</p> | ||
</p> | ||
<p id="badges" align="center"> | ||
<a href="https://www.npmjs.com/package/alsatian"> | ||
<img src="https://img.shields.io/npm/v/alsatian.svg" alt="NPM Version" /> | ||
</a> | ||
<a href="https://www.github.com/alsatian-test/alsatian/blob/master/LICENSE"> | ||
<img src="https://img.shields.io/github/license/alsatian-test/alsatian.svg" alt="License" /> | ||
</a> | ||
<a href="https://travis-ci.org/alsatian-test/alsatian"> | ||
<img src="https://travis-ci.org/alsatian-test/alsatian.svg?branch=master" alt="Build Status" /> | ||
</a> | ||
<a href="https://codeclimate.com/github/alsatian-test/alsatian"> | ||
<img src="https://codeclimate.com/github/alsatian-test/alsatian/badges/gpa.svg" alt="Code Climate" /> | ||
</a> | ||
<a href="https://coveralls.io/github/alsatian-test/alsatian?branch=master"> | ||
<img src="https://coveralls.io/repos/github/alsatian-test/alsatian/badge.svg?branch=master" alt="Coverage Status" /> | ||
</a> | ||
<a href="https://codeclimate.com/github/alsatian-test/alsatian"> | ||
<img src="https://codeclimate.com/github/alsatian-test/alsatian/badges/issue_count.svg" alt="Code Climate Issue Count" /> | ||
</a> | ||
<a href="https://www.bithound.io/github/alsatian-test/alsatian"> | ||
<img src="https://www.bithound.io/github/alsatian-test/alsatian/badges/code.svg" alt="bitHound Code Rating" /> | ||
</a> | ||
<a href="https://www.bithound.io/github/alsatian-test/alsatian/master/dependencies/npm"> | ||
<img src="https://www.bithound.io/github/alsatian-test/alsatian/badges/dependencies.svg" alt="bitHound Dependencies Rating" /> | ||
</a> | ||
<a href="https://snyk.io/test/github/alsatian-test/alsatian"> | ||
<img src="https://snyk.io/test/github/alsatian-test/alsatian/badge.svg" alt="Known Vulnerabilities" /> | ||
</a> | ||
</p> | ||
TypeScript testing framework with test cases, compatible with istanbul and tap reporters. | ||
## In BETA | ||
@@ -30,3 +51,3 @@ | ||
* Being written in TypeScript it fits perfectly into your TypeScript project (we're currently checking out supporting JavaScript too :) ) | ||
* Active suppport if you've got a question, a suggestion or found an issue let us know and we'll get back to you quickly | ||
* Active support if you've got a question, a suggestion or found an issue let us know and we'll get back to you quickly | ||
@@ -70,3 +91,3 @@ Also it's lightning fast, watch it run all of it's unit tests in super quick time! | ||
``` | ||
```typescript | ||
import { TestSet, TestRunner } from "alsatian"; | ||
@@ -104,3 +125,3 @@ import { TapBark } from "tap-bark"; | ||
``` | ||
```typescript | ||
import * as Gulp from "gulp"; | ||
@@ -140,3 +161,3 @@ import { TestSet, TestRunner } from "alsatian"; | ||
``` | ||
```typescript | ||
import { Expect, Test } from "alsatian"; | ||
@@ -164,7 +185,8 @@ | ||
By default, tests will be named the same as their functions and this will be what is output by alsatian. However, you can give the test a more meaningful name simply by supplying the ```Test``` annotation with whatever you desire. | ||
By default, tests will be named the same as their functions and fixtures will be named the same as their class. This will be what is output by alsatian. However, you can give the test or fixture more meaningful name simply by supplying the ```Test``` and ```TestFixture``` annotations with whatever you desire. | ||
``` | ||
import { Expect, Test } from "alsatian"; | ||
```typescript | ||
import { Expect, Test, TestFixture } from "alsatian"; | ||
@TestFixture("Awesome Test Fixture") | ||
export class ExampleTestFixture { | ||
@@ -183,5 +205,9 @@ | ||
> alsatian ./path/to/example.spec | ||
TAP version 13 | ||
1..1 | ||
ok 1 - Confirm 1 + 1 is 2 | ||
Awesome Test Fixture | ||
Confirm 1 + 1 is 2 | ||
|====================| | ||
Pass: 1/1 | ||
Fail: 0/1 | ||
Ignore: 0/1 | ||
``` | ||
@@ -193,5 +219,6 @@ | ||
``` | ||
import { Expect, TestCase } from "alsatian"; | ||
```typescript | ||
import { Expect, TestCase, TestFixture } from "alsatian"; | ||
@TestFixture("Example Test Fixture") | ||
export class ExampleTestFixture { | ||
@@ -215,3 +242,3 @@ | ||
``` | ||
```typescript | ||
Expect(1 + 1).toBe(2); | ||
@@ -225,3 +252,3 @@ Expect(1 + 1).not.toBe(3); | ||
``` | ||
```typescript | ||
Expect("1").toEqual(1); | ||
@@ -235,3 +262,3 @@ Expect(1 + 1).not.toEqual("3"); | ||
``` | ||
```typescript | ||
Expect("something").toMatch(/some/); | ||
@@ -245,3 +272,3 @@ Expect("another thing").not.toMatch(/something/); | ||
``` | ||
```typescript | ||
Expect("something").toBeDefined(); | ||
@@ -255,3 +282,3 @@ Expect(undefined).not.toBeDefined(); | ||
``` | ||
```typescript | ||
Expect(null).toBeNull(); | ||
@@ -265,3 +292,3 @@ Expect("something").not.toBeNull(); | ||
``` | ||
```typescript | ||
Expect(1).toBeTruthy(); | ||
@@ -275,3 +302,3 @@ Expect(0).not.toBeTruthy(); | ||
``` | ||
```typescript | ||
Expect("something").toContain("thing"); | ||
@@ -287,3 +314,3 @@ Expect([1, 2, 3]).toContain(2); | ||
``` | ||
```typescript | ||
Expect(2).toBeGreaterThan(1); | ||
@@ -297,3 +324,3 @@ Expect(1).not.toBeGreaterThan(2); | ||
``` | ||
```typescript | ||
Expect(1).toBeLessThan(2); | ||
@@ -307,3 +334,3 @@ Expect(2).not.toBeLessThan(1); | ||
``` | ||
```typescript | ||
Expect(() => throw new Error()).toThrow(); | ||
@@ -317,3 +344,3 @@ Expect(() => {}).not.toThrow(); | ||
``` | ||
```typescript | ||
Expect(() => throw new TypeError("things went wrong")).toThrowError(TypeError, "things went wrong"); | ||
@@ -327,3 +354,3 @@ Expect(() => throw new Error("some error we don't care about")).not.toThrow(TypeError, "super nasty error"); | ||
``` | ||
```typescript | ||
import { SpyOn } from "alsatian"; | ||
@@ -341,3 +368,3 @@ | ||
``` | ||
```typescript | ||
Expect(some.function).toHaveBeenCalled(); | ||
@@ -348,3 +375,3 @@ ``` | ||
``` | ||
```typescript | ||
Expect(some.function).toHaveBeenCalledWith(this, "and that"); | ||
@@ -355,3 +382,3 @@ ``` | ||
``` | ||
```typescript | ||
// you can use the Any function to signify an argument can be anything or any specific type | ||
@@ -362,3 +389,4 @@ Expect(some.function).toHaveBeenCalledWith(Any, Any(Number), Any(String)); | ||
... or a specific number of times ... | ||
``` | ||
```typescript | ||
Expect(some.function).toHaveBeenCalled().exactly(42).times; | ||
@@ -379,3 +407,3 @@ Expect(some.function).toHaveBeenCalledWith("something").anythingBut(10).times; | ||
``` | ||
```typescript | ||
SpyOn(some, "function").andStub(); | ||
@@ -386,3 +414,3 @@ ``` | ||
``` | ||
```typescript | ||
SpyOn(some, "function").andCall(() => console.log("I are called")); | ||
@@ -393,3 +421,3 @@ ``` | ||
``` | ||
```typescript | ||
SpyOn(some, "function").andReturn(42); | ||
@@ -400,3 +428,3 @@ ``` | ||
``` | ||
```typescript | ||
SpyOn(some, "function"); | ||
@@ -417,3 +445,3 @@ | ||
``` | ||
```typescript | ||
import { FunctionSpy } from "alsatian"; | ||
@@ -428,3 +456,3 @@ | ||
``` | ||
```typescript | ||
import { SpyOnProperty } from "alsatian"; | ||
@@ -453,3 +481,3 @@ | ||
``` | ||
```typescript | ||
const propertySpy = SpyOnProperty(test, "property"); | ||
@@ -465,3 +493,3 @@ | ||
``` | ||
```typescript | ||
Expect(propertySpy).toHaveBeenSetTo(42); | ||
@@ -472,5 +500,4 @@ ``` | ||
``` | ||
```typescript | ||
SpyOnProperty(test, "property").andCallGetter(() => { return "something"; }); | ||
``` | ||
@@ -480,5 +507,4 @@ | ||
``` | ||
```typescript | ||
SpyOnProperty(test, "property").andCallSetter((value: any) => { doSomethingWith(value); }); | ||
``` | ||
@@ -488,5 +514,4 @@ | ||
``` | ||
```typescript | ||
SpyOnProperty(test, "property").andReturnValue(42); | ||
``` | ||
@@ -496,6 +521,6 @@ | ||
``` | ||
```typescript | ||
const properySpy = SpyOnProperty(test, "property"); | ||
properySp.restore(); | ||
properySpy.restore(); | ||
``` | ||
@@ -507,5 +532,6 @@ | ||
``` | ||
import { Expect, AsyncTest } from "alsatian"; | ||
```typescript | ||
import { Expect, AsyncTest, TestFixture } from "alsatian"; | ||
@TestFixture("Example Test Fixture") | ||
export class ExampleTestFixture { | ||
@@ -529,5 +555,6 @@ | ||
``` | ||
import { Expect, AsyncTest, Timeout } from "alsatian"; | ||
```typescript | ||
import { Expect, AsyncTest, Timeout, TestFixture } from "alsatian"; | ||
@TestFixture("Example Test Fixture") | ||
export class ExampleTestFixture { | ||
@@ -553,5 +580,6 @@ | ||
``` | ||
import { Expect, Test, IgnoreTest } from "alsatian"; | ||
```typescript | ||
import { Expect, Test, IgnoreTest, TestFixture } from "alsatian"; | ||
@TestFixture("Example Test Fixture") | ||
export class ExampleTestFixture { | ||
@@ -569,6 +597,7 @@ | ||
``` | ||
import { Expect, Test, IgnoreTests } from "alsatian"; | ||
```typescript | ||
import { Expect, Test, IgnoreTests, TestFixture } from "alsatian"; | ||
@IgnoreTests() | ||
@TestFixture("Example Test Fixture") | ||
export class ExampleTestFixture { | ||
@@ -590,5 +619,6 @@ | ||
``` | ||
import { Expect, Test, IgnoreTest } from "alsatian"; | ||
```typescript | ||
import { Expect, Test, IgnoreTest, TestFixture } from "alsatian"; | ||
@TestFixture("Example Test Fixture") | ||
export class ExampleTestFixture { | ||
@@ -608,5 +638,6 @@ | ||
``` | ||
import { Expect, Test, FocusTest } from "alsatian"; | ||
```typescript | ||
import { Expect, Test, FocusTest, TestFixture } from "alsatian"; | ||
@TestFixture("Example Test Fixture") | ||
export class ExampleTestFixture { | ||
@@ -629,6 +660,7 @@ | ||
``` | ||
import { Expect, Test, FocusTests } from "alsatian"; | ||
```typescript | ||
import { Expect, Test, FocusTests, TestFixture } from "alsatian"; | ||
@FocusTests | ||
@TestFixture("Example Test Fixture") | ||
export class ExampleTestFixture { | ||
@@ -652,5 +684,6 @@ | ||
``` | ||
import { Expect, Test, Setup } from "alsatian"; | ||
```typescript | ||
import { Expect, Test, Setup, TestFixture } from "alsatian"; | ||
@TestFixture("Example Test Fixture") | ||
export class ExampleTestFixture { | ||
@@ -674,5 +707,6 @@ | ||
``` | ||
import { Expect, Test, Teardown } from "alsatian"; | ||
```typescript | ||
import { Expect, Test, Teardown, TestFixture } from "alsatian"; | ||
@TestFixture("Example Test Fixture") | ||
export class ExampleTestFixture { | ||
@@ -679,0 +713,0 @@ |
728471
158
3045
681
9
+ Addedtap-bark@1.0.0-beta.11(transitive)
- Removedtap-bark@1.0.0-beta.10(transitive)
Updatedtap-bark@1.0.0-beta.11