* @param args - program arguments
(args)
| 14 | * @param args - program arguments |
| 15 | */ |
| 16 | async function main(args) { |
| 17 | args = yargs(args) |
| 18 | .option('l', { |
| 19 | alias: 'log', |
| 20 | demandOption: true, |
| 21 | default: './data/mongod.log', // cluster_setup.sh default |
| 22 | describe: 'The log you wish to filter', |
| 23 | type: 'string' |
| 24 | }) |
| 25 | .option('f', { |
| 26 | alias: 'filter', |
| 27 | demandOption: true, |
| 28 | default: '', // No filter is still useful if you want to look at all tests |
| 29 | describe: 'The test name filter, if none provided all test logs will be shown', |
| 30 | type: 'string' |
| 31 | }) |
| 32 | .option('v', { |
| 33 | alias: 'verbose', |
| 34 | demandOption: false, |
| 35 | describe: 'Enable warnings about processing', |
| 36 | type: 'boolean' |
| 37 | }) |
| 38 | .help('h') |
| 39 | .alias('h', 'help').epilog(` |
| 40 | - Some log processing is done: |
| 41 | - better date time format |
| 42 | - string interpolation |
| 43 | - 'testName' property added |
| 44 | - Depends on an xunit file, should be left over from every test run |
| 45 | |
| 46 | Examples: |
| 47 | ${chalk.green('crawfish.mjs | jq -SC | less -R')} |
| 48 | - jq -SC will sort the keys and force color output |
| 49 | - less lets you page through and search logs |
| 50 | |
| 51 | ${chalk.green('crawfish.mjs | jq -Sc | code -')} |
| 52 | - jq -Sc will sort the keys and keep the logs one line (compact) |
| 53 | - Opens the output in vscode, good for searching! |
| 54 | `).argv; |
| 55 | |
| 56 | warnings = !!args.verbose; |
| 57 | const logFile = args.log; |
| 58 | const testNameRegex = args.filter; |
| 59 | |
| 60 | if (!existsSync('xunit.xml')) { |
| 61 | console.error('xunit.xml file not found, required for db log test filtering.'); |
| 62 | process.exit(1); |
| 63 | } |
| 64 | |
| 65 | const content = await readFile('xunit.xml', { encoding: 'utf8' }); |
| 66 | const xunit = await parseStringPromise(content); |
| 67 | |
| 68 | const tests = collectTests(xunit, testNameRegex); |
| 69 | if (warnings) console.error(`filtering log file ${logFile}`); |
| 70 | |
| 71 | const logStream = |
| 72 | logFile === '-' ? process.stdin : createReadStream(logFile, { encoding: 'utf8' }); |
| 73 | const lineStream = createInterface({ |
no test coverage detected