fix: logs stream and reporting

This commit is contained in:
Danish Arora 2025-01-29 21:45:29 +05:30
parent 29dd3e225b
commit 4e29f60419
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E
3 changed files with 63 additions and 18 deletions

View File

@ -30,6 +30,8 @@ jobs:
runs-on: ubuntu-latest
env:
WAKUNODE_IMAGE: ${{ inputs.nim_wakunode_image }}
REPORT_PATH: packages/tests/reports/mocha-results.json
GITHUB_WORKSPACE: ${{ github.workspace }}
permissions:
contents: read
actions: read
@ -47,6 +49,9 @@ jobs:
- run: npm run build:esm
- name: Create reports directory
run: mkdir -p packages/tests/reports
- run: ${{ (inputs.test_type == 'node-optional') && 'npm run test:optional --workspace=@waku/tests' || 'npm run test:node' }}
- name: Test Report
@ -54,7 +59,7 @@ jobs:
if: success() || failure()
with:
name: Test Report - ${{ inputs.test_type }}
path: 'packages/tests/reports/mocha-*.json'
path: packages/tests/reports/mocha-results.json
reporter: mocha-json
fail-on-error: true

View File

@ -15,13 +15,27 @@ if (process.env.CI) {
config.parallel = true;
config.jobs = 6;
console.log("Using multi reporters for test results");
config.reporter = 'mocha-multi-reporters';
config.reporterOptions = {
reporterEnabled: 'spec, json',
jsonReporterOptions: {
output: 'reports/mocha-results.json'
config.reporter = 'spec';
// Write JSON results to file without printing to console
if (process.env.REPORT_PATH) {
const fs = require('fs');
const path = require('path');
const reportDir = path.dirname(process.env.REPORT_PATH);
if (!fs.existsSync(reportDir)) {
fs.mkdirSync(reportDir, { recursive: true });
}
};
config.reporter = 'mocha-multi-reporters';
config.reporterOptions = {
reporterEnabled: 'spec, json',
reporterOptions: {
json: {
stdout: '/dev/null', // Don't print JSON to stdout
options: { output: process.env.REPORT_PATH }
}
}
};
}
} else {
console.log("Running tests serially. To enable parallel execution update mocha config");
}

View File

@ -1,9 +1,15 @@
import { exec, spawn } from "child_process";
import { mkdir } from "fs/promises";
import { dirname } from "path";
import { mkdir, writeFile } from "fs/promises";
import { dirname, join, resolve } from "path";
import { fileURLToPath } from "url";
import { promisify } from "util";
const execAsync = promisify(exec);
const __dirname = dirname(fileURLToPath(import.meta.url));
// Ensure paths are absolute and relative to the package root
const PACKAGE_ROOT = resolve(__dirname, "..");
const getPackagePath = (path) => resolve(PACKAGE_ROOT, path);
const WAKUNODE_IMAGE = process.env.WAKUNODE_IMAGE || "wakuorg/nwaku:v0.31.0";
@ -26,18 +32,38 @@ async function main() {
];
if (process.env.CI) {
const reportPath = "reports/mocha-results.json";
await mkdir(dirname(reportPath), { recursive: true });
const reportsDir = getPackagePath("reports");
const reportFile = resolve(reportsDir, "mocha-results.json");
const configFile = resolve(reportsDir, "config.json");
await mkdir(reportsDir, { recursive: true });
// Create a clean reporter config
const reporterConfig = {
reporterEnabled: "spec",
reporterOptions: {
json: {
stdout: false,
options: {
output: reportFile
}
}
}
};
// Write the config file
await writeFile(configFile, JSON.stringify(reporterConfig, null, 2));
// Add a separate JSON reporter directly
mochaArgs.push(
"--reporter",
"json",
"--reporter-option",
`output=${reportPath}`,
"--parallel",
"--jobs",
"6"
`output=${reportFile}`,
"--reporter",
"json"
);
} else {
// In non-CI environments, just use spec reporter
mochaArgs.push("--reporter", "spec");
}
// Add test files
@ -48,7 +74,7 @@ async function main() {
}
mochaArgs.push(...testFiles);
console.log("Running mocha with args:", mochaArgs);
console.info("Running mocha with args:", mochaArgs);
// Run mocha tests
const mocha = spawn("npx", mochaArgs, {