feat: support chai in scripts (#4552)

feat: support chai in scripts
This commit is contained in:
Pooja
2025-06-10 22:41:11 +05:30
committed by GitHub
parent 9bc07afc77
commit fc697bf81b
17 changed files with 501 additions and 194 deletions

View File

@@ -16,6 +16,7 @@ const BrunoResponse = require('../bruno-response');
const Test = require('../test');
const TestResults = require('../test-results');
const { cleanJson } = require('../utils');
const { createBruTestResultMethods } = require('../utils/results');
// Inbuilt Library Support
const ajv = require('ajv');
@@ -35,25 +36,6 @@ const cheerio = require('cheerio');
const tv4 = require('tv4');
const { executeQuickJsVmAsync } = require('../sandbox/quickjs');
const getResultsSummary = (results) => {
const summary = {
total: results.length,
passed: 0,
failed: 0,
skipped: 0,
};
results.forEach((r) => {
const passed = r.status === "pass";
if (passed) summary.passed += 1;
else if (r.status === "fail") summary.failed += 1;
else summary.skipped += 1;
});
return summary;
}
class TestRuntime {
constructor(props) {
this.runtime = props?.runtime || 'vm2';
@@ -99,9 +81,8 @@ class TestRuntime {
}
}
const __brunoTestResults = new TestResults();
const test = Test(__brunoTestResults, chai);
// extend bru with result getter methods
const { __brunoTestResults, test } = createBruTestResultMethods(bru, assertionResults, chai);
if (!testsFile || !testsFile.length) {
return {
@@ -114,36 +95,6 @@ class TestRuntime {
};
}
bru.getTestResults = async () => {
let results = await __brunoTestResults.getResults();
const summary = getResultsSummary(results);
return {
summary,
results: results?.map?.(r => ({
status: r?.status,
description: r?.description,
expected: r?.expected,
actual: r?.actual,
error: r?.error
}))
};
}
bru.getAssertionResults = async () => {
let results = assertionResults;
const summary = getResultsSummary(results);
return {
summary,
results: results?.map?.(r => ({
status: r?.status,
lhsExpr: r?.lhsExpr,
rhsExpr: r?.rhsExpr,
operator: r?.operator,
rhsOperand: r?.rhsOperand,
error: r?.error
}))
};
}
const context = {
test,
bru,