Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
0ea621cb99 | |||
984d551bd6 | |||
4066d9b0e8 | |||
f24ff2f79e | |||
9d37fcf734 | |||
f7524179d7 | |||
19d6b52ddb | |||
cf69e5436c | |||
6bee853cd2 | |||
4aa731b531 | |||
a849f36a1b | |||
30284b770c |
29
package-lock.json
generated
29
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@gitzone/tstest",
|
"name": "@gitzone/tstest",
|
||||||
"version": "1.0.35",
|
"version": "1.0.41",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -1567,16 +1567,31 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@pushrocks/tapbundle": {
|
"@pushrocks/tapbundle": {
|
||||||
"version": "3.2.1",
|
"version": "3.2.7",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.2.1.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.2.7.tgz",
|
||||||
"integrity": "sha512-D3o205SE+Viu8sukm+6CvGkXEwOiQiEEcga9eWyvjWS4vDx6FWwrO0pNZkQq6GqsKQ9xRpCmBtI7F3KsJR0+PA==",
|
"integrity": "sha512-RBRjuJs3v/biKypc9rSecApn7IXRdmr/jbVH86+2mDxyzUQ8IcMhaKhUrIjKoNyvxvMAMS2j+OxPyiOCnK6RAw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@pushrocks/early": "^3.0.3",
|
"@pushrocks/smartdelay": "^2.0.9",
|
||||||
"@pushrocks/smartdelay": "^2.0.3",
|
"@pushrocks/smartenv": "^4.0.10",
|
||||||
"@pushrocks/smartfile": "^7.0.9",
|
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
|
"@pushrocks/smarttime": "^3.0.19",
|
||||||
"smartchai": "^2.0.1"
|
"smartchai": "^2.0.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@pushrocks/smarttime": {
|
||||||
|
"version": "3.0.19",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmarttime/-/smarttime-3.0.19.tgz",
|
||||||
|
"integrity": "sha512-1iSkNJcF632Mikcd/EvcBPC1T5tLRZqTHjVkuZlXpaNY11eZIzYVMOn5/ZDfLp2GuEi6hhIbEx9zwsdoYqz5cA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@pushrocks/smartdelay": "^2.0.9",
|
||||||
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
|
"croner": "^1.1.23",
|
||||||
|
"dayjs": "^1.8.27",
|
||||||
|
"is-nan": "^1.3.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@pushrocks/webrequest": {
|
"@pushrocks/webrequest": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@gitzone/tstest",
|
"name": "@gitzone/tstest",
|
||||||
"version": "1.0.35",
|
"version": "1.0.41",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a test utility to run tests that match test/**/*.ts",
|
"description": "a test utility to run tests that match test/**/*.ts",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -19,7 +19,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.17",
|
"@gitzone/tsbuild": "^2.1.17",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@pushrocks/tapbundle": "^3.2.7",
|
||||||
"tslint": "^6.1.2",
|
"tslint": "^6.1.2",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
|
@ -20,7 +20,15 @@ export class TapCombinator {
|
|||||||
|
|
||||||
let failGlobal = false; // determine wether tstest should fail
|
let failGlobal = false; // determine wether tstest should fail
|
||||||
for (const tapParser of this.tapParserStore) {
|
for (const tapParser of this.tapParserStore) {
|
||||||
if (tapParser.getErrorTests().length === 0) {
|
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.getErrorTests().length === 0) {
|
||||||
let overviewString =
|
let overviewString =
|
||||||
logPrefixes.TsTestPrefix +
|
logPrefixes.TsTestPrefix +
|
||||||
cs(` ${tapParser.fileName} ${plugins.figures.tick}`, 'green') +
|
cs(` ${tapParser.fileName} ${plugins.figures.tick}`, 'green') +
|
||||||
@ -28,13 +36,13 @@ export class TapCombinator {
|
|||||||
tapParser.getTestOverviewAsString();
|
tapParser.getTestOverviewAsString();
|
||||||
console.log(overviewString);
|
console.log(overviewString);
|
||||||
} else {
|
} else {
|
||||||
|
failGlobal = true;
|
||||||
let overviewString =
|
let overviewString =
|
||||||
logPrefixes.TsTestPrefix +
|
logPrefixes.TsTestPrefix +
|
||||||
cs(` ${tapParser.fileName} ${plugins.figures.cross}`, 'red') +
|
cs(` ${tapParser.fileName} ${plugins.figures.cross}`, 'red') +
|
||||||
` ${plugins.figures.pointer} ` +
|
` ${plugins.figures.pointer} ` +
|
||||||
tapParser.getTestOverviewAsString();
|
tapParser.getTestOverviewAsString();
|
||||||
console.log(overviewString);
|
console.log(overviewString);
|
||||||
failGlobal = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(cs(plugins.figures.hamburger.repeat(48), 'cyan'));
|
console.log(cs(plugins.figures.hamburger.repeat(48), 'cyan'));
|
||||||
|
@ -113,7 +113,7 @@ export class TapParser {
|
|||||||
* returns all tests that threw an error
|
* returns all tests that threw an error
|
||||||
*/
|
*/
|
||||||
public getErrorTests() {
|
public getErrorTests() {
|
||||||
return this.testStore.filter(tapTestArg => {
|
return this.testStore.filter((tapTestArg) => {
|
||||||
return !tapTestArg.testOk;
|
return !tapTestArg.testOk;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -140,49 +140,58 @@ export class TapParser {
|
|||||||
* handles a tap process
|
* handles a tap process
|
||||||
* @param childProcessArg
|
* @param childProcessArg
|
||||||
*/
|
*/
|
||||||
async handleTapProcess(childProcessArg: ChildProcess) {
|
public async handleTapProcess(childProcessArg: ChildProcess) {
|
||||||
const done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
childProcessArg.stdout.on('data', data => {
|
childProcessArg.stdout.on('data', (data) => {
|
||||||
this._processLog(data);
|
this._processLog(data);
|
||||||
});
|
});
|
||||||
childProcessArg.stderr.on('data', data => {
|
childProcessArg.stderr.on('data', (data) => {
|
||||||
this._processLog(data);
|
this._processLog(data);
|
||||||
});
|
});
|
||||||
childProcessArg.on('exit', () => {
|
childProcessArg.on('exit', async () => {
|
||||||
this.receivedTests = this.testStore.length;
|
await this._evaluateResult();
|
||||||
|
|
||||||
// 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'
|
|
||||||
)}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
done.resolve();
|
done.resolve();
|
||||||
});
|
});
|
||||||
await done.promise;
|
await done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
public handleTapLog(tapLog: string) {
|
public async handleTapLog(tapLog: string) {
|
||||||
this._processLog(tapLog);
|
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'
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import { coloredString as cs } from '@pushrocks/consolecolor';
|
|||||||
import { TestDirectory } from './tstest.classes.testdirectory';
|
import { TestDirectory } from './tstest.classes.testdirectory';
|
||||||
import { TapCombinator } from './tstest.classes.tap.combinator';
|
import { TapCombinator } from './tstest.classes.tap.combinator';
|
||||||
import { TapParser } from './tstest.classes.tap.parser';
|
import { TapParser } from './tstest.classes.tap.parser';
|
||||||
import { threeEighths } from 'figures';
|
|
||||||
|
|
||||||
export class TsTest {
|
export class TsTest {
|
||||||
public testDir: TestDirectory;
|
public testDir: TestDirectory;
|
||||||
@ -48,13 +47,15 @@ export class TsTest {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tapCombinator.addTapParser(tapParser);
|
tapCombinator.addTapParser(tapParser);
|
||||||
|
console.log(cs(`^`.repeat(16), 'cyan'));
|
||||||
|
console.log(''); // force new line
|
||||||
}
|
}
|
||||||
tapCombinator.evaluate();
|
tapCombinator.evaluate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async runInNode(fileNameArg: string): Promise<TapParser> {
|
public async runInNode(fileNameArg: string): Promise<TapParser> {
|
||||||
console.log(`${cs('=> ', 'blue')} Running ${cs(fileNameArg, 'orange')} in node.js runtime.`);
|
console.log(`${cs('=> ', 'blue')} Running ${cs(fileNameArg, 'orange')} in node.js runtime.`);
|
||||||
console.log(cs(`=`.repeat(16), 'cyan'));
|
console.log(`${cs(`= `.repeat(32), 'cyan')}`);
|
||||||
const tapParser = new TapParser(fileNameArg);
|
const tapParser = new TapParser(fileNameArg);
|
||||||
|
|
||||||
// tsrun options
|
// tsrun options
|
||||||
@ -67,14 +68,12 @@ export class TsTest {
|
|||||||
`tsrun ${fileNameArg}${tsrunOptions}`
|
`tsrun ${fileNameArg}${tsrunOptions}`
|
||||||
);
|
);
|
||||||
await tapParser.handleTapProcess(execResultStreaming.childProcess);
|
await tapParser.handleTapProcess(execResultStreaming.childProcess);
|
||||||
console.log(cs(`^`.repeat(16), 'cyan'));
|
|
||||||
console.log(''); // force new line
|
|
||||||
return tapParser;
|
return tapParser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async runInChrome(fileNameArg: string): Promise<TapParser> {
|
public async runInChrome(fileNameArg: string): Promise<TapParser> {
|
||||||
console.log(`${cs('=> ', 'blue')} Running ${cs(fileNameArg, 'orange')} in chromium runtime.`);
|
console.log(`${cs('=> ', 'blue')} Running ${cs(fileNameArg, 'orange')} in chromium runtime.`);
|
||||||
console.log(cs(`=`.repeat(16), 'cyan'));
|
console.log(`${cs(`= `.repeat(32), 'cyan')}`);
|
||||||
|
|
||||||
// lets get all our paths sorted
|
// lets get all our paths sorted
|
||||||
const tsbundleCacheDirPath = plugins.path.join(paths.cwd, './.nogit/tstest_cache');
|
const tsbundleCacheDirPath = plugins.path.join(paths.cwd, './.nogit/tstest_cache');
|
||||||
@ -115,47 +114,13 @@ export class TsTest {
|
|||||||
const evaluation = await this.smartbrowserInstance.evaluateOnPage(
|
const evaluation = await this.smartbrowserInstance.evaluateOnPage(
|
||||||
`http://localhost:3007/test?bundleName=${bundleFileName}`,
|
`http://localhost:3007/test?bundleName=${bundleFileName}`,
|
||||||
async () => {
|
async () => {
|
||||||
let logStore = 'Starting log capture\n';
|
|
||||||
// tslint:disable-next-line: max-classes-per-file
|
|
||||||
class Deferred<T> {
|
|
||||||
public promise: Promise<T>;
|
|
||||||
public resolve;
|
|
||||||
public reject;
|
|
||||||
public status;
|
|
||||||
|
|
||||||
public startedAt: number;
|
|
||||||
public stoppedAt: number;
|
|
||||||
public get duration(): number {
|
|
||||||
if (this.stoppedAt) {
|
|
||||||
return this.stoppedAt - this.startedAt;
|
|
||||||
} else {
|
|
||||||
return Date.now() - this.startedAt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.promise = new Promise<T>((resolve, reject) => {
|
|
||||||
this.resolve = (valueArg: T | PromiseLike<T>) => {
|
|
||||||
this.status = 'fulfilled';
|
|
||||||
this.stoppedAt = Date.now();
|
|
||||||
resolve(valueArg);
|
|
||||||
};
|
|
||||||
this.reject = (reason: any) => {
|
|
||||||
this.status = 'rejected';
|
|
||||||
this.stoppedAt = Date.now();
|
|
||||||
reject(reason);
|
|
||||||
};
|
|
||||||
this.startedAt = Date.now();
|
|
||||||
this.status = 'pending';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const done = new Deferred();
|
|
||||||
const convertToText = (obj) => {
|
const convertToText = (obj) => {
|
||||||
// create an array that will later be joined into a string.
|
// create an array that will later be joined into a string.
|
||||||
const stringArray = [];
|
const stringArray = [];
|
||||||
|
|
||||||
if (typeof obj === 'object' && obj.join === undefined) {
|
if (typeof obj === 'object' && typeof obj.toString === 'function') {
|
||||||
|
stringArray.push(obj.toString());
|
||||||
|
} else if (typeof obj === 'object' && obj.join === undefined) {
|
||||||
stringArray.push('{');
|
stringArray.push('{');
|
||||||
for (const prop of Object.keys(obj)) {
|
for (const prop of Object.keys(obj)) {
|
||||||
stringArray.push(prop, ': ', convertToText(obj[prop]), ',');
|
stringArray.push(prop, ': ', convertToText(obj[prop]), ',');
|
||||||
@ -181,6 +146,9 @@ export class TsTest {
|
|||||||
|
|
||||||
return stringArray.join('');
|
return stringArray.join('');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let logStore = '';
|
||||||
|
// tslint:disable-next-line: max-classes-per-file
|
||||||
const log = console.log.bind(console);
|
const log = console.log.bind(console);
|
||||||
console.log = (...args) => {
|
console.log = (...args) => {
|
||||||
args = args.map((argument) => {
|
args = args.map((argument) => {
|
||||||
@ -197,26 +165,31 @@ export class TsTest {
|
|||||||
logStore += `${args}\n`;
|
logStore += `${args}\n`;
|
||||||
error(...args);
|
error(...args);
|
||||||
};
|
};
|
||||||
const bundle = await (await fetch('/test__test.browser.ts.js')).text();
|
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 {
|
try {
|
||||||
// tslint:disable-next-line: no-eval
|
// tslint:disable-next-line: no-eval
|
||||||
eval(bundle);
|
eval(bundle);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
|
||||||
console.log(globalThis.testdom);
|
if (globalThis.tapbundleDeferred && globalThis.tapbundleDeferred.promise) {
|
||||||
done.resolve();
|
await globalThis.tapbundleDeferred.promise;
|
||||||
}, 5000);
|
} else {
|
||||||
await done.promise;
|
console.log('Error: Could not find tapbundle Deferred');
|
||||||
|
}
|
||||||
return logStore;
|
return logStore;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
await plugins.smartdelay.delayFor(1000);
|
|
||||||
await this.smartbrowserInstance.stop();
|
await this.smartbrowserInstance.stop();
|
||||||
console.log(`${cs('=> ', 'blue')} Stopped ${cs(fileNameArg, 'orange')} chromium instance.`);
|
|
||||||
await server.stop();
|
await server.stop();
|
||||||
console.log(`${cs('=> ', 'blue')} Stopped ${cs(fileNameArg, 'orange')} server.`);
|
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
|
// lets create the tap parser
|
||||||
const tapParser = new TapParser(fileNameArg);
|
const tapParser = new TapParser(fileNameArg);
|
||||||
tapParser.handleTapLog(evaluation);
|
tapParser.handleTapLog(evaluation);
|
||||||
|
Reference in New Issue
Block a user