Compare commits

..

4 Commits

Author SHA1 Message Date
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
4 changed files with 163 additions and 63 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@gitzone/tstest", "name": "@gitzone/tstest",
"version": "1.0.34", "version": "1.0.36",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@gitzone/tstest", "name": "@gitzone/tstest",
"version": "1.0.34", "version": "1.0.36",
"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",
@ -11,7 +11,7 @@
"tstest": "./cli.js" "tstest": "./cli.js"
}, },
"scripts": { "scripts": {
"test": "(npm run cleanUp && 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", "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/ --web", "tstest": "cd .nogit/sandbox-npmts && node ../../cli.ts.js test/ --web",
"cleanUp": "rm -rf .nogit/sandbox-npmts", "cleanUp": "rm -rf .nogit/sandbox-npmts",

View File

@ -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,54 @@ 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.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

@ -39,7 +39,7 @@ export class TsTest {
const tapCombinator = new TapCombinator(); // lets create the TapCombinator const tapCombinator = new TapCombinator(); // lets create the TapCombinator
for (const fileNameArg of fileNamesToRun) { for (const fileNameArg of fileNamesToRun) {
let tapParser: TapParser; let tapParser: TapParser;
switch(true) { switch (true) {
case fileNameArg.endsWith('.browser.ts'): case fileNameArg.endsWith('.browser.ts'):
tapParser = await this.runInChrome(fileNameArg); tapParser = await this.runInChrome(fileNameArg);
break; break;
@ -48,6 +48,8 @@ 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();
} }
@ -67,8 +69,6 @@ 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;
} }
@ -88,35 +88,130 @@ export class TsTest {
// lets create a server // lets create a server
const server = new plugins.smartexpress.Server({ const server = new plugins.smartexpress.Server({
cors: true, cors: true,
port: 3007 port: 3007,
}); });
server.addRoute('/test', new plugins.smartexpress.Handler('GET', async (req, res) => { server.addRoute(
res.type('.html'); '/test',
res.write(` new plugins.smartexpress.Handler('GET', async (req, res) => {
res.type('.html');
res.write(`
<html> <html>
<head></head> <head>
<script>
globalThis.testdom = true;
</script>
</head>
<body></body> <body></body>
</html> </html>
`); `);
res.end(); res.end();
})); })
);
server.addRoute('*', new plugins.smartexpress.HandlerStatic(tsbundleCacheDirPath)); server.addRoute('*', new plugins.smartexpress.HandlerStatic(tsbundleCacheDirPath));
await server.start(); await server.start();
// lets do the browser bit // lets do the browser bit
await this.smartbrowserInstance.start(); await this.smartbrowserInstance.start();
const evaluation = await this.smartbrowserInstance.evaluateOnPage('http://localhost:3007/test', async () => { const evaluation = await this.smartbrowserInstance.evaluateOnPage(
const logStore = 'hello'; `http://localhost:3007/test?bundleName=${bundleFileName}`,
const log = console.log.bind(console); async () => {
console.log = (...args) => { let logStore = 'Starting log capture\n';
log('My Console!!!'); // tslint:disable-next-line: max-classes-per-file
log(...args); class Deferred<T> {
}; public promise: Promise<T>;
const script = document.createElement('script'); public resolve;
script.src = '/test__test.browser.ts.js'; public reject;
document.head.appendChild(script); public status;
return logStore;
}); 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) => {
// create an array that will later be joined into a string.
const stringArray = [];
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('');
};
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 bundle = await (await fetch('/test__test.browser.ts.js')).text();
try {
// tslint:disable-next-line: no-eval
eval(bundle);
} catch (err) {
console.error(err);
}
setTimeout(() => {
console.log(globalThis.testdom);
done.resolve();
}, 5000);
await done.promise;
return logStore;
}
);
await plugins.smartdelay.delayFor(1000); await plugins.smartdelay.delayFor(1000);
await this.smartbrowserInstance.stop(); await this.smartbrowserInstance.stop();
console.log(`${cs('=> ', 'blue')} Stopped ${cs(fileNameArg, 'orange')} chromium instance.`); console.log(`${cs('=> ', 'blue')} Stopped ${cs(fileNameArg, 'orange')} chromium instance.`);