-
Notifications
You must be signed in to change notification settings - Fork 0
/
myrunner.js
47 lines (37 loc) · 1.44 KB
/
myrunner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* global process */
import { console_output } from "./src/console_output.js";
import { console_report } from "./src/console_report.js";
import { TestSuite, Test } from "./src/testSuite.js";
import fs from 'fs';
import path from 'path'; // Import the path module
function getClassNames( obj ){
let arr = Object.getOwnPropertyNames( obj );
return arr;
}
let report = new console_report( new console_output() );
let testSuiteFilePath = process.argv[2]; // Get the full path to the test suite file
let {dir: testSuiteDir, name: testSuiteName} = path.parse( testSuiteFilePath ); // Parse the file path
//console.log("Directory:", testSuiteDir);
//console.log("Filename:", testSuiteName);
if( !fs.existsSync( testSuiteFilePath ) ) {
console.log( "File does not exist: " + testSuiteFilePath );
process.exit( 1 );
}
cargar( testSuiteFilePath );
function cargar( testSuiteFilePath ){
let fn_error = function ( error ){
console.error( "Error loading test suite:", error );
process.exit( 1 );
};
let fn_then = function ( module ){
let classNames = getClassNames( module );
if( classNames.length === 0 ) {
throw new Error( testSuiteFilePath + " does not contain any classes" );
}
let className = classNames[0];
let suite = new module[className]( report );
suite.setup();
suite.start();
};
import( testSuiteFilePath ).then( fn_then ).catch( fn_error );
}