feat(implement testing): update

This commit is contained in:
Philipp Kunz 2018-08-04 14:23:07 +02:00
parent a5ace2fa49
commit 662c472055
9 changed files with 164 additions and 22 deletions

11
package-lock.json generated
View File

@ -24,6 +24,14 @@
"typescript": "^2.9.1" "typescript": "^2.9.1"
} }
}, },
"@pushrocks/consolecolor": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@pushrocks/consolecolor/-/consolecolor-2.0.1.tgz",
"integrity": "sha512-iOFCHVeFZ2OywbdwSxVI4/wokkcLrXVdHLgvMmkNhJ220eeLgjNZWx3EJo3vNW3zq5ybCSCUIq0878djBxrWpw==",
"requires": {
"ansi-256-colors": "^1.1.0"
}
},
"@pushrocks/smartdelay": { "@pushrocks/smartdelay": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/@pushrocks/smartdelay/-/smartdelay-2.0.1.tgz", "resolved": "https://registry.npmjs.org/@pushrocks/smartdelay/-/smartdelay-2.0.1.tgz",
@ -161,8 +169,7 @@
"ansi-256-colors": { "ansi-256-colors": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/ansi-256-colors/-/ansi-256-colors-1.1.0.tgz", "resolved": "https://registry.npmjs.org/ansi-256-colors/-/ansi-256-colors-1.1.0.tgz",
"integrity": "sha1-kQ3lDvzHwJ49gvL4er1rcAwYgYo=", "integrity": "sha1-kQ3lDvzHwJ49gvL4er1rcAwYgYo="
"dev": true
}, },
"argparse": { "argparse": {
"version": "1.0.10", "version": "1.0.10",

View File

@ -20,6 +20,7 @@
}, },
"dependencies": { "dependencies": {
"@gitzone/tsrun": "^1.1.9", "@gitzone/tsrun": "^1.1.9",
"@pushrocks/consolecolor": "^2.0.1",
"@pushrocks/smartfile": "^6.0.3", "@pushrocks/smartfile": "^6.0.3",
"@pushrocks/smartlog": "^2.0.1", "@pushrocks/smartlog": "^2.0.1",
"@pushrocks/smartpromise": "^2.0.5", "@pushrocks/smartpromise": "^2.0.5",

1
test/sandbox-npmts Submodule

@ -0,0 +1 @@
Subproject commit 0d623adeab09ca0861da5b669454aaa24d8f3669

View File

@ -1,7 +1,9 @@
import * as plugins from './tstest.plugins'; import * as plugins from "./tstest.plugins";
import { TestDirectory } from './tstest.classes.testdirectory'; import { coloredString as cs } from '@pushrocks/consolecolor';
import { TapCombinator } from './tstest.tap.combinator';
import { TapParser } from './tstest.tap.parser'; import { TestDirectory } from "./tstest.classes.testdirectory";
import { TapCombinator } from "./tstest.tap.combinator";
import { TapParser } from "./tstest.tap.parser";
export class TsTest { export class TsTest {
testDir: TestDirectory; testDir: TestDirectory;
@ -12,19 +14,26 @@ export class TsTest {
async run() { async run() {
const fileNamesToRun: string[] = await this.testDir.getTestFilePathArray(); const fileNamesToRun: string[] = await this.testDir.getTestFilePathArray();
console.log(`Found ${fileNamesToRun.length} test(s):`); console.log(`Found ${fileNamesToRun.length} Testfile(s):`);
for (const fileName of fileNamesToRun) { for (const fileName of fileNamesToRun) {
console.log(fileName); console.log(cs(fileName, "orange"));
} }
console.log("-".repeat(16));
const smartshellInstance = new plugins.smartshell.Smartshell({ const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash', executor: "bash",
sourceFilePaths: [] sourceFilePaths: []
}); });
const tapCombinator = new TapCombinator(); // lets create the TapCombinator const tapCombinator = new TapCombinator(); // lets create the TapCombinator
for (const fileName of fileNamesToRun) { for (const fileName of fileNamesToRun) {
console.log(`${cs("=> ", "blue")} Running ${cs(fileName, "orange")}`);
console.log(`=`.repeat(16));
const tapParser = new TapParser(); const tapParser = new TapParser();
const execResultStreaming = await smartshellInstance.execStreamingSilent(`tsrun ${fileName}`); const execResultStreaming = await smartshellInstance.execStreamingSilent(
`tsrun ${fileName}`
);
await tapParser.handleTapProcess(execResultStreaming.childProcess); await tapParser.handleTapProcess(execResultStreaming.childProcess);
tapCombinator.addTapParser(tapParser);
} }
tapCombinator.evaluate();
} }
} }

7
ts/tstest.logprefixes.ts Normal file
View File

@ -0,0 +1,7 @@
import * as plugins from './tstest.plugins';
export const TapPrefix = plugins.consolecolor.coloredString(
`:::TAP:::`,
'green',
'black'
)

View File

@ -1,7 +1,11 @@
// node native
import * as path from 'path'; import * as path from 'path';
// @pushrocks scope
import * as consolecolor from '@pushrocks/consolecolor';
import * as smartfile from '@pushrocks/smartfile'; import * as smartfile from '@pushrocks/smartfile';
import * as smartlog from '@pushrocks/smartlog'; import * as smartlog from '@pushrocks/smartlog';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
import * as smartshell from '@pushrocks/smartshell'; import * as smartshell from '@pushrocks/smartshell';
export { path, smartfile, smartlog, smartpromise, smartshell }; export { consolecolor, path, smartfile, smartlog, smartpromise, smartshell };

View File

@ -2,10 +2,20 @@
// combines different tap test files to an overall result // combines different tap test files to an overall result
// ============ // ============
import * as plugins from './tstest.plugins'; import * as plugins from './tstest.plugins';
import { coloredString as cs } from '@pushrocks/consolecolor';
import { TapParser } from './tstest.tap.parser'; import { TapParser } from './tstest.tap.parser';
export class TapCombinator { export class TapCombinator {
tapParserStore: TapParser[] = [];
addTapParser(tapParserArg: TapParser) { addTapParser(tapParserArg: TapParser) {
this.tapParserStore.push(tapParserArg);
}
evaluate() {
console.log(`Ran ${this.tapParserStore.length} Testfiles!`);
for (const tapParser of this.tapParserStore) {
}
} }
} }

View File

@ -1,26 +1,107 @@
import { ChildProcess } from 'child_process'; import { ChildProcess } from "child_process";
import { coloredString as cs } from '@pushrocks/consolecolor';
// ============ // ============
// combines different tap test files to an overall result // combines different tap test files to an overall result
// ============ // ============
import * as plugins from './tstest.plugins'; import * as plugins from "./tstest.plugins";
import { TapTestResult } from './tstest.tap.testresult'; import { TapTestResult } from "./tstest.tap.testresult";
export class TapParser { export class TapParser {
resultStore: TapTestResult[] = []; resultStore: TapTestResult[] = [];
expectedTestsRegex = /([0-9]*)\.\.([0-9]*)/;
expectedTests: number; expectedTests: number;
processLog(logChunk: Buffer | string) { testStatusRegex = /(ok|not\sok)\s([0-9]+)\s-\s/;
if(Buffer.isBuffer(logChunk)) { activeTapTestResult: TapTestResult;
private _getNewTapTestResult () {
this.activeTapTestResult = new TapTestResult(
this.resultStore.length + 1
);
}
private _processLog(logChunk: Buffer | string) {
if (Buffer.isBuffer(logChunk)) {
logChunk = logChunk.toString(); logChunk = logChunk.toString();
} }
const logLineArray = logChunk.split('\n'); const logLineArray = logChunk.split("\n");
console.log(logLineArray); if (logLineArray[logLineArray.length - 1] === "") {
logLineArray.pop();
}
// lets parse the log information
for (const logLine of logLineArray) {
let logLineIsTapProtocol = false;
if (!this.expectedTests && this.expectedTestsRegex.test(logLine)) {
logLineIsTapProtocol = true;
const regexResult = this.expectedTestsRegex.exec(logLine);
this.expectedTests = parseInt(regexResult[2]);
console.log(`:::TAP::: Expecting ${this.expectedTests} tests!`);
// initiating first TapResult
this._getNewTapTestResult();
} else if (this.testStatusRegex.test(logLine)) {
logLineIsTapProtocol = true;
const regexResult = this.testStatusRegex.exec(logLine);
const testId = parseInt(regexResult[2]);
const testOk = (() => {
if (regexResult[1] === "ok") {
return true;
}
return false;
})();
// test for protocol error
if(testId !== this.activeTapTestResult.id) {
console.log(`:::TAP PROTOCOL ERROR::: Something is strange! Test Ids are not equal!`)
}
this.activeTapTestResult.setTestResult(testOk);
if(testOk) {
console.log(
cs(
`:::TAP::: Success: Test ${testId} is ok!`,
'green',
'black'
));
} else {
console.log(
cs(
`:::TAP::: Error: Test ${testId} is NOT ok!`,
'green',
'black'
));
}
}
if (!logLineIsTapProtocol) {
if (this.activeTapTestResult) {
this.activeTapTestResult.addLogLine(logLine);
}
console.log(logLine);
}
if(this.activeTapTestResult && this.activeTapTestResult.testSettled) {
this.resultStore.push(this.activeTapTestResult);
this._getNewTapTestResult();
}
}
} }
async handleTapProcess(childProcessArg: ChildProcess) { async handleTapProcess(childProcessArg: ChildProcess) {
const done = plugins.smartpromise.defer(); const done = plugins.smartpromise.defer();
childProcessArg.stdout.on("data", data => {
this._processLog(data);
});
childProcessArg.stderr.on("data", data => {
this._processLog(data);
});
childProcessArg.on("exit", () => {
done.resolve();
});
await done.promise; await done.promise;
} }
} }

View File

@ -3,4 +3,26 @@
// ============ // ============
import * as plugins from './tstest.plugins'; import * as plugins from './tstest.plugins';
export class TapTestResult {} export class TapTestResult {
testLogBuffer = Buffer.from('');
testOk: boolean = false;
testSettled: boolean = false;
constructor(public id: number) {
}
/**
* adds a logLine to the log buffer of the test
* @param logLine
*/
addLogLine(logLine: string) {
logLine = logLine + '\n';
const logLineBuffer = Buffer.from(logLine);
this.testLogBuffer = Buffer.concat([this.testLogBuffer, logLineBuffer]);
}
setTestResult(testOkArg: boolean) {
this.testOk = testOkArg;
this.testSettled = true;
}
}