Compare commits

...

68 Commits

Author SHA1 Message Date
003dc473ea 1.0.47 2020-09-29 15:58:28 +00:00
e6baed5470 fix(core): update 2020-09-29 15:58:26 +00:00
d9a27adb4a 1.0.46 2020-09-29 15:29:46 +00:00
eabb75a9a8 fix(core): update 2020-09-29 15:29:45 +00:00
deb63c1af5 1.0.45 2020-09-29 15:14:33 +00:00
7ee3969798 fix(core): update 2020-09-29 15:14:32 +00:00
61eea77805 1.0.44 2020-08-13 01:29:19 +00:00
3d9685ac6f fix(core): update 2020-08-13 01:29:19 +00:00
4ec56c3f0b 1.0.43 2020-07-12 00:47:42 +00:00
ab33720aba fix(core): update 2020-07-12 00:47:41 +00:00
5e42565567 1.0.42 2020-07-11 16:14:08 +00:00
88b7581eeb fix(core): update 2020-07-11 16:14:07 +00:00
0ea621cb99 1.0.41 2020-07-11 15:52:32 +00:00
984d551bd6 fix(core): update 2020-07-11 15:52:31 +00:00
4066d9b0e8 1.0.40 2020-07-09 23:20:15 +00:00
f24ff2f79e fix(core): update 2020-07-09 23:20:14 +00:00
9d37fcf734 1.0.39 2020-07-09 22:00:46 +00:00
f7524179d7 fix(core): update 2020-07-09 22:00:45 +00:00
19d6b52ddb 1.0.38 2020-07-08 02:05:51 +00:00
cf69e5436c fix(core): update 2020-07-08 02:05:51 +00:00
6bee853cd2 1.0.37 2020-07-08 00:59:56 +00:00
4aa731b531 fix(core): update 2020-07-08 00:59:55 +00:00
a849f36a1b 1.0.36 2020-07-07 23:09:17 +00:00
30284b770c fix(core): update 2020-07-07 23:09:17 +00:00
023176258a 1.0.35 2020-07-07 21:59:08 +00:00
ad2866ae0b fix(core): update 2020-07-07 21:59:07 +00:00
af030ed013 1.0.34 2020-07-07 20:50:30 +00:00
940133493c fix(core): update 2020-07-07 20:50:29 +00:00
e999abbba6 1.0.33 2020-06-01 20:48:55 +00:00
4ede3090af fix(core): update 2020-06-01 20:48:54 +00:00
c5c295f42d 1.0.32 2020-06-01 19:58:15 +00:00
4602fed130 fix(core): update 2020-06-01 19:58:15 +00:00
a6ecf1d530 1.0.31 2020-06-01 19:52:25 +00:00
22703f261c fix(core): update 2020-06-01 19:52:24 +00:00
289cc6c0df 1.0.30 2020-06-01 19:29:57 +00:00
97d0ebffec fix(core): update 2020-06-01 19:29:56 +00:00
da19d5de39 1.0.29 2020-06-01 18:40:22 +00:00
7380323186 fix(core): update 2020-06-01 18:40:22 +00:00
7a6923051f 1.0.28 2019-10-02 11:51:32 +02:00
0bac34dd37 fix(core): update 2019-10-02 11:51:31 +02:00
e10d9eb2a7 1.0.27 2019-10-02 11:18:45 +02:00
c5596f1a8f fix(core): update 2019-10-02 11:18:45 +02:00
ac0bb6f9b0 1.0.26 2019-10-02 10:59:54 +02:00
32db50ef1f fix(core): update 2019-10-02 10:59:53 +02:00
a35db70155 1.0.25 2019-10-02 10:56:03 +02:00
0286312855 fix(core): update 2019-10-02 10:56:02 +02:00
40cf6f72ce 1.0.24 2019-05-28 11:32:06 +02:00
e6c71a1350 fix(core): update 2019-05-28 11:32:06 +02:00
1c640b8545 1.0.23 2019-05-27 15:49:22 +02:00
8c4b591391 fix(core): update 2019-05-27 15:49:22 +02:00
8eb270ebbc 1.0.22 2019-05-27 13:14:31 +02:00
f6d47a1a67 fix(core): update 2019-05-27 13:14:31 +02:00
2a41acc6e4 1.0.21 2019-05-22 16:43:02 +02:00
fb6bb85441 fix(core): update 2019-05-22 16:43:02 +02:00
02dbe602b2 1.0.20 2019-04-08 17:52:41 +02:00
e17d7009d9 fix(core): update 2019-04-08 17:52:41 +02:00
d22534388d 1.0.19 2019-04-08 17:50:57 +02:00
e258b2d62e fix(core): update 2019-04-08 17:50:57 +02:00
5afe6e6981 1.0.18 2018-12-06 01:03:49 +01:00
5d071d0299 fix(core): update 2018-12-06 01:03:48 +01:00
180bfcb353 1.0.17 2018-12-06 00:56:36 +01:00
3161e6b4eb fix(core): update 2018-12-06 00:56:36 +01:00
6129388a20 1.0.16 2018-12-06 00:38:03 +01:00
8f0cfe1a06 fix(core): update 2018-12-06 00:38:03 +01:00
39926fb08b 1.0.15 2018-08-14 00:04:43 +02:00
36594b64f2 fix(dependencies): update 2018-08-14 00:04:42 +02:00
9f898b6579 1.0.14 2018-08-13 23:58:51 +02:00
b1725b636b fix(improve test handling): now failing correctly and with better log output 2018-08-13 23:58:50 +02:00
20 changed files with 10098 additions and 695 deletions

16
.gitignore vendored
View File

@ -1,6 +1,20 @@
.nogit/
node_modules/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,16 +1,16 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmci
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
- security
- test
- release
- metadata
# ====================
# security stage
@ -18,109 +18,104 @@ stages:
mirror:
stage: security
script:
- npmci git mirror
- npmci git mirror
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
snyk:
audit:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm install -g snyk
- npmci npm prepare
- 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:
- docker
- notpriv
- lossless
- docker
- notpriv
# ====================
# test stage
# ====================
testLEGACY:
stage: test
script:
- npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
allow_failure: true
testLTS:
testStable:
stage: test
script:
- npmci node install lts
- npmci npm install
- npmci npm test
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
testSTABLE:
- lossless
- docker
- priv
testBuild:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm test
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
- npmci node install stable
- npmci npm publish
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SOURCE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
- npmci trigger
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g typedoc typescript
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
@ -128,15 +123,5 @@ pages:
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true
windowsCompatibility:
image: stefanscherer/node-windows:10-build-tools
stage: metadata
script:
- npm install & npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- windows
- public
allow_failure: true

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"]
}
}
}
}
}
}
]
}

3
cli.js
View File

@ -1,3 +1,4 @@
#!/usr/bin/env node
process.env.CLI_CALL = 'true';
require('./dist/index');
const cliTool = require('./dist_ts/index');
cliTool.runCli();

View File

@ -1,4 +1,5 @@
#!/usr/bin/env node
process.env.CLI_CALL = 'true';
require('@gitzone/tsrun');
require('./ts/index');
const cliTool = require('./ts/index');
cliTool.runCli();

3
contribute.md Normal file
View File

@ -0,0 +1,3 @@
# How to contribute
Start with `tstest.classes.tstest.ts` to understand whats happening

View File

@ -2,5 +2,16 @@
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "gitzone",
"gitrepo": "tstest",
"shortDescription": "a test utility to run tests that match test/**/*.ts",
"npmPackagename": "@gitzone/tstest",
"license": "MIT"
}
}
}
}

9946
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,35 +1,55 @@
{
"name": "@gitzone/tstest",
"version": "1.0.13",
"version": "1.0.47",
"private": false,
"description": "a test utility to run tests that match test/**/*.ts",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH",
"license": "MIT",
"bin": {
"tstest": "./cli.js"
},
"scripts": {
"test": "(npm run prepareTest && npm run tstest && npm run cleanUp)",
"test": "(npm run cleanUp && npm run prepareTest && npm run tstest)",
"prepareTest": "git clone https://gitlab.com/sandboxzone/sandbox-npmts.git .nogit/sandbox-npmts && cd .nogit/sandbox-npmts && npm install",
"tstest": "cd .nogit/sandbox-npmts && node ../../cli.ts.js test/",
"tstest": "cd .nogit/sandbox-npmts && node ../../cli.ts.js test/ --web",
"cleanUp": "rm -rf .nogit/sandbox-npmts",
"format": "(gitzone format)",
"build": "(tsbuild)"
"build": "(tsbuild --web)"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.0.21",
"@pushrocks/tapbundle": "^3.0.1"
"@gitzone/tsbuild": "^2.1.25",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@gitzone/tsrun": "^1.1.11",
"@gitzone/tsbundle": "^1.0.78",
"@gitzone/tsrun": "^1.2.12",
"@pushrocks/consolecolor": "^2.0.1",
"@pushrocks/smartfile": "^6.0.6",
"@pushrocks/smartlog": "^2.0.1",
"@pushrocks/smartpromise": "^2.0.5",
"@pushrocks/smartshell": "^2.0.6",
"@types/figures": "^2.0.0",
"figures": "^2.0.0"
}
"@pushrocks/smartbrowser": "^1.0.17",
"@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartexpress": "^3.0.76",
"@pushrocks/smartfile": "^8.0.0",
"@pushrocks/smartlog": "^2.0.39",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartshell": "^2.0.25",
"@pushrocks/tapbundle": "^3.2.9",
"@types/figures": "^3.0.1",
"figures": "^3.0.0"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
}

42
readme.md Normal file
View File

@ -0,0 +1,42 @@
# @gitzone/tstest
a test utility to run tests that match test/**/*.ts
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@gitzone/tstest)
* [gitlab.com (source)](https://gitlab.com/gitzone/tstest)
* [github.com (source mirror)](https://github.com/gitzone/tstest)
* [docs (typedoc)](https://gitzone.gitlab.io/tstest/)
## Status for master
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/gitzone/tstest/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/gitzone/tstest/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@gitzone/tstest)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/gitzone/tstest)](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/@gitzone/tstest)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@gitzone/tstest)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@gitzone/tstest)](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
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,9 +1,6 @@
import { TsTest } from './tstest.classes.tstest';
const cliRun = async () => {
if (process.env.CLI_CALL) {
const tsTestInstance = new TsTest(process.cwd(), process.argv[2]);
await tsTestInstance.run();
}
export const runCli = async () => {
const tsTestInstance = new TsTest(process.cwd(), process.argv[2]);
await tsTestInstance.run();
};
cliRun();

View File

@ -0,0 +1,65 @@
// ============
// combines different tap test files to an overall result
// ============
import * as plugins from './tstest.plugins';
import { coloredString as cs } from '@pushrocks/consolecolor';
import { TapParser } from './tstest.classes.tap.parser';
import * as logPrefixes from './tstest.logprefixes';
export class TapCombinator {
tapParserStore: TapParser[] = [];
addTapParser(tapParserArg: TapParser) {
this.tapParserStore.push(tapParserArg);
}
evaluate() {
console.log(
`${logPrefixes.TsTestPrefix} RESULTS FOR ${this.tapParserStore.length} TESTFILE(S):`
);
let failGlobal = false; // determine wether tstest should fail
for (const tapParser of this.tapParserStore) {
if (!tapParser.expectedTests) {
failGlobal = true;
let overviewString =
logPrefixes.TsTestPrefix +
cs(` ${tapParser.fileName} ${plugins.figures.cross}`, 'red') +
` ${plugins.figures.pointer} ` +
`does not specify tests!`;
console.log(overviewString);
} else if (tapParser.expectedTests !== tapParser.receivedTests) {
failGlobal = true;
let overviewString =
logPrefixes.TsTestPrefix +
cs(` ${tapParser.fileName} ${plugins.figures.cross}`, 'red') +
` ${plugins.figures.pointer} ` +
tapParser.getTestOverviewAsString() +
`did not execute all specified tests!`;
console.log(overviewString);
} else if (tapParser.getErrorTests().length === 0) {
let overviewString =
logPrefixes.TsTestPrefix +
cs(` ${tapParser.fileName} ${plugins.figures.tick}`, 'green') +
` ${plugins.figures.pointer} ` +
tapParser.getTestOverviewAsString();
console.log(overviewString);
} else {
failGlobal = true;
let overviewString =
logPrefixes.TsTestPrefix +
cs(` ${tapParser.fileName} ${plugins.figures.cross}`, 'red') +
` ${plugins.figures.pointer} ` +
tapParser.getTestOverviewAsString();
console.log(overviewString);
}
}
console.log(cs(plugins.figures.hamburger.repeat(48), 'cyan'));
if (!failGlobal) {
console.log(cs('FINAL RESULT: SUCCESS!', 'green'));
} else {
console.log(cs('FINAL RESULT: FAIL!', 'red'));
process.exit(1);
}
}
}

View File

@ -5,13 +5,13 @@ import { coloredString as cs } from '@pushrocks/consolecolor';
// combines different tap test files to an overall result
// ============
import * as plugins from './tstest.plugins';
import { TapTestResult } from './tstest.tap.testresult';
import { TapTestResult } from './tstest.classes.tap.testresult';
import * as logPrefixes from './tstest.logprefixes';
export class TapParser {
testStore: TapTestResult[] = [];
expectedTestsRegex = /([0-9]*)\.\.([0-9]*)/;
expectedTestsRegex = /([0-9]*)\.\.([0-9]*)$/;
expectedTests: number;
receivedTests: number;
@ -23,7 +23,6 @@ export class TapParser {
*/
constructor(public fileName: string) {}
private _getNewTapTestResult() {
this.activeTapTestResult = new TapTestResult(this.testStore.length + 1);
}
@ -45,10 +44,7 @@ export class TapParser {
const regexResult = this.expectedTestsRegex.exec(logLine);
this.expectedTests = parseInt(regexResult[2]);
console.log(
`${logPrefixes.TapPrefix} ${cs(
`Expecting ${this.expectedTests} tests!`,
'blue'
)}`
`${logPrefixes.TapPrefix} ${cs(`Expecting ${this.expectedTests} tests!`, 'blue')}`
);
// initiating first TapResult
@ -70,9 +66,7 @@ export class TapParser {
// test for protocol error
if (testId !== this.activeTapTestResult.id) {
console.log(
`${
logPrefixes.TapErrorPrefix
} Something is strange! Test Ids are not equal!`
`${logPrefixes.TapErrorPrefix} Something is strange! Test Ids are not equal!`
);
}
this.activeTapTestResult.setTestResult(testOk);
@ -80,14 +74,14 @@ export class TapParser {
if (testOk) {
console.log(
logPrefixes.TapPrefix,
`${cs(`T${testId} ${plugins.figures.tick}`, 'green')} | ` +
`${cs(`T${testId} ${plugins.figures.tick}`, 'green')} ${plugins.figures.arrowRight} ` +
cs(testSubject, 'blue') +
` | ${cs(`${testDuration} ms`, 'orange')}`
);
} else {
console.log(
logPrefixes.TapPrefix,
`${cs(`T${testId} ${plugins.figures.cross}`, 'red')} | ` +
`${cs(`T${testId} ${plugins.figures.cross}`, 'red')} ${plugins.figures.arrowRight} ` +
cs(testSubject, 'blue') +
` | ${cs(`${testDuration} ms`, 'orange')}`
);
@ -111,67 +105,98 @@ export class TapParser {
/**
* returns all tests that are not completed
*/
getUncompletedTests() {
public getUncompletedTests() {
// TODO:
}
/**
* returns all tests that threw an error
*/
getErrorTests() {
return this.testStore.filter(tapTestArg => {
public getErrorTests() {
return this.testStore.filter((tapTestArg) => {
return !tapTestArg.testOk;
});
}
async handleTapProcess(childProcessArg: ChildProcess) {
const done = plugins.smartpromise.defer();
childProcessArg.stdout.on('data', data => {
this._processLog(data);
});
childProcessArg.stderr.on('data', data => {
this._processLog(data);
});
childProcessArg.on('exit', () => {
this.receivedTests = this.testStore.length;
/**
* returns a test overview as string
*/
getTestOverviewAsString() {
let overviewString = '';
for (const test of this.testStore) {
if (overviewString !== '') {
overviewString += ' | ';
}
if (test.testOk) {
overviewString += cs(`T${test.id} ${plugins.figures.tick}`, 'green');
} else {
overviewString += cs(`T${test.id} ${plugins.figures.cross}`, 'red');
}
}
return overviewString;
}
// check wether all tests ran
if (this.expectedTests === this.receivedTests) {
console.log(
`${logPrefixes.TapPrefix} ${cs(
`${this.receivedTests} out of ${
this.expectedTests
} Tests completed!`,
'green'
)}`
);
} else {
console.log(
`${logPrefixes.TapErrorPrefix} ${cs(
`Only ${this.receivedTests} out of ${
this.expectedTests
} completed!`,
'red'
)}`
);
}
if (this.getErrorTests().length === 0) {
console.log(
`${logPrefixes.TapPrefix} ${cs(
`All tests are successfull!!!`,
'green'
)}`
);
} else {
console.log(
`${logPrefixes.TapPrefix} ${cs(
`${this.getErrorTests().length} tests threw an error!!!`,
'red'
)}`
);
}
/**
* handles a tap process
* @param childProcessArg
*/
public async handleTapProcess(childProcessArg: ChildProcess) {
const done = plugins.smartpromise.defer();
childProcessArg.stdout.on('data', (data) => {
this._processLog(data);
});
childProcessArg.stderr.on('data', (data) => {
this._processLog(data);
});
childProcessArg.on('exit', async () => {
await this._evaluateResult();
done.resolve();
});
await done.promise;
}
public async handleTapLog(tapLog: string) {
this._processLog(tapLog);
await this._evaluateResult();
}
private async _evaluateResult() {
this.receivedTests = this.testStore.length;
// check wether all tests ran
if (this.expectedTests === this.receivedTests) {
console.log(
`${logPrefixes.TapPrefix} ${cs(
`${this.receivedTests} out of ${this.expectedTests} Tests completed!`,
'green'
)}`
);
} else {
console.log(
`${logPrefixes.TapErrorPrefix} ${cs(
`Only ${this.receivedTests} out of ${this.expectedTests} completed!`,
'red'
)}`
);
}
if (!this.expectedTests) {
console.log(cs('Error: No tests were defined. Therefore the testfile failed!', 'red'));
} else if (this.expectedTests !== this.receivedTests) {
console.log(
cs(
'Error: The amount of received tests and expectedTests is unequal! Therefore the testfile failed',
'red'
)
);
} else if (this.getErrorTests().length === 0) {
console.log(`${logPrefixes.TapPrefix} ${cs(`All tests are successfull!!!`, 'green')}`);
} else {
console.log(
`${logPrefixes.TapPrefix} ${cs(
`${this.getErrorTests().length} tests threw an error!!!`,
'red'
)}`
);
}
}
}

View File

@ -3,9 +3,9 @@ import * as paths from './tstest.paths';
import { Smartfile } from '@pushrocks/smartfile';
// tap related stuff
import { TapCombinator } from './tstest.tap.combinator';
import { TapParser } from './tstest.tap.parser';
import { TapTestResult } from './tstest.tap.testresult';
import { TapCombinator } from './tstest.classes.tap.combinator';
import { TapParser } from './tstest.classes.tap.parser';
import { TapTestResult } from './tstest.classes.tap.testresult';
export class TestDirectory {
/**
@ -41,7 +41,7 @@ export class TestDirectory {
private async _init() {
this.testfileArray = await plugins.smartfile.fs.fileTreeToObject(
plugins.path.join(this.cwd, this.relativePath),
'**/*.ts'
'test*.ts'
);
}

View File

@ -5,11 +5,20 @@ import * as logPrefixes from './tstest.logprefixes';
import { coloredString as cs } from '@pushrocks/consolecolor';
import { TestDirectory } from './tstest.classes.testdirectory';
import { TapCombinator } from './tstest.tap.combinator';
import { TapParser } from './tstest.tap.parser';
import { TapCombinator } from './tstest.classes.tap.combinator';
import { TapParser } from './tstest.classes.tap.parser';
export class TsTest {
testDir: TestDirectory;
public testDir: TestDirectory;
public smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash',
pathDirectories: [paths.binDirectory],
sourceFilePaths: [],
});
public smartbrowserInstance = new plugins.smartbrowser.SmartBrowser();
public tsbundleInstance = new plugins.tsbundle.TsBundle();
constructor(cwdArg: string, relativePathToTestDirectory: string) {
this.testDir = new TestDirectory(cwdArg, relativePathToTestDirectory);
@ -17,28 +26,190 @@ export class TsTest {
async run() {
const fileNamesToRun: string[] = await this.testDir.getTestFilePathArray();
console.log(`${logPrefixes.TsTestPrefix} Found ${fileNamesToRun.length} Testfile(s):`);
console.log(cs(plugins.figures.hamburger.repeat(80), 'cyan'));
console.log('');
console.log(`${logPrefixes.TsTestPrefix} FOUND ${fileNamesToRun.length} TESTFILE(S):`);
for (const fileName of fileNamesToRun) {
console.log(`${logPrefixes.TsTestPrefix} ${cs(fileName, 'orange')}`);
}
console.log('-'.repeat(16));
console.log('-'.repeat(48));
console.log(''); // force new line
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash',
pathDirectories: [paths.binDirectory],
sourceFilePaths: []
});
const tapCombinator = new TapCombinator(); // lets create the TapCombinator
for (const fileName of fileNamesToRun) {
console.log(`${cs('=> ', 'blue')} Running ${cs(fileName, 'orange')}`);
console.log(cs(`=`.repeat(16), 'cyan'));
const tapParser = new TapParser(fileName);
const execResultStreaming = await smartshellInstance.execStreamingSilent(`tsrun ${fileName}`);
await tapParser.handleTapProcess(execResultStreaming.childProcess);
for (const fileNameArg of fileNamesToRun) {
switch (true) {
case fileNameArg.endsWith('.browser.ts'):
const tapParserBrowser = await this.runInChrome(fileNameArg);
tapCombinator.addTapParser(tapParserBrowser);
break;
case fileNameArg.endsWith('.both.ts'):
console.log('>>>>>>> TEST PART 1: chrome');
const tapParserBothBrowser = await this.runInChrome(fileNameArg);
tapCombinator.addTapParser(tapParserBothBrowser);
console.log(cs(`|`.repeat(16), 'cyan'));
console.log(''); // force new line
console.log('>>>>>>> TEST PART 2: node');
const tapParserBothNode = await this.runInNode(fileNameArg);
tapCombinator.addTapParser(tapParserBothBrowser);
break;
default:
const tapParserNode = await this.runInNode(fileNameArg);
tapCombinator.addTapParser(tapParserNode);
break;
}
console.log(cs(`^`.repeat(16), 'cyan'));
console.log(''); // force new line
tapCombinator.addTapParser(tapParser);
}
tapCombinator.evaluate();
}
public async runInNode(fileNameArg: string): Promise<TapParser> {
console.log(`${cs('=> ', 'blue')} Running ${cs(fileNameArg, 'orange')} in node.js runtime.`);
console.log(`${cs(`= `.repeat(32), 'cyan')}`);
const tapParser = new TapParser(fileNameArg + ':node');
// tsrun options
let tsrunOptions = '';
if (process.argv.includes('--web')) {
tsrunOptions += ' --web';
}
const execResultStreaming = await this.smartshellInstance.execStreamingSilent(
`tsrun ${fileNameArg}${tsrunOptions}`
);
await tapParser.handleTapProcess(execResultStreaming.childProcess);
return tapParser;
}
public async runInChrome(fileNameArg: string): Promise<TapParser> {
console.log(`${cs('=> ', 'blue')} Running ${cs(fileNameArg, 'orange')} in chromium runtime.`);
console.log(`${cs(`= `.repeat(32), 'cyan')}`);
// lets get all our paths sorted
const tsbundleCacheDirPath = plugins.path.join(paths.cwd, './.nogit/tstest_cache');
const bundleFileName = fileNameArg.replace('/', '__') + '.js';
const bundleFilePath = plugins.path.join(tsbundleCacheDirPath, bundleFileName);
// lets bundle the test
await plugins.smartfile.fs.ensureDir(tsbundleCacheDirPath);
await this.tsbundleInstance.buildTest(fileNameArg, bundleFilePath, 'parcel');
// lets create a server
const server = new plugins.smartexpress.Server({
cors: true,
port: 3007,
});
server.addRoute(
'/test',
new plugins.smartexpress.Handler('GET', async (req, res) => {
res.type('.html');
res.write(`
<html>
<head>
<script>
globalThis.testdom = true;
</script>
</head>
<body></body>
</html>
`);
res.end();
})
);
server.addRoute('*', new plugins.smartexpress.HandlerStatic(tsbundleCacheDirPath));
await server.start();
// lets do the browser bit
await this.smartbrowserInstance.start();
const evaluation = await this.smartbrowserInstance.evaluateOnPage(
`http://localhost:3007/test?bundleName=${bundleFileName}`,
async () => {
const convertToText = (obj) => {
// create an array that will later be joined into a string.
const stringArray = [];
if (typeof obj === 'object' && typeof obj.toString === 'function') {
stringArray.push(obj.toString());
} else if (typeof obj === 'object' && obj.join === undefined) {
stringArray.push('{');
for (const prop of Object.keys(obj)) {
stringArray.push(prop, ': ', convertToText(obj[prop]), ',');
}
stringArray.push('}');
// is array
} else if (typeof obj === 'object' && !(obj.join === undefined)) {
stringArray.push('[');
for (const prop of Object.keys(obj)) {
stringArray.push(convertToText(obj[prop]), ',');
}
stringArray.push(']');
// is function
} else if (typeof obj === 'function') {
stringArray.push(obj.toString());
// all other values can be done with JSON.stringify
} else {
stringArray.push(JSON.stringify(obj));
}
return stringArray.join('');
};
let logStore = '';
// tslint:disable-next-line: max-classes-per-file
const log = console.log.bind(console);
console.log = (...args) => {
args = args.map((argument) => {
return typeof argument !== 'string' ? convertToText(argument) : argument;
});
logStore += `${args}\n`;
log(...args);
};
const error = console.error;
console.error = (...args) => {
args = args.map((argument) => {
return typeof argument !== 'string' ? convertToText(argument) : argument;
});
logStore += `${args}\n`;
error(...args);
};
const bundleName = new URLSearchParams(window.location.search).get('bundleName');
console.log(`::TSTEST IN CHROMIUM:: Relevant Script name is: ${bundleName}`);
const bundleResponse = await fetch(`/${bundleName}`);
console.log(
`::TSTEST IN CHROMIUM:: Got ${bundleName} with STATUS ${bundleResponse.status}`
);
const bundle = await bundleResponse.text();
console.log(`::TSTEST IN CHROMIUM:: Executing ${bundleName}`);
try {
// tslint:disable-next-line: no-eval
eval(bundle);
} catch (err) {
console.error(err);
}
if (globalThis.tapbundleDeferred && globalThis.tapbundleDeferred.promise) {
await globalThis.tapbundleDeferred.promise;
} else {
console.log('Error: Could not find tapbundle Deferred');
}
return logStore;
}
);
await this.smartbrowserInstance.stop();
await server.stop();
console.log(
`${cs('=> ', 'blue')} Stopped ${cs(fileNameArg, 'orange')} chromium instance and server.`
);
console.log(`${cs('=> ', 'blue')} See the result captured from the chromium execution:`);
// lets create the tap parser
const tapParser = new TapParser(fileNameArg + ':chrome');
tapParser.handleTapLog(evaluation);
return tapParser;
}
public async runInDeno() {}
}

View File

@ -1,14 +1,37 @@
// node native
import * as path from 'path';
export { path };
// @pushrocks scope
import * as consolecolor from '@pushrocks/consolecolor';
import * as smartbrowser from '@pushrocks/smartbrowser';
import * as smartexpress from '@pushrocks/smartexpress';
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartfile from '@pushrocks/smartfile';
import * as smartlog from '@pushrocks/smartlog';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartshell from '@pushrocks/smartshell';
import * as tapbundle from '@pushrocks/tapbundle';
export {
consolecolor,
smartbrowser,
smartexpress,
smartdelay,
smartfile,
smartlog,
smartpromise,
smartshell,
tapbundle,
};
// @gitzone scope
import * as tsbundle from '@gitzone/tsbundle';
export { tsbundle };
// sindresorhus
import * as figures from 'figures';
export { consolecolor, figures, path, smartfile, smartlog, smartpromise, smartshell };
export { figures };

View File

@ -1,48 +0,0 @@
// ============
// combines different tap test files to an overall result
// ============
import * as plugins from './tstest.plugins';
import { coloredString as cs } from '@pushrocks/consolecolor';
import { TapParser } from './tstest.tap.parser';
import * as logPrefixes from './tstest.logprefixes';
export class TapCombinator {
tapParserStore: TapParser[] = [];
addTapParser(tapParserArg: TapParser) {
this.tapParserStore.push(tapParserArg);
}
evaluate() {
console.log(`${logPrefixes.TsTestPrefix} Ran ${this.tapParserStore.length} Testfiles!`);
console.log(`${logPrefixes.TsTestPrefix} Here are the overall results:`);
let failGlobal = false; // determine wether tstest should fail
for (const tapParser of this.tapParserStore) {
if(tapParser.getErrorTests().length === 0) {
console.log(
logPrefixes.TsTestPrefix +
cs(` ${tapParser.fileName} ${plugins.figures.tick}`, 'green') +
' | ' +
cs(` all tests completed successfully!`, 'blue')
)
} else {
console.log(
logPrefixes.TsTestPrefix +
cs(` ${tapParser.fileName} ${plugins.figures.cross}`, 'red') +
' | ' +
cs(` Errors ocurred, please check for the logs!`, 'blue')
);
failGlobal = true;
}
}
console.log(cs('-'.repeat(16), 'cyan'));
console.log(cs('*'.repeat(16), 'cyan'));
console.log(cs('-'.repeat(16), 'cyan'));
if(!failGlobal) {
console.log(cs('Ending with code 0: TESTS ARE PASSING!', 'green'));
} else {
console.log(cs('Ending with code 1: TESTS ARE FAILING!', 'red'));
}
}
}

View File

@ -1,3 +1,17 @@
{
"extends": "tslint-config-standard"
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}