This commit is contained in:
2018-08-03 19:18:42 +02:00
commit a5ace2fa49
17 changed files with 1224 additions and 0 deletions

9
ts/index.ts Normal file
View File

@ -0,0 +1,9 @@
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();
}
};
cliRun();

View File

@ -0,0 +1,57 @@
import * as plugins from './tstest.plugins';
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';
export class TestDirectory {
/**
* the current working directory
*/
cwd: string;
/**
* the relative location of the test dir
*/
relativePath: string;
/**
* the absolute path of the test dir
*/
absolutePath: string;
/**
* an array of Smartfiles
*/
testfileArray: Smartfile[] = [];
/**
* the constructor for TestDirectory
* tell it the path
* @param pathToTestDirectory
*/
constructor(cwdArg: string, relativePathToTestDirectory: string) {
this.cwd = cwdArg;
this.relativePath = relativePathToTestDirectory;
}
private async _init() {
this.testfileArray = await plugins.smartfile.fs.fileTreeToObject(
plugins.path.join(this.cwd, this.relativePath),
'**/*.ts'
);
}
async getTestFilePathArray() {
await this._init();
const testFilePaths: string[] = [];
for (const testFile of this.testfileArray) {
const filePath = plugins.path.join(this.relativePath, testFile.path);
testFilePaths.push(filePath);
}
return testFilePaths;
}
}

View File

@ -0,0 +1,30 @@
import * as plugins from './tstest.plugins';
import { TestDirectory } from './tstest.classes.testdirectory';
import { TapCombinator } from './tstest.tap.combinator';
import { TapParser } from './tstest.tap.parser';
export class TsTest {
testDir: TestDirectory;
constructor(cwdArg: string, relativePathToTestDirectory: string) {
this.testDir = new TestDirectory(cwdArg, relativePathToTestDirectory);
}
async run() {
const fileNamesToRun: string[] = await this.testDir.getTestFilePathArray();
console.log(`Found ${fileNamesToRun.length} test(s):`);
for (const fileName of fileNamesToRun) {
console.log(fileName);
}
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash',
sourceFilePaths: []
});
const tapCombinator = new TapCombinator(); // lets create the TapCombinator
for (const fileName of fileNamesToRun) {
const tapParser = new TapParser();
const execResultStreaming = await smartshellInstance.execStreamingSilent(`tsrun ${fileName}`);
await tapParser.handleTapProcess(execResultStreaming.childProcess);
}
}
}

4
ts/tstest.paths.ts Normal file
View File

@ -0,0 +1,4 @@
import * as plugins from './tstest.plugins';
export const cwd = process.cwd();
export const testDir = plugins.path.join(cwd, './test/');

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

@ -0,0 +1,7 @@
import * as path from 'path';
import * as smartfile from '@pushrocks/smartfile';
import * as smartlog from '@pushrocks/smartlog';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartshell from '@pushrocks/smartshell';
export { path, smartfile, smartlog, smartpromise, smartshell };

View File

@ -0,0 +1,11 @@
// ============
// combines different tap test files to an overall result
// ============
import * as plugins from './tstest.plugins';
import { TapParser } from './tstest.tap.parser';
export class TapCombinator {
addTapParser(tapParserArg: TapParser) {
}
}

26
ts/tstest.tap.parser.ts Normal file
View File

@ -0,0 +1,26 @@
import { ChildProcess } from 'child_process';
// ============
// combines different tap test files to an overall result
// ============
import * as plugins from './tstest.plugins';
import { TapTestResult } from './tstest.tap.testresult';
export class TapParser {
resultStore: TapTestResult[] = [];
expectedTests: number;
processLog(logChunk: Buffer | string) {
if(Buffer.isBuffer(logChunk)) {
logChunk = logChunk.toString();
}
const logLineArray = logChunk.split('\n');
console.log(logLineArray);
}
async handleTapProcess(childProcessArg: ChildProcess) {
const done = plugins.smartpromise.defer();
await done.promise;
}
}

View File

@ -0,0 +1,6 @@
// ============
// combines different tap test files to an overall result
// ============
import * as plugins from './tstest.plugins';
export class TapTestResult {}