Compare commits

...

19 Commits

Author SHA1 Message Date
2b71ffe8c2 3.2.8 2020-07-11 16:07:31 +00:00
29ec99e63e fix(core): update 2020-07-11 16:07:30 +00:00
50f1aad895 3.2.7 2020-07-08 00:46:44 +00:00
f7e95df2b9 fix(core): update 2020-07-08 00:46:43 +00:00
a00536996c 3.2.6 2020-07-08 00:17:32 +00:00
66f49cf8aa fix(core): update 2020-07-08 00:17:31 +00:00
aa3f1eb21f update readme 2020-07-08 00:17:25 +00:00
d81a8006b1 3.2.5 2020-07-08 00:16:10 +00:00
5fa4c1cd85 fix(core): update 2020-07-08 00:16:09 +00:00
fc609858ff 3.2.4 2020-07-08 00:15:45 +00:00
19ecca0179 fix(core): update 2020-07-08 00:15:44 +00:00
ff55e596cb 3.2.3 2020-07-08 00:11:16 +00:00
ed8c8312c2 fix(core): update 2020-07-08 00:11:16 +00:00
a6dd8de0db 3.2.2 2020-07-07 22:54:15 +00:00
081347b23b fix(core): update 2020-07-07 22:54:15 +00:00
f23575a8a2 3.2.1 2020-03-15 16:36:26 +00:00
b2dbc9160b fix(core): update 2020-03-15 16:36:25 +00:00
1e8ab2d7a2 3.2.0 2019-11-16 23:40:38 +01:00
427878763e feat(pretask): introduce new pretask functionality for setting up testing environment 2019-11-16 23:40:36 +01:00
19 changed files with 10452 additions and 948 deletions

4
.gitignore vendored
View File

@ -15,8 +15,6 @@ node_modules/
# builds # builds
dist/ dist/
dist_web/ dist_*/
dist_serve/
dist_ts_web/
# custom # custom

View File

@ -24,13 +24,14 @@ mirror:
- docker - docker
- notpriv - notpriv
snyk: audit:
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 -g snyk
- npmci command npm install --ignore-scripts - npmci command npm install --ignore-scripts
- npmci command snyk test - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high
tags: tags:
- lossless - lossless
- docker - docker

29
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
}
}
}
}
}
}
]
}

View File

@ -9,6 +9,7 @@
} }
}, },
"gitzone": { "gitzone": {
"projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "pushrocks",

11066
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,13 @@
{ {
"name": "@pushrocks/tapbundle", "name": "@pushrocks/tapbundle",
"private": false, "private": false,
"version": "3.1.0", "version": "3.2.8",
"description": "tap bundled for tapbuffer", "description": "tap bundled for tapbuffer",
"main": "dist/index.js", "main": "dist_ts/index.js",
"typings": "dist/index.d.ts", "typings": "dist_ts/index.d.ts",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/)",
"build": "(tsbuild)" "build": "(tsbuild --web)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -20,30 +20,34 @@
}, },
"homepage": "https://gitlab.com/pushrocks/tapbundle#README", "homepage": "https://gitlab.com/pushrocks/tapbundle#README",
"dependencies": { "dependencies": {
"@pushrocks/early": "^3.0.3", "@pushrocks/smartdelay": "^2.0.9",
"@pushrocks/smartdelay": "^2.0.3", "@pushrocks/smartenv": "^4.0.10",
"@pushrocks/smartfile": "^7.0.6",
"@pushrocks/smartpromise": "^3.0.2", "@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smarttime": "^3.0.19",
"smartchai": "^2.0.1" "smartchai": "^2.0.1"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.11", "@gitzone/tsbuild": "^2.1.24",
"@gitzone/tsrun": "^1.2.8", "@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.24", "@gitzone/tstest": "^1.0.41",
"@types/node": "^12.7.2", "@types/node": "^14.0.22",
"randomstring": "^1.1.5", "randomstring": "^1.1.5",
"tslint": "^5.19.0", "tslint": "^6.1.2",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
"ts_web/**/*", "ts_web/**/*",
"dist/**/*", "dist/**/*",
"dist_web/**/*", "dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*", "dist_ts_web/**/*",
"assets/**/*", "assets/**/*",
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
],
"browserslist": [
"last 1 chrome versions"
] ]
} }

View File

@ -8,13 +8,20 @@ tap bundled for tapbuffer
* [docs (typedoc)](https://pushrocks.gitlab.io/tapbundle/) * [docs (typedoc)](https://pushrocks.gitlab.io/tapbundle/)
## Status for master ## Status for master
[![build status](https://gitlab.com/pushrocks/tapbundle/badges/master/build.svg)](https://gitlab.com/pushrocks/tapbundle/commits/master)
[![coverage report](https://gitlab.com/pushrocks/tapbundle/badges/master/coverage.svg)](https://gitlab.com/pushrocks/tapbundle/commits/master) Status Category | Status Badge
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/tapbundle.svg)](https://www.npmjs.com/package/@pushrocks/tapbundle) -- | --
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/tapbundle/badge.svg)](https://snyk.io/test/npm/@pushrocks/tapbundle) GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/tapbundle/badges/master/pipeline.svg)](https://lossless.cloud)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/tapbundle/badges/master/coverage.svg)](https://lossless.cloud)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/tapbundle)](https://lossless.cloud)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/tapbundle)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/tapbundle)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/tapbundle)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/tapbundle)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage ## Usage
@ -35,24 +42,24 @@ import { tap, expect } 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
tap.test('my awesome description', async tools => { tap.test('my awesome description', async (tools) => {
// tools are optional parameter // tools are optional parameter
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 => { let 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).to.be.true; // will not throw
await expect(tools.delayFor(2000)).to.eventually.be.fulfilled; // yay expect promises :) await expect(tools.delayFor(2000)).to.eventually.be.fulfilled; // yay expect promises :)
expect((await myTest2.promise).hrtMeasurement.milliSeconds > 1000).to.be.true; // access other tests metadata :) expect((await myTest2.promise).hrtMeasurement.milliSeconds > 1000).to.be.true; // access other tests metadata :)
}); });
let myTest4 = tap.testParallel('my awesome test 4', async tools => { let 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');
}); });

40
test/test.browser.ts Normal file
View File

@ -0,0 +1,40 @@
import { tap, expect } from '../ts/index';
tap.preTask('hi there', async () => {
console.log('this is a pretask');
});
const test1 = tap.test('my first test -> expect true to be true', async () => {
return expect(true).to.be.true;
});
const test2 = tap.test('my second test', async (tools) => {
await tools.delayFor(50);
});
const test3 = tap.test(
'my third test -> test2 should take longer than test1 and endure at least 1000ms',
async () => {
expect((await test1).hrtMeasurement.milliSeconds < (await test2).hrtMeasurement.milliSeconds).to
.be.true;
expect((await test2).hrtMeasurement.milliSeconds > 10).to.be.true;
}
);
const test4 = tap.skip.test('my 4th test -> should fail', async (tools) => {
tools.allowFailure();
expect(false).to.be.true;
});
const test5 = tap.test('my 5th test -> should pass in about 500ms', async (tools) => {
tools.timeout(1000);
await tools.delayFor(500);
});
const test6 = tap.skip.test('my 6th test -> should fail after 1000ms', async (tools) => {
tools.allowFailure();
tools.timeout(1000);
await tools.delayFor(100);
});
tap.start();

View File

@ -1,21 +0,0 @@
import { tap, expect } from '../ts/index';
import * as randomstring from 'randomstring';
const test1 = tap.test('my first test -> expect true to be true', async tools => {
await tools.checkIterationLeak(async () => {
const domain = randomstring.generate(1000);
});
});
const outsideArray = [];
const test2 = tap.test('should throw', async tools => {
const err = await tools.returnError(async () => {
await tools.checkIterationLeak(async () => {
outsideArray.push(randomstring.generate(1000));
});
});
expect(err).to.be.undefined;
});
tap.start();

View File

@ -1,10 +1,5 @@
import { tap, expect } from '../ts/index'; import { tap, expect, TapWrap } from '../ts/index';
const tapwrap = tap.wrap(async () => { tap.test('should run a test', async () => {});
tap.test('should do something', async () => {
console.log('test1');
});
tap.start();
});
tapwrap.run(); tap.start();

View File

@ -1,10 +1,14 @@
import { tap, expect } from '../ts/index'; import { tap, expect } from '../ts/index';
tap.preTask('hi there', async () => {
console.log('this is a pretask');
});
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;
}); });
const test2 = tap.test('my second test', async tools => { const test2 = tap.test('my second test', async (tools) => {
await tools.delayFor(1000); await tools.delayFor(1000);
}); });
@ -17,17 +21,17 @@ const test3 = tap.test(
} }
); );
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).to.be.true;
}); });
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) => {
tools.timeout(1000); tools.timeout(1000);
await tools.delayFor(500); await tools.delayFor(500);
}); });
const test6 = tap.skip.test('my 6th test -> should fail after 1000ms', async tools => { const test6 = tap.skip.test('my 6th test -> should fail after 1000ms', async (tools) => {
tools.allowFailure(); tools.allowFailure();
tools.timeout(1000); tools.timeout(1000);
await tools.delayFor(2000); await tools.delayFor(2000);

View File

@ -1,2 +1,3 @@
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';

View File

@ -0,0 +1,21 @@
import * as plugins from './tapbundle.plugins';
import { TapTools } from './tapbundle.classes.taptools';
export interface IPreTaskFunction {
(tapTools?: TapTools): Promise<any>;
}
export class PreTask {
public description: string;
public preTaskFunction: IPreTaskFunction;
constructor(descriptionArg: string, preTaskFunctionArg: IPreTaskFunction) {
this.description = descriptionArg;
this.preTaskFunction = preTaskFunctionArg;
}
public async run() {
console.log(`::__PRETASK: ${this.description}`);
await this.preTaskFunction(new TapTools(null));
}
}

View File

@ -1,7 +1,7 @@
import * as plugins from './tapbundle.plugins'; import * as plugins from './tapbundle.plugins';
import { IPreTaskFunction, PreTask } from './tapbundle.classes.pretask';
import { TapTest, ITestFunction } from './tapbundle.classes.taptest'; import { TapTest, ITestFunction } from './tapbundle.classes.taptest';
import { TapWrap, ITapWrapFunction } from './tapbundle.classes.tapwrap';
export class Tap { export class Tap {
/** /**
* skips a test * skips a test
@ -13,7 +13,7 @@ export class Tap {
}, },
testParallel: (descriptionArg: string, functionArg: ITestFunction) => { testParallel: (descriptionArg: string, functionArg: ITestFunction) => {
console.log(`skipped test: ${descriptionArg}`); console.log(`skipped test: ${descriptionArg}`);
} },
}; };
/** /**
@ -22,9 +22,10 @@ export class Tap {
public only = { public only = {
test: (descriptionArg: string, testFunctionArg: ITestFunction) => { test: (descriptionArg: string, testFunctionArg: ITestFunction) => {
this.test(descriptionArg, testFunctionArg, 'only'); this.test(descriptionArg, testFunctionArg, 'only');
} },
}; };
private _tapPreTasks: PreTask[] = [];
private _tapTests: TapTest[] = []; private _tapTests: TapTest[] = [];
private _tapTestsOnly: TapTest[] = []; private _tapTestsOnly: TapTest[] = [];
@ -41,7 +42,7 @@ export class Tap {
const localTest = new TapTest({ const localTest = new TapTest({
description: testDescription, description: testDescription,
testFunction, testFunction,
parallel: false parallel: false,
}); });
if (modeArg === 'normal') { if (modeArg === 'normal') {
this._tapTests.push(localTest); this._tapTests.push(localTest);
@ -51,11 +52,8 @@ export class Tap {
return localTest; return localTest;
} }
/** public preTask(descriptionArg: string, functionArg: IPreTaskFunction) {
* wraps function this._tapPreTasks.push(new PreTask(descriptionArg, functionArg));
*/
public wrap(functionArg: ITapWrapFunction) {
return new TapWrap(functionArg);
} }
/** /**
@ -68,7 +66,7 @@ export class Tap {
new TapTest({ new TapTest({
description: testDescription, description: testDescription,
testFunction, testFunction,
parallel: true parallel: true,
}) })
); );
} }
@ -77,11 +75,19 @@ export class Tap {
* starts the test evaluation * starts the test evaluation
*/ */
public async start(optionsArg?: { throwOnError: boolean }) { public async start(optionsArg?: { throwOnError: boolean }) {
// lets set the tapbundle promise
const smartenvInstance = new plugins.smartenv.Smartenv();
smartenvInstance.isBrowser
? (globalThis.tapbundleDeferred = plugins.smartpromise.defer())
: null;
// lets continue with running the tests
const promiseArray: Array<Promise<any>> = []; const promiseArray: Array<Promise<any>> = [];
// safeguard against empty test array // safeguard against empty test array
if (this._tapTests.length === 0) { if (this._tapTests.length === 0) {
console.log('no tests specified. Ending here!'); console.log('no tests specified. Ending here!');
// TODO: throw proper error
return; return;
} }
@ -93,6 +99,11 @@ export class Tap {
concerningTests = this._tapTests; concerningTests = this._tapTests;
} }
// lets run the pretasks
for (const preTask of this._tapPreTasks) {
await preTask.run();
}
console.log(`1..${concerningTests.length}`); console.log(`1..${concerningTests.length}`);
for (let testKey = 0; testKey < concerningTests.length; testKey++) { for (let testKey = 0; testKey < concerningTests.length; testKey++) {
const currentTest = concerningTests[testKey]; const currentTest = concerningTests[testKey];
@ -125,7 +136,10 @@ export class Tap {
} }
if (optionsArg && optionsArg.throwOnError && failReasons.length > 0) { if (optionsArg && optionsArg.throwOnError && failReasons.length > 0) {
process.exit(1); if (!smartenvInstance.isBrowser) process.exit(1);
}
if (smartenvInstance.isBrowser) {
globalThis.tapbundleDeferred.resolve();
} }
} }

View File

@ -3,27 +3,25 @@ import { tapCreator } from './tapbundle.tapcreator';
import { TapTools } from './tapbundle.classes.taptools'; import { TapTools } from './tapbundle.classes.taptools';
// imported interfaces // imported interfaces
import { HrtMeasurement } from '@pushrocks/early';
import { Deferred } from '@pushrocks/smartpromise'; import { Deferred } from '@pushrocks/smartpromise';
import { HrtMeasurement } from '@pushrocks/smarttime';
// interfaces // interfaces
export type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess' | 'timeout'; export type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess' | 'timeout';
export interface ITestFunction { export type ITestFunction = (tapTools?: TapTools) => Promise<any>;
(tapTools?: TapTools): Promise<any>;
}
export class TapTest { export class TapTest {
description: string; public description: string;
failureAllowed: boolean; public failureAllowed: boolean;
hrtMeasurement: HrtMeasurement; public hrtMeasurement: HrtMeasurement;
parallel: boolean; public parallel: boolean;
status: TTestStatus; public status: TTestStatus;
tapTools: TapTools; public tapTools: TapTools;
testFunction: ITestFunction; public testFunction: ITestFunction;
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()
testDeferred: Deferred<TapTest> = plugins.smartpromise.defer(); public testDeferred: Deferred<TapTest> = plugins.smartpromise.defer();
testPromise: Promise<TapTest> = this.testDeferred.promise; public testPromise: Promise<TapTest> = this.testDeferred.promise;
/** /**
* constructor * constructor
*/ */
@ -39,10 +37,10 @@ export class TapTest {
/** /**
* run the test * run the test
*/ */
async run(testKeyArg: number) { public async run(testKeyArg: number) {
this.hrtMeasurement.start(); this.hrtMeasurement.start();
this.testKey = testKeyArg; this.testKey = testKeyArg;
let testNumber = testKeyArg + 1; const testNumber = testKeyArg + 1;
try { try {
await this.testFunction(this.tapTools); await this.testFunction(this.tapTools);
if (this.status === 'timeout') { if (this.status === 'timeout') {

View File

@ -42,14 +42,6 @@ export class TapTools {
} }
} }
public async ensureDir(pathArg: string) {
await plugins.smartfile.fs.ensureDir(pathArg);
}
public async checkIterationLeak(iterationfuncArg: IPromiseFunc) {
console.log('iteration leakage checks disabled for now due to incompatibilities with node v12');
}
public async returnError(throwingFuncArg: IPromiseFunc) { public async returnError(throwingFuncArg: IPromiseFunc) {
let funcErr: Error; let funcErr: Error;
try { try {

View File

@ -1,24 +1,13 @@
import * as plugins from './tapbundle.plugins'; import * as plugins from './tapbundle.plugins';
export interface ITapWrapFunction { export interface ITapWrapOptions {
(): Promise<any>; before: () => Promise<any>;
after: () => {};
} }
export class TapWrap { export class TapWrap {
wrapFunction: ITapWrapFunction; public options: ITapWrapOptions;
constructor(optionsArg: ITapWrapOptions) {
/** this.options = optionsArg;
* the constructor
*/
constructor(wrapFunctionArg: ITapWrapFunction) {
// nothing here
this.wrapFunction = wrapFunctionArg;
}
/**
* run the wrapFunction
*/
async run() {
await this.wrapFunction();
} }
} }

View File

@ -1,10 +1,9 @@
// pushrocks // pushrocks
import * as early from '@pushrocks/early';
import * as smartdelay from '@pushrocks/smartdelay'; import * as smartdelay from '@pushrocks/smartdelay';
import * as smartfile from '@pushrocks/smartfile'; import * as smartenv from '@pushrocks/smartenv';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
export { early, smartfile, smartdelay, smartpromise }; export { smartdelay, smartenv, smartpromise };
// third party // third party
/* import * as leakage from 'leakage'; /* import * as leakage from 'leakage';