implement tap myself
This commit is contained in:
parent
4e541b7986
commit
753c387325
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
import 'typings-global';
|
import 'typings-global';
|
||||||
import * as tap from 'tap';
|
|
||||||
import { expect } from 'smartchai';
|
import { expect } from 'smartchai';
|
||||||
|
import { tap } from './tapbundle.tap';
|
||||||
export { tap, expect };
|
export { tap, expect };
|
||||||
|
6
dist/index.js
vendored
6
dist/index.js
vendored
@ -1,8 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
require("typings-global");
|
require("typings-global");
|
||||||
const tap = require("tap");
|
|
||||||
exports.tap = tap;
|
|
||||||
const smartchai_1 = require("smartchai");
|
const smartchai_1 = require("smartchai");
|
||||||
exports.expect = smartchai_1.expect;
|
exports.expect = smartchai_1.expect;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QiwyQkFBMEI7QUFJeEIsa0JBQUc7QUFITCx5Q0FBa0M7QUFJaEMsb0NBQU0ifQ==
|
const tapbundle_tap_1 = require("./tapbundle.tap");
|
||||||
|
exports.tap = tapbundle_tap_1.tap;
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2Qix5Q0FBa0M7QUFNaEMsaUJBTk8sa0JBQU0sQ0FNUDtBQUxSLG1EQUFxQztBQUluQyxjQUpPLG1CQUFHLENBSVAifQ==
|
3
dist/tapbundle.plugins.d.ts
vendored
Normal file
3
dist/tapbundle.plugins.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import 'typings-global';
|
||||||
|
import * as smartq from 'smartq';
|
||||||
|
export { smartq };
|
6
dist/tapbundle.plugins.js
vendored
Normal file
6
dist/tapbundle.plugins.js
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
require("typings-global");
|
||||||
|
const smartq = require("smartq");
|
||||||
|
exports.smartq = smartq;
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwYnVuZGxlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90YXBidW5kbGUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QixpQ0FBZ0M7QUFHOUIsd0JBQU0ifQ==
|
37
dist/tapbundle.tap.d.ts
vendored
Normal file
37
dist/tapbundle.tap.d.ts
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
export declare type TTestStatus = 'success' | 'error' | 'pending';
|
||||||
|
export interface ITestFunction {
|
||||||
|
(): Promise<any>;
|
||||||
|
}
|
||||||
|
export declare class TapTest {
|
||||||
|
description: string;
|
||||||
|
testFunction: ITestFunction;
|
||||||
|
status: TTestStatus;
|
||||||
|
parallel: boolean;
|
||||||
|
returnValue: any;
|
||||||
|
/**
|
||||||
|
* constructor
|
||||||
|
*/
|
||||||
|
constructor(optionsArg: {
|
||||||
|
description: string;
|
||||||
|
testFunction: ITestFunction;
|
||||||
|
parallel: boolean;
|
||||||
|
});
|
||||||
|
/**
|
||||||
|
* run the test
|
||||||
|
*/
|
||||||
|
run(testKeyArg: number): Promise<void>;
|
||||||
|
}
|
||||||
|
export declare class Tap {
|
||||||
|
private _tests;
|
||||||
|
test(testDescription: string, testFunction: ITestFunction): Promise<void>;
|
||||||
|
testParallel(testDescription: string, testFunction: ITestFunction): void;
|
||||||
|
/**
|
||||||
|
* starts the test evaluation
|
||||||
|
*/
|
||||||
|
start(): Promise<void>;
|
||||||
|
/**
|
||||||
|
* handle errors
|
||||||
|
*/
|
||||||
|
threw(err: any): void;
|
||||||
|
}
|
||||||
|
export declare let tap: Tap;
|
91
dist/tapbundle.tap.js
vendored
Normal file
91
dist/tapbundle.tap.js
vendored
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
"use strict";
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
class TapTest {
|
||||||
|
/**
|
||||||
|
* constructor
|
||||||
|
*/
|
||||||
|
constructor(optionsArg) {
|
||||||
|
this.description = optionsArg.description;
|
||||||
|
this.testFunction = optionsArg.testFunction;
|
||||||
|
this.parallel = optionsArg.parallel;
|
||||||
|
this.status = 'pending';
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* run the test
|
||||||
|
*/
|
||||||
|
run(testKeyArg) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
try {
|
||||||
|
yield this.testFunction();
|
||||||
|
console.log(`ok ${testKeyArg + 1} - ${this.description}`);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.TapTest = TapTest;
|
||||||
|
class Tap {
|
||||||
|
constructor() {
|
||||||
|
this._tests = [];
|
||||||
|
}
|
||||||
|
test(testDescription, testFunction) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
this._tests.push(new TapTest({
|
||||||
|
description: testDescription,
|
||||||
|
testFunction: testFunction,
|
||||||
|
parallel: false
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
testParallel(testDescription, testFunction) {
|
||||||
|
this._tests.push(new TapTest({
|
||||||
|
description: testDescription,
|
||||||
|
testFunction: testFunction,
|
||||||
|
parallel: true
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* starts the test evaluation
|
||||||
|
*/
|
||||||
|
start() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
let promiseArray = [];
|
||||||
|
// safeguard against empty test array
|
||||||
|
if (this._tests.length === 0) {
|
||||||
|
console.log('no tests specified. Ending here!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(`1..${this._tests.length}`);
|
||||||
|
for (let testKey = 0; testKey < this._tests.length; testKey++) {
|
||||||
|
let currentTest = this._tests[testKey];
|
||||||
|
let testPromise = currentTest.run(testKey);
|
||||||
|
if (currentTest.parallel) {
|
||||||
|
promiseArray.push(testPromise);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
yield testPromise;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
yield Promise.all(promiseArray);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* handle errors
|
||||||
|
*/
|
||||||
|
threw(err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.Tap = Tap;
|
||||||
|
exports.tap = new Tap();
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwYnVuZGxlLnRhcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3Vy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QUFZLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxDQUFBO2dCQUNoQyxDQUFDO2dCQUFDLElBQUksQ0FBQyxDQUFDO29CQUNOLE1BQU0sV0FBVyxDQUFBO2dCQUNuQixDQUFDO1lBQ0gsQ0FBQztZQUNELE1BQU0sT0FBTyxDQUFDLEdBQUcsQ0FBQyxZQUFZLENBQUMsQ0FBQTtRQUNqQyxDQUFDO0tBQUE7SUFFRDs7T0FFRztJQUNILEtBQUssQ0FBRSxHQUFHO1FBQ1IsT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQTtJQUNsQixDQUFDO0NBQ0Y7QUFsREQsa0JBa0RDO0FBRVUsUUFBQSxHQUFHLEdBQUcsSUFBSSxHQUFHLEVBQUUsQ0FBQSJ9
|
@ -19,7 +19,7 @@
|
|||||||
"homepage": "https://gitlab.com/pushrocks/tapbundle#README",
|
"homepage": "https://gitlab.com/pushrocks/tapbundle#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"smartchai": "^1.0.3",
|
"smartchai": "^1.0.3",
|
||||||
"tap": "^10.3.0",
|
"smartq": "^1.1.1",
|
||||||
"typings-global": "^1.0.14"
|
"typings-global": "^1.0.16"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
7
test/test.ts
Normal file
7
test/test.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { tap, expect } from '../dist/index'
|
||||||
|
|
||||||
|
tap.test('my first test', async () => {
|
||||||
|
return expect(true).to.be.true
|
||||||
|
})
|
||||||
|
|
||||||
|
tap.start()
|
@ -1,6 +1,7 @@
|
|||||||
import 'typings-global'
|
import 'typings-global'
|
||||||
let tap = require('tap')
|
|
||||||
import { expect } from 'smartchai'
|
import { expect } from 'smartchai'
|
||||||
|
import { tap } from './tapbundle.tap'
|
||||||
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
tap,
|
tap,
|
||||||
|
6
ts/tapbundle.plugins.ts
Normal file
6
ts/tapbundle.plugins.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import 'typings-global'
|
||||||
|
import * as smartq from 'smartq'
|
||||||
|
|
||||||
|
export {
|
||||||
|
smartq
|
||||||
|
}
|
98
ts/tapbundle.tap.ts
Normal file
98
ts/tapbundle.tap.ts
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
import * as plugins from './tapbundle.plugins'
|
||||||
|
|
||||||
|
// interfaces
|
||||||
|
export type TTestStatus = 'success' | 'error' | 'pending'
|
||||||
|
|
||||||
|
export interface ITestFunction {
|
||||||
|
(): Promise<any>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export class TapTest {
|
||||||
|
description: string
|
||||||
|
testFunction: ITestFunction
|
||||||
|
status: TTestStatus
|
||||||
|
parallel: boolean
|
||||||
|
returnValue
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor
|
||||||
|
*/
|
||||||
|
constructor (optionsArg: {
|
||||||
|
description: string,
|
||||||
|
testFunction: ITestFunction,
|
||||||
|
parallel: boolean
|
||||||
|
}) {
|
||||||
|
this.description = optionsArg.description
|
||||||
|
this.testFunction = optionsArg.testFunction
|
||||||
|
this.parallel = optionsArg.parallel
|
||||||
|
this.status = 'pending'
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* run the test
|
||||||
|
*/
|
||||||
|
async run (testKeyArg: number) {
|
||||||
|
try {
|
||||||
|
await this.testFunction()
|
||||||
|
console.log(`ok ${testKeyArg + 1} - ${this.description}`)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Tap {
|
||||||
|
private _tests: TapTest[] = []
|
||||||
|
|
||||||
|
async test (testDescription: string, testFunction: ITestFunction) {
|
||||||
|
this._tests.push(new TapTest({
|
||||||
|
description: testDescription,
|
||||||
|
testFunction: testFunction,
|
||||||
|
parallel: false
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
testParallel (testDescription: string, testFunction: ITestFunction) {
|
||||||
|
this._tests.push(new TapTest({
|
||||||
|
description: testDescription,
|
||||||
|
testFunction: testFunction,
|
||||||
|
parallel: true
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* starts the test evaluation
|
||||||
|
*/
|
||||||
|
async start () {
|
||||||
|
let promiseArray: Promise<any>[] = []
|
||||||
|
|
||||||
|
// safeguard against empty test array
|
||||||
|
if (this._tests.length === 0) {
|
||||||
|
console.log('no tests specified. Ending here!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`1..${this._tests.length}`)
|
||||||
|
for (let testKey = 0; testKey < this._tests.length; testKey++) {
|
||||||
|
let currentTest = this._tests[testKey]
|
||||||
|
let testPromise = currentTest.run(testKey)
|
||||||
|
if (currentTest.parallel) {
|
||||||
|
promiseArray.push(testPromise)
|
||||||
|
} else {
|
||||||
|
await testPromise
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await Promise.all(promiseArray)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handle errors
|
||||||
|
*/
|
||||||
|
threw (err) {
|
||||||
|
console.log(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export let tap = new Tap()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user