Compare commits

...

24 Commits

Author SHA1 Message Date
8bf99ae7ec 4.0.5 2022-02-15 16:48:04 +01:00
cc708b29ae fix(core): update 2022-02-15 16:48:03 +01:00
5798d3e808 4.0.4 2022-02-15 16:40:22 +01:00
37fe299a45 fix(core): update 2022-02-15 16:40:21 +01:00
e24cdd9f0f 4.0.3 2022-02-02 08:11:01 +01:00
ae7aaab456 fix(core): update 2022-02-02 08:11:00 +01:00
bab360cc59 4.0.2 2022-02-02 07:38:27 +01:00
36dcd228fd fix(core): update 2022-02-02 07:38:26 +01:00
c7d6451758 4.0.1 2022-02-02 03:03:03 +01:00
aeedf14336 fix(core): update 2022-02-02 03:03:03 +01:00
14b95cfbc3 4.0.0 2022-01-21 19:54:08 +01:00
0884da7941 BREAKING CHANGE(core): switxh to @pushrocks/smartexpect 2022-01-21 19:54:07 +01:00
22df58b8bc 3.2.15 2021-12-10 17:34:06 +01:00
33399126f7 fix(core): update 2021-12-10 17:34:06 +01:00
d1e46fd2a7 3.2.14 2021-02-13 16:06:38 +00:00
9304e6d736 fix(core): update 2021-02-13 16:06:38 +00:00
588c532d6d 3.2.13 2021-02-13 16:02:40 +00:00
e3a756c775 fix(core): update 2021-02-13 16:02:40 +00:00
05defe6031 3.2.12 2021-01-26 03:19:50 +00:00
f4bb17dea1 fix(core): update 2021-01-26 03:19:49 +00:00
1023a94ff2 3.2.11 2021-01-26 03:15:50 +00:00
8ee456da5f fix(core): update 2021-01-26 03:15:50 +00:00
45ee6eca31 3.2.10 2021-01-26 02:35:03 +00:00
1eaf1e9a77 fix(core): update 2021-01-26 02:35:02 +00:00
13 changed files with 20428 additions and 3855 deletions

View File

@ -19,23 +19,35 @@ mirror:
stage: security stage: security
script: script:
- npmci git mirror - npmci git mirror
only:
- tags
tags: tags:
- lossless - lossless
- docker - docker
- notpriv - notpriv
audit: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare - npmci npm prepare
- npmci command npm install --ignore-scripts - npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high - npmci command npm audit --audit-level=high --only=dev
tags: tags:
- lossless
- docker - docker
- notpriv allow_failure: true
# ==================== # ====================
# test stage # test stage
@ -50,9 +62,7 @@ testStable:
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- priv
testBuild: testBuild:
stage: test stage: test
@ -63,9 +73,7 @@ testBuild:
- npmci command npm run build - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- notpriv
release: release:
stage: release stage: release
@ -85,6 +93,8 @@ release:
codequality: codequality:
stage: metadata stage: metadata
allow_failure: true allow_failure: true
only:
- tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g tslint typescript
- npmci npm prepare - npmci npm prepare

View File

@ -15,7 +15,7 @@
"properties": { "properties": {
"projectType": { "projectType": {
"type": "string", "type": "string",
"enum": ["website", "element", "service", "npm"] "enum": ["website", "element", "service", "npm", "wcc"]
} }
} }
} }

24068
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{ {
"name": "@pushrocks/tapbundle", "name": "@pushrocks/tapbundle",
"private": false, "private": false,
"version": "3.2.9", "version": "4.0.5",
"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,19 +20,20 @@
}, },
"homepage": "https://gitlab.com/pushrocks/tapbundle#README", "homepage": "https://gitlab.com/pushrocks/tapbundle#README",
"dependencies": { "dependencies": {
"@pushrocks/smartdelay": "^2.0.9", "@open-wc/testing-helpers": "^2.0.4",
"@pushrocks/smartenv": "^4.0.10", "@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartpromise": "^3.0.2", "@pushrocks/smartenv": "^4.0.16",
"@pushrocks/smarttime": "^3.0.19", "@pushrocks/smartexpect": "^1.0.12",
"smartchai": "^2.0.1" "@pushrocks/smartpromise": "^3.1.6",
"@pushrocks/smarttime": "^3.0.45"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.24", "@gitzone/tsbuild": "^2.1.29",
"@gitzone/tsrun": "^1.2.12", "@gitzone/tsrun": "^1.2.18",
"@gitzone/tstest": "^1.0.41", "@gitzone/tstest": "^1.0.64",
"@types/node": "^14.0.22", "@types/node": "^17.0.18",
"randomstring": "^1.1.5", "randomstring": "^1.2.2",
"tslint": "^6.1.2", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"files": [ "files": [

View File

@ -1,5 +1,5 @@
# @pushrocks/tapbundle # @pushrocks/tapbundle
tap bundled for tapbuffer tap based testing framework for use with @gitzone/tstest
## Availabililty and Links ## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/tapbundle) * [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/tapbundle)
@ -31,14 +31,17 @@ A few words on TypeScript
### Included in this package ### Included in this package
- tap compatible testing framework written in TypeScript * tap compatible testing framework written in TypeScript
- a collection of test tools * `expect` and `expectAsync` from the package `@pushrocks/smartexpect`
- **code** testing framework with typings
### A few words on tap
tap stands for **test anything protocol**. Its programming language agnostic as long as the test interpreter can read the tap console output. This package is optimized to work with @gitzone/tstest as interpreter, which offers different V8 based runtime environments like nodejs, chrome, and deno.
### Write your first tests ### Write your first tests
```javascript ```typescript
import { tap, expect } from 'tapbundle'; // has typings in place import { tap, expect, expectAsync } from 'tapbundle'; // has typings in place
import * as myAwesomeModuleToTest from '../dist/index'; // '../dist/index' is the standard path for npmts modules import * as myAwesomeModuleToTest from '../dist/index'; // '../dist/index' is the standard path for npmts modules
@ -47,25 +50,27 @@ tap.test('my awesome description', async (tools) => {
tools.timeout(2000); // test will fail if it takes longer than 2000 millisenconds tools.timeout(2000); // test will fail if it takes longer than 2000 millisenconds
}); });
let myTest2 = tap.test('my awesome test 2', async (tools) => { const myTest2 = tap.test('my awesome test 2', async (tools) => {
myAwsomeModuleToTest.doSomethingAsync(); // we don't wait here myAwsomeModuleToTest.doSomethingAsync(); // we don't wait here
await tools.delayFor(3000); // yay! :) promise based timeouts :) await tools.delayFor(3000); // yay! :) promise based timeouts :)
console.log('This gets logged 3000 ms into the test'); console.log('This gets logged 3000 ms into the test');
}); });
tap.test('my awesome test 3', async (tools) => { tap.test('my awesome test 3', async (tools) => {
expect(true).to.be.true; // will not throw expect(true).toBeTrue(); // will not throw
await expect(tools.delayFor(2000)).to.eventually.be.fulfilled; // yay expect promises :) await expectAsync(tools.delayFor(2000)).toBeUndefined(); // yay expect promises :)
expect((await myTest2.promise).hrtMeasurement.milliSeconds > 1000).to.be.true; // access other tests metadata :) expectAsync(myTest2.promise) // access other tests metadata :)
.property('hrtMeasurement') // and drill down into properties
.property('milliSeconds').toBeGreaterThan(1000);
}); });
let myTest4 = tap.testParallel('my awesome test 4', async (tools) => { const myTest4 = tap.testParallel('my awesome test 4', async (tools) => {
await tools.delayFor(4000); await tools.delayFor(4000);
console.log('logs to console after 4 seconds into this test'); console.log('logs to console after 4 seconds into this test');
}); });
tap.test('my awesome test 5', async () => { tap.test('my awesome test 5', async () => {
expect(myTest4.status).to.equal('pending'); // since this test will likely finish before myTest4. expect(myTest4.status).toEqual('pending'); // since this test will likely finish before myTest4.
}); });
tap.start(); // start the test, will automtically plan tests for you (so the tap parser knows when tests exit bofore they are finished) tap.start(); // start the test, will automtically plan tests for you (so the tap parser knows when tests exit bofore they are finished)

View File

@ -1,11 +1,17 @@
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).toBeInstanceOf(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).toBeTrue();
}); });
const test2 = tap.test('my second test', async (tools) => { const test2 = tap.test('my second test', async (tools) => {
@ -15,15 +21,14 @@ const test2 = tap.test('my second test', async (tools) => {
const test3 = tap.test( const test3 = tap.test(
'my third test -> test2 should take longer than test1 and endure at least 1000ms', 'my third test -> test2 should take longer than test1 and endure at least 1000ms',
async () => { async () => {
expect((await test1).hrtMeasurement.milliSeconds < (await test2).hrtMeasurement.milliSeconds).to expect((await test1).hrtMeasurement.milliSeconds < (await test2).hrtMeasurement.milliSeconds).toBeTrue();
.be.true; expect((await test2).hrtMeasurement.milliSeconds > 10).toBeTrue();
expect((await test2).hrtMeasurement.milliSeconds > 10).to.be.true;
} }
); );
const test4 = tap.skip.test('my 4th test -> should fail', async (tools) => { const test4 = tap.skip.test('my 4th test -> should fail', async (tools) => {
tools.allowFailure(); tools.allowFailure();
expect(false).to.be.true; expect(false).toBeTrue();
}); });
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) => {

View File

@ -5,7 +5,7 @@ tap.preTask('hi there', async () => {
}); });
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).toBeTrue();
}); });
const test2 = tap.test('my second test', async (tools) => { const test2 = tap.test('my second test', async (tools) => {
@ -15,18 +15,22 @@ const test2 = tap.test('my second test', async (tools) => {
const test3 = tap.test( const test3 = tap.test(
'my third test -> test2 should take longer than test1 and endure at least 1000ms', 'my third test -> test2 should take longer than test1 and endure at least 1000ms',
async () => { async () => {
expect((await test1).hrtMeasurement.milliSeconds < (await test2).hrtMeasurement.milliSeconds).to expect(
.be.true; (await test1.testPromise).hrtMeasurement.milliSeconds <
expect((await test2).hrtMeasurement.milliSeconds > 1000).to.be.true; (await test2).hrtMeasurement.milliSeconds
).toBeTrue();
expect((await test2.testPromise).hrtMeasurement.milliSeconds > 1000).toBeTrue();
} }
); );
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).toBeFalse();
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);
}); });

View File

@ -1,3 +1,10 @@
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';
import { expect, expectAsync } from '@pushrocks/smartexpect';
export {
expect,
expectAsync
}

View File

@ -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,26 +20,26 @@ 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
* @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 async 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,
@ -78,7 +78,7 @@ export class Tap {
// lets set the tapbundle promise // lets set the tapbundle promise
const smartenvInstance = new plugins.smartenv.Smartenv(); const smartenvInstance = new plugins.smartenv.Smartenv();
smartenvInstance.isBrowser smartenvInstance.isBrowser
? (globalThis.tapbundleDeferred = plugins.smartpromise.defer()) ? ((globalThis as any).tapbundleDeferred = plugins.smartpromise.defer())
: null; : null;
// lets continue with running the tests // lets continue with running the tests
@ -139,14 +139,14 @@ export class Tap {
if (!smartenvInstance.isBrowser) process.exit(1); if (!smartenvInstance.isBrowser) process.exit(1);
} }
if (smartenvInstance.isBrowser) { if (smartenvInstance.isBrowser) {
globalThis.tapbundleDeferred.resolve(); (globalThis as any).tapbundleDeferred.resolve();
} }
} }
/** /**
* handle errors * handle errors
*/ */
public threw(err) { public threw(err: Error) {
console.log(err); console.log(err);
} }
} }

View File

@ -9,23 +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()
public 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<T> = plugins.smartpromise.defer();
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;
@ -42,7 +44,7 @@ export class TapTest {
this.testKey = testKeyArg; this.testKey = testKeyArg;
const testNumber = testKeyArg + 1; const testNumber = testKeyArg + 1;
try { try {
await this.testFunction(this.tapTools); const testReturnValue = await this.testFunction(this.tapTools);
if (this.status === 'timeout') { if (this.status === 'timeout') {
throw new Error('Test succeeded, but timed out...'); throw new Error('Test succeeded, but timed out...');
} }
@ -52,12 +54,14 @@ export class TapTest {
); );
this.status = 'success'; this.status = 'success';
this.testDeferred.resolve(this); this.testDeferred.resolve(this);
} catch (err) { this.testResultDeferred.resolve(testReturnValue);
} catch (err: any) {
this.hrtMeasurement.stop(); this.hrtMeasurement.stop();
console.log( console.log(
`not ok ${testNumber} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms` `not ok ${testNumber} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`
); );
this.testDeferred.resolve(this); this.testDeferred.resolve(this);
this.testResultDeferred.resolve(err);
// if the test has already succeeded before // if the test has already succeeded before
if (this.status === 'success') { if (this.status === 'success') {

View File

@ -11,7 +11,7 @@ export class TapTools {
*/ */
private _tapTest: TapTest; private _tapTest: TapTest;
constructor(TapTestArg) { constructor(TapTestArg: TapTest<any>) {
this._tapTest = TapTestArg; this._tapTest = TapTestArg;
} }
@ -25,11 +25,11 @@ export class TapTools {
/** /**
* async/await delay method * async/await delay method
*/ */
public async delayFor(timeMilliArg) { public async delayFor(timeMilliArg: number) {
await plugins.smartdelay.delayFor(timeMilliArg); await plugins.smartdelay.delayFor(timeMilliArg);
} }
public async delayForRandom(timeMilliMinArg, timeMilliMaxArg) { public async delayForRandom(timeMilliMinArg: number, timeMilliMaxArg: number) {
await plugins.smartdelay.delayForRandom(timeMilliMinArg, timeMilliMaxArg); await plugins.smartdelay.delayForRandom(timeMilliMinArg, timeMilliMaxArg);
} }
@ -46,7 +46,7 @@ export class TapTools {
let funcErr: Error; let funcErr: Error;
try { try {
await throwingFuncArg(); await throwingFuncArg();
} catch (err) { } catch (err: any) {
funcErr = err; funcErr = err;
} }
return funcErr; return funcErr;

View File

@ -1,11 +1,7 @@
// pushrocks // pushrocks
import * as smartdelay from '@pushrocks/smartdelay'; import * as smartdelay from '@pushrocks/smartdelay';
import * as smartenv from '@pushrocks/smartenv'; import * as smartenv from '@pushrocks/smartenv';
import * as smartexpect from '@pushrocks/smartexpect';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
export { smartdelay, smartenv, smartpromise }; export { smartdelay, smartenv, smartexpect, smartpromise };
// third party
/* import * as leakage from 'leakage';
export { leakage }; */

25
ts/webhelpers.ts Normal file
View 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();