Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
d1e46fd2a7 | |||
9304e6d736 | |||
588c532d6d | |||
e3a756c775 | |||
05defe6031 | |||
f4bb17dea1 | |||
1023a94ff2 | |||
8ee456da5f |
2174
package-lock.json
generated
2174
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/tapbundle",
|
"name": "@pushrocks/tapbundle",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "3.2.10",
|
"version": "3.2.14",
|
||||||
"description": "tap bundled for tapbuffer",
|
"description": "tap bundled for tapbuffer",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
@ -20,6 +20,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/tapbundle#README",
|
"homepage": "https://gitlab.com/pushrocks/tapbundle#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@open-wc/testing-helpers": "^1.8.12",
|
||||||
"@pushrocks/smartdelay": "^2.0.10",
|
"@pushrocks/smartdelay": "^2.0.10",
|
||||||
"@pushrocks/smartenv": "^4.0.16",
|
"@pushrocks/smartenv": "^4.0.16",
|
||||||
"@pushrocks/smartpromise": "^3.1.3",
|
"@pushrocks/smartpromise": "^3.1.3",
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
import { tap, expect } from '../ts/index';
|
import { tap, expect, webhelpers } from '../ts/index';
|
||||||
|
|
||||||
tap.preTask('hi there', async () => {
|
tap.preTask('custompretask', async () => {
|
||||||
console.log('this is a pretask');
|
console.log('this is a pretask');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should have access to webhelpers', async () => {
|
||||||
|
const myElement = await webhelpers.fixture(webhelpers.html`<div></div>`);
|
||||||
|
expect(myElement).to.be.instanceOf(HTMLElement);
|
||||||
|
console.log(myElement);
|
||||||
|
});
|
||||||
|
|
||||||
const test1 = tap.test('my first test -> expect true to be true', async () => {
|
const test1 = tap.test('my first test -> expect true to be true', async () => {
|
||||||
return expect(true).to.be.true;
|
return expect(true).to.be.true;
|
||||||
});
|
});
|
||||||
|
@ -23,12 +23,14 @@ const test3 = tap.test(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const test4 = tap.skip.test('my 4th test -> should fail', async (tools) => {
|
const test4 = tap.test('my 4th test -> should fail', async (tools) => {
|
||||||
tools.allowFailure();
|
tools.allowFailure();
|
||||||
expect(false).to.be.true;
|
expect(false).to.be.false;
|
||||||
|
return 'hello';
|
||||||
});
|
});
|
||||||
|
|
||||||
const test5 = tap.test('my 5th test -> should pass in about 500ms', async (tools) => {
|
const test5 = tap.test('my 5th test -> should pass in about 500ms', async (tools) => {
|
||||||
|
const test4Result = await test4.testResultPromise;
|
||||||
tools.timeout(1000);
|
tools.timeout(1000);
|
||||||
await tools.delayFor(500);
|
await tools.delayFor(500);
|
||||||
});
|
});
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
export { expect } from 'smartchai';
|
export { expect } from 'smartchai';
|
||||||
export { tap } from './tapbundle.classes.tap';
|
export { tap } from './tapbundle.classes.tap';
|
||||||
export { TapWrap } from './tapbundle.classes.tapwrap';
|
export { TapWrap } from './tapbundle.classes.tapwrap';
|
||||||
|
export { webhelpers } from './webhelpers';
|
@ -2,16 +2,16 @@ import * as plugins from './tapbundle.plugins';
|
|||||||
|
|
||||||
import { IPreTaskFunction, PreTask } from './tapbundle.classes.pretask';
|
import { IPreTaskFunction, PreTask } from './tapbundle.classes.pretask';
|
||||||
import { TapTest, ITestFunction } from './tapbundle.classes.taptest';
|
import { TapTest, ITestFunction } from './tapbundle.classes.taptest';
|
||||||
export class Tap {
|
export class Tap <T> {
|
||||||
/**
|
/**
|
||||||
* skips a test
|
* skips a test
|
||||||
* tests marked with tap.skip.test() are never executed
|
* tests marked with tap.skip.test() are never executed
|
||||||
*/
|
*/
|
||||||
public skip = {
|
public skip = {
|
||||||
test: (descriptionArg: string, functionArg: ITestFunction) => {
|
test: (descriptionArg: string, functionArg: ITestFunction<T>) => {
|
||||||
console.log(`skipped test: ${descriptionArg}`);
|
console.log(`skipped test: ${descriptionArg}`);
|
||||||
},
|
},
|
||||||
testParallel: (descriptionArg: string, functionArg: ITestFunction) => {
|
testParallel: (descriptionArg: string, functionArg: ITestFunction<T>) => {
|
||||||
console.log(`skipped test: ${descriptionArg}`);
|
console.log(`skipped test: ${descriptionArg}`);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -20,14 +20,14 @@ export class Tap {
|
|||||||
* only executes tests marked as ONLY
|
* only executes tests marked as ONLY
|
||||||
*/
|
*/
|
||||||
public only = {
|
public only = {
|
||||||
test: (descriptionArg: string, testFunctionArg: ITestFunction) => {
|
test: (descriptionArg: string, testFunctionArg: ITestFunction<T>) => {
|
||||||
this.test(descriptionArg, testFunctionArg, 'only');
|
this.test(descriptionArg, testFunctionArg, 'only');
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
private _tapPreTasks: PreTask[] = [];
|
private _tapPreTasks: PreTask[] = [];
|
||||||
private _tapTests: TapTest[] = [];
|
private _tapTests: TapTest<any>[] = [];
|
||||||
private _tapTestsOnly: TapTest[] = [];
|
private _tapTestsOnly: TapTest<any>[] = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normal test function, will run one by one
|
* Normal test function, will run one by one
|
||||||
@ -36,10 +36,10 @@ export class Tap {
|
|||||||
*/
|
*/
|
||||||
public test(
|
public test(
|
||||||
testDescription: string,
|
testDescription: string,
|
||||||
testFunction: ITestFunction,
|
testFunction: ITestFunction<T>,
|
||||||
modeArg: 'normal' | 'only' | 'skip' = 'normal'
|
modeArg: 'normal' | 'only' | 'skip' = 'normal'
|
||||||
) {
|
): TapTest<T> {
|
||||||
const localTest = new TapTest({
|
const localTest = new TapTest<T>({
|
||||||
description: testDescription,
|
description: testDescription,
|
||||||
testFunction,
|
testFunction,
|
||||||
parallel: false,
|
parallel: false,
|
||||||
@ -61,7 +61,7 @@ export class Tap {
|
|||||||
* @param testDescription - A description of what the test does
|
* @param testDescription - A description of what the test does
|
||||||
* @param testFunction - A Function that returns a Promise and resolves or rejects
|
* @param testFunction - A Function that returns a Promise and resolves or rejects
|
||||||
*/
|
*/
|
||||||
public testParallel(testDescription: string, testFunction: ITestFunction) {
|
public testParallel(testDescription: string, testFunction: ITestFunction<T>) {
|
||||||
this._tapTests.push(
|
this._tapTests.push(
|
||||||
new TapTest({
|
new TapTest({
|
||||||
description: testDescription,
|
description: testDescription,
|
||||||
|
@ -9,25 +9,25 @@ import { HrtMeasurement } from '@pushrocks/smarttime';
|
|||||||
// interfaces
|
// interfaces
|
||||||
export type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess' | 'timeout';
|
export type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess' | 'timeout';
|
||||||
|
|
||||||
export type ITestFunction = (tapTools?: TapTools) => Promise<any>;
|
export interface ITestFunction <T> { (tapTools?: TapTools): Promise<T> };
|
||||||
|
|
||||||
export class TapTest {
|
export class TapTest <T = unknown> {
|
||||||
public description: string;
|
public description: string;
|
||||||
public failureAllowed: boolean;
|
public failureAllowed: boolean;
|
||||||
public hrtMeasurement: HrtMeasurement;
|
public hrtMeasurement: HrtMeasurement;
|
||||||
public parallel: boolean;
|
public parallel: boolean;
|
||||||
public status: TTestStatus;
|
public status: TTestStatus;
|
||||||
public tapTools: TapTools;
|
public tapTools: TapTools;
|
||||||
public testFunction: ITestFunction;
|
public testFunction: ITestFunction<T>;
|
||||||
public testKey: number; // the testKey the position in the test qeue. Set upon calling .run()
|
public testKey: number; // the testKey the position in the test qeue. Set upon calling .run()
|
||||||
private testDeferred: Deferred<TapTest> = plugins.smartpromise.defer();
|
private testDeferred: Deferred<TapTest<T>> = plugins.smartpromise.defer();
|
||||||
public testPromise: Promise<TapTest> = this.testDeferred.promise;
|
public testPromise: Promise<TapTest<T>> = this.testDeferred.promise;
|
||||||
private testResultDeferred: Deferred<any> = plugins.smartpromise.defer();
|
private testResultDeferred: Deferred<T> = plugins.smartpromise.defer();
|
||||||
public testResultPromise: Promise<any> = this.testResultDeferred.promise;
|
public testResultPromise: Promise<T> = this.testResultDeferred.promise;
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
*/
|
*/
|
||||||
constructor(optionsArg: { description: string; testFunction: ITestFunction; parallel: boolean }) {
|
constructor(optionsArg: { description: string; testFunction: ITestFunction<T>; parallel: boolean }) {
|
||||||
this.description = optionsArg.description;
|
this.description = optionsArg.description;
|
||||||
this.hrtMeasurement = new HrtMeasurement();
|
this.hrtMeasurement = new HrtMeasurement();
|
||||||
this.parallel = optionsArg.parallel;
|
this.parallel = optionsArg.parallel;
|
||||||
|
25
ts/webhelpers.ts
Normal file
25
ts/webhelpers.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import * as plugins from './tapbundle.plugins';
|
||||||
|
import type { fixture, html } from '@open-wc/testing-helpers';
|
||||||
|
import { tap } from './tapbundle.classes.tap';
|
||||||
|
|
||||||
|
class WebHelpers {
|
||||||
|
html: typeof html;
|
||||||
|
fixture: typeof fixture;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
const smartenv = new plugins.smartenv.Smartenv();
|
||||||
|
if(smartenv.isBrowser) {
|
||||||
|
this.enable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enable() {
|
||||||
|
tap.preTask('enable webhelpers', async () => {
|
||||||
|
const webhelpers = await import('@open-wc/testing-helpers')
|
||||||
|
this.html = webhelpers.html;
|
||||||
|
this.fixture = webhelpers.fixture;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const webhelpers = new WebHelpers();
|
Reference in New Issue
Block a user