You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
example util for handler coverage (more oriented to ANT contracts but could be modified for AOS):
importfsfrom'fs';import{glob}from'glob';importchalkfrom'chalk';importluaparsefrom'luaparse';importyargsfrom'yargs';import{hideBin}from'yargs/helpers';// Configure named argumentsconstargv=yargs(hideBin(process.argv)).option('luaEntryFile',{alias: 'l',type: 'string',description: 'Path to the Lua entry file',demandOption: true,}).option('testFilePattern',{alias: 't',type: 'string',description: 'Glob pattern for test files (e.g., **/*.test.(ts|mjs|js))',demandOption: true,}).option('coverageOutputFile',{alias: 'o',type: 'string',description: 'File to output the coverage report (optional)',}).help().argv;// Handler extraction functionsfunctiongetHandlerNames(filePath){constcontent=fs.readFileSync(filePath,'utf-8');constast=luaparse.parse(content);consthandlers=newSet();functiontraverseNode(node){if(node.type==='FunctionDeclaration'&&node.identifier.identifier.name=='init'){node.body.forEach((subNode)=>{if(subNode.type=='LocalStatement'&&subNode.variables[0].name.includes('ActionMap')){subNode.init?.forEach((initNode)=>{if(initNode.type==='TableConstructorExpression'){initNode.fields.forEach((field)=>{if(field.key.type==='Identifier'&&field.value.type==='StringLiteral'){handlers.add(field.value.raw.replace(/^["']|["']$/g,''));// Remove quotes}});}});}});}}ast.body.forEach((node)=>traverseNode(node));returnArray.from(handlers);}// Test file processing functionsfunctionextractTestedHandlers(testFileContent){constactionRegex=/{name:'Action',value:['"](\w+(-\w+)?)['"]}/g;consttestedHandlers=newSet();letmatch;while((match=actionRegex.exec(testFileContent))!==null){// Add handler to set, ensuring any quotes are removedtestedHandlers.add(match[1].replace(/^['"]|['"]$/g,''));}return[...testedHandlers];}functiongetTestedHandlersInFiles(pattern,luaHandlers){consttestedHandlers=newSet();constfiles=glob.sync(pattern,{});files.forEach((file)=>{constcontent=fs.readFileSync(file,'utf-8');extractTestedHandlers(content,luaHandlers).forEach((handler)=>testedHandlers.add(handler),);});return[...testedHandlers];}// Coverage report generationfunctiongenerateCoverageReport(luaHandlers,testedHandlers){constuntestedHandlers=luaHandlers.filter((handler)=>!testedHandlers.includes(handler),);constcoverage=((luaHandlers.length-untestedHandlers.length)/luaHandlers.length)*100;constreportLines=[];reportLines.push(chalk.bold('\nHandlers Coverage Report'));reportLines.push(`Total Handlers: ${chalk.cyan(luaHandlers.length)}`);reportLines.push(`Tested Handlers: ${chalk.green(luaHandlers.length-untestedHandlers.length)}`,);reportLines.push(`Untested Handlers: ${chalk.red(untestedHandlers.length)}`);reportLines.push(`Coverage: ${coverage>=80 ? chalk.green.bold(coverage.toFixed(2)+'%') : chalk.red.bold(coverage.toFixed(2)+'%')}`,);if(untestedHandlers.length>0){reportLines.push(chalk.bold.red('\nUntested Handlers:'));untestedHandlers.forEach((handler)=>reportLines.push(`- ${chalk.red(handler)}`),);}else{reportLines.push(chalk.bold.green('\nAll handlers are tested!'));}constreportText=reportLines.join('\n');console.log(reportText);if(argv.coverageOutputFile){fs.writeFileSync(argv.coverageOutputFile,reportLines.join('\n').replace(/\x1b\[[0-9;]*m/g,''),);console.log(chalk.green(`\nReport written to ${argv.coverageOutputFile}`));}}// Run the report generationconstluaHandlers=getHandlerNames(argv.luaEntryFile);consttestedHandlers=getTestedHandlersInFiles(argv.testFilePattern,luaHandlers,);generateCoverageReport(luaHandlers,testedHandlers);
The text was updated successfully, but these errors were encountered:
Please Describe The Problem To Be Solved
A testing suite for AOS processes would be nice.
example util for handler coverage (more oriented to ANT contracts but could be modified for AOS):
The text was updated successfully, but these errors were encountered: