@@ -9,13 +9,14 @@ const { parseArgs } = require('node:util');
99
1010const args = process . argv . slice ( 2 ) ;
1111
12- let config , report , suiteName ;
12+ let config , report , suiteName , onlycase , bench , unit , stopOnFailure , id , puterjs ;
1313
1414try {
1515 const parsed = parseArgs ( {
1616 options : {
1717 config : {
1818 type : 'string' ,
19+ default : './tools/api-tester/config.yml' ,
1920 } ,
2021 report : {
2122 type : 'string' ,
2425 bench : { type : 'boolean' } ,
2526 unit : { type : 'boolean' } ,
2627 suite : { type : 'string' } ,
28+ 'stop-on-failure' : { type : 'boolean' } ,
29+ puterjs : { type : 'boolean' } ,
2730 } ,
2831 allowPositionals : true ,
2932 } ) ;
3538 bench,
3639 unit,
3740 suite : suiteName ,
41+ 'stop-on-failure' : stopOnFailure ,
42+ puterjs,
3843 } , positionals : [ id ] } = parsed ) ;
3944
4045 onlycase = onlycase !== undefined ? Number . parseInt ( onlycase ) : undefined ;
4752 '\n' +
4853 'Options:\n' +
4954 ' --config=<path> (required) Path to configuration file\n' +
55+ ' --puterjs (optional) Use puter-js puterjs\n' +
5056 ' --report=<path> (optional) Output file for full test results\n' +
5157 ' --suite=<name> (optional) Run only tests with matching suite name\n' +
5258 ''
@@ -58,6 +64,87 @@ const conf = YAML.parse(fs.readFileSync(config).toString());
5864
5965
6066const main = async ( ) => {
67+ if ( puterjs ) {
68+ // const run = require('./puter_js/__entry__.js');
69+
70+ const context = {
71+ mountpoint : {
72+ path : '/' ,
73+ }
74+ } ;
75+
76+ const ts = new TestSDK ( conf , context , { } ) ;
77+ const registry = new TestRegistry ( ts ) ;
78+
79+ await require ( './puter_js/__entry__.js' ) ( registry ) ;
80+
81+ await registry . run_all_tests ( ) ;
82+
83+ // await run(conf);
84+ ts . printTestResults ( ) ;
85+ ts . printBenchmarkResults ( ) ;
86+ process . exit ( 0 ) ;
87+ return ;
88+ }
89+
90+ const unit_test_results = [ ] ;
91+ const benchmark_results = [ ] ;
92+ for ( const mountpoint of conf . mountpoints ) {
93+ const { unit_test_results : results , benchmark_results : benchs } = await test ( { mountpoint } ) ;
94+ unit_test_results . push ( ...results ) ;
95+ benchmark_results . push ( ...benchs ) ;
96+ }
97+
98+ // hard-coded identifier for ci script
99+ console . log ( "==================== nightly build results begin ====================" )
100+
101+ // print unit test results
102+ let tbl = { } ;
103+ for ( const result of unit_test_results ) {
104+ tbl [ result . name + ' - ' + result . settings ] = {
105+ passed : result . caseCount - result . failCount ,
106+ failed : result . failCount ,
107+ total : result . caseCount ,
108+ 'duration (s)' : result . duration ? result . duration . toFixed ( 2 ) : 'N/A' ,
109+ }
110+ }
111+ console . table ( tbl ) ;
112+
113+ // print benchmark results
114+ if ( benchmark_results . length > 0 ) {
115+ tbl = { } ;
116+ for ( const result of benchmark_results ) {
117+ const fs_provider = result . fs_provider || 'unknown' ;
118+ tbl [ result . name + ' - ' + fs_provider ] = {
119+ 'duration (s)' : result . duration ? ( result . duration / 1000 ) . toFixed ( 2 ) : 'N/A' ,
120+ }
121+ }
122+ console . table ( tbl ) ;
123+
124+ // print description of each benchmark since it's too long to fit in the table
125+ const seen = new Set ( ) ;
126+ for ( const result of benchmark_results ) {
127+ if ( seen . has ( result . name ) ) continue ;
128+ seen . add ( result . name ) ;
129+
130+ if ( result . description ) {
131+ console . log ( result . name + ': ' + result . description ) ;
132+ }
133+ }
134+ }
135+
136+ // hard-coded identifier for ci script
137+ console . log ( "==================== nightly build results end ====================" )
138+ }
139+
140+ /**
141+ * Run test using the given config, and return the test results
142+ *
143+ * @param {Object } options
144+ * @param {Object } options.mountpoint
145+ * @returns {Promise<Object> }
146+ */
147+ async function test ( { mountpoint } ) {
61148 const context = {
62149 options : {
63150 onlycase,
0 commit comments