fix(test result): now failing and succeeding correctly
This commit is contained in:
		| @@ -30,7 +30,7 @@ export class TsTest { | ||||
|     for (const fileName of fileNamesToRun) { | ||||
|       console.log(`${cs('=> ', 'blue')} Running ${cs(fileName, 'orange')}`); | ||||
|       console.log(cs(`=`.repeat(16), 'cyan')); | ||||
|       const tapParser = new TapParser(); | ||||
|       const tapParser = new TapParser(fileName); | ||||
|       const execResultStreaming = await smartshellInstance.execStreamingSilent(`tsrun ${fileName}`); | ||||
|       await tapParser.handleTapProcess(execResultStreaming.childProcess); | ||||
|       console.log(cs(`^`.repeat(16), 'cyan')); | ||||
|   | ||||
| @@ -1,3 +1,7 @@ | ||||
| import * as plugins from './tstest.plugins'; | ||||
| import { coloredString as cs } from '@pushrocks/consolecolor'; | ||||
|  | ||||
| export const TapPrefix = plugins.consolecolor.coloredString(`:::TAP:::`, 'pink', 'black'); | ||||
| export const TapPrefix = cs(`:::TAP:::`, 'pink', 'black'); | ||||
| export const TapErrorPrefix = cs(`!!!TAP PROTOCOL ERROR!!!`, 'red', 'black'); | ||||
|  | ||||
| export const TsTestPrefix = cs(`>>>TSTEST<<<`, 'pink', 'black'); | ||||
|   | ||||
| @@ -5,6 +5,7 @@ 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[] = []; | ||||
| @@ -13,8 +14,35 @@ export class TapCombinator { | ||||
|   } | ||||
|  | ||||
|   evaluate() { | ||||
|     console.log(`Ran ${this.tapParserStore.length} Testfiles!`); | ||||
|     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')); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -9,16 +9,23 @@ import { TapTestResult } from './tstest.tap.testresult'; | ||||
| import * as logPrefixes from './tstest.logprefixes'; | ||||
|  | ||||
| export class TapParser { | ||||
|   resultStore: TapTestResult[] = []; | ||||
|   testStore: TapTestResult[] = []; | ||||
|  | ||||
|   expectedTestsRegex = /([0-9]*)\.\.([0-9]*)/; | ||||
|   expectedTests: number; | ||||
|   receivedTests: number; | ||||
|  | ||||
|   testStatusRegex = /(ok|not\sok)\s([0-9]+)\s-\s(.*)\s#\stime=(.*)ms$/; | ||||
|   activeTapTestResult: TapTestResult; | ||||
|  | ||||
|   /** | ||||
|    * the constructor for TapParser | ||||
|    */ | ||||
|   constructor(public fileName: string) {} | ||||
|  | ||||
|  | ||||
|   private _getNewTapTestResult() { | ||||
|     this.activeTapTestResult = new TapTestResult(this.resultStore.length + 1); | ||||
|     this.activeTapTestResult = new TapTestResult(this.testStore.length + 1); | ||||
|   } | ||||
|  | ||||
|   private _processLog(logChunk: Buffer | string) { | ||||
| @@ -37,7 +44,12 @@ export class TapParser { | ||||
|         logLineIsTapProtocol = true; | ||||
|         const regexResult = this.expectedTestsRegex.exec(logLine); | ||||
|         this.expectedTests = parseInt(regexResult[2]); | ||||
|         console.log(`:::TAP::: Expecting ${this.expectedTests} tests!`); | ||||
|         console.log( | ||||
|           `${logPrefixes.TapPrefix} ${cs( | ||||
|             `Expecting ${this.expectedTests} tests!`, | ||||
|             'blue' | ||||
|           )}` | ||||
|         ); | ||||
|  | ||||
|         // initiating first TapResult | ||||
|         this._getNewTapTestResult(); | ||||
| @@ -57,23 +69,27 @@ export class TapParser { | ||||
|  | ||||
|         // test for protocol error | ||||
|         if (testId !== this.activeTapTestResult.id) { | ||||
|           console.log(`:::TAP PROTOCOL ERROR::: Something is strange! Test Ids are not equal!`); | ||||
|           console.log( | ||||
|             `${ | ||||
|               logPrefixes.TapErrorPrefix | ||||
|             } Something is strange! Test Ids are not equal!` | ||||
|           ); | ||||
|         } | ||||
|         this.activeTapTestResult.setTestResult(testOk); | ||||
|  | ||||
|         if (testOk) { | ||||
|           console.log( | ||||
|             logPrefixes.TapPrefix, | ||||
|             ` ${cs(`T${testId} ${plugins.figures.tick}`, 'green')} | ` + | ||||
|             cs(testSubject, 'blue') + | ||||
|             ` | ${cs(`${testDuration} milliseconds`, 'orange')}` | ||||
|             `${cs(`T${testId} ${plugins.figures.tick}`, 'green')} | ` + | ||||
|               cs(testSubject, 'blue') + | ||||
|               ` | ${cs(`${testDuration} ms`, 'orange')}` | ||||
|           ); | ||||
|         } else { | ||||
|           console.log( | ||||
|             logPrefixes.TapPrefix, | ||||
|             ` ${cs(`T${testId} ${plugins.figures.cross}`, 'red')} | ` + | ||||
|             cs(testSubject, 'blue') + | ||||
|             ` | ${cs(`${testDuration} milliseconds`, 'orange')}` | ||||
|             `${cs(`T${testId} ${plugins.figures.cross}`, 'red')} | ` + | ||||
|               cs(testSubject, 'blue') + | ||||
|               ` | ${cs(`${testDuration} ms`, 'orange')}` | ||||
|           ); | ||||
|         } | ||||
|       } | ||||
| @@ -86,12 +102,28 @@ export class TapParser { | ||||
|       } | ||||
|  | ||||
|       if (this.activeTapTestResult && this.activeTapTestResult.testSettled) { | ||||
|         this.resultStore.push(this.activeTapTestResult); | ||||
|         this.testStore.push(this.activeTapTestResult); | ||||
|         this._getNewTapTestResult(); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * returns all tests that are not completed | ||||
|    */ | ||||
|   getUncompletedTests() { | ||||
|     // TODO: | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * returns all tests that threw an error | ||||
|    */ | ||||
|   getErrorTests() { | ||||
|     return this.testStore.filter(tapTestArg => { | ||||
|       return !tapTestArg.testOk; | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   async handleTapProcess(childProcessArg: ChildProcess) { | ||||
|     const done = plugins.smartpromise.defer(); | ||||
|     childProcessArg.stdout.on('data', data => { | ||||
| @@ -101,6 +133,43 @@ export class TapParser { | ||||
|       this._processLog(data); | ||||
|     }); | ||||
|     childProcessArg.on('exit', () => { | ||||
|       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' | ||||
|           )}` | ||||
|         ); | ||||
|       } | ||||
|       done.resolve(); | ||||
|     }); | ||||
|     await done.promise; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user