Skip to content

Commit 46fd67a

Browse files
committed
Add some colors in the logs in order to easily see failures and add a summary of the failures at the end
1 parent b71be8a commit 46fd67a

6 files changed

Lines changed: 112 additions & 24 deletions

File tree

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"jasmine": "^6.2.0",
4343
"jsdoc": "^4.0.5",
4444
"jstransformer-nunjucks": "^1.2.0",
45+
"kleur": "^4.1.5",
4546
"metalsmith": "^2.7.0",
4647
"metalsmith-html-relative": "^2.0.11",
4748
"ordered-read-streams": "^2.0.0",

test/color_utils.mjs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* Copyright 2026 Mozilla Foundation
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
import kleur from "kleur";
17+
18+
kleur.enabled =
19+
!process.env.NO_COLOR &&
20+
(!!process.stdout.isTTY ||
21+
!!process.env.FORCE_COLOR ||
22+
process.env.GITHUB_ACTIONS === "true");
23+
24+
const TEST_PASSED = kleur.green("TEST-PASS");
25+
const TEST_UNEXPECTED_FAIL = kleur.red().bold("TEST-UNEXPECTED-FAIL");
26+
27+
function colorBrowser(name) {
28+
return kleur.cyan(name);
29+
}
30+
31+
export { colorBrowser, TEST_PASSED, TEST_UNEXPECTED_FAIL };

test/integration/jasmine-boot.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
/* eslint-disable no-console */
1717

18+
import { TEST_PASSED, TEST_UNEXPECTED_FAIL } from "../color_utils.mjs";
1819
import Jasmine from "jasmine";
1920

2021
async function runTests(results) {
@@ -50,6 +51,13 @@ async function runTests(results) {
5051
],
5152
});
5253

54+
function failureError(result) {
55+
return result.failedExpectations
56+
?.map(item => item.message)
57+
.filter(Boolean)
58+
.join(" ");
59+
}
60+
5361
jasmine.addReporter({
5462
jasmineDone(suiteInfo) {},
5563
jasmineStarted(suiteInfo) {},
@@ -62,10 +70,17 @@ async function runTests(results) {
6270
// Report on passed or failed tests.
6371
++results.runs;
6472
if (result.status === "passed") {
65-
console.log(`TEST-PASSED | ${result.description}`);
73+
console.log(`${TEST_PASSED} | ${result.description}`);
6674
} else {
6775
++results.failures;
68-
console.log(`TEST-UNEXPECTED-FAIL | ${result.description}`);
76+
const error = failureError(result);
77+
results.failureList?.push({
78+
description: result.description,
79+
error,
80+
});
81+
console.log(
82+
`${TEST_UNEXPECTED_FAIL} | ${result.description}${error ? ` | ${error}` : ""}`
83+
);
6984
}
7085
},
7186
specStarted(result) {},
@@ -78,7 +93,14 @@ async function runTests(results) {
7893
// Report on failed suites only (indicates problems in setup/teardown).
7994
if (result.status === "failed") {
8095
++results.failures;
81-
console.log(`TEST-UNEXPECTED-FAIL | ${result.description}`);
96+
const error = failureError(result);
97+
results.failureList?.push({
98+
description: result.description,
99+
error,
100+
});
101+
console.log(
102+
`${TEST_UNEXPECTED_FAIL} | ${result.description}${error ? ` | ${error}` : ""}`
103+
);
82104
}
83105
},
84106
suiteStarted(result) {},

test/reporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const TestReporter = function (browser) {
6969

7070
// Report on passed or failed tests.
7171
if (result.status === "passed") {
72-
sendResult("TEST-PASSED", result.description);
72+
sendResult("TEST-PASS", result.description);
7373
} else {
7474
let failedMessages = "";
7575
for (const item of result.failedExpectations) {

test/test.mjs

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
*/
1515
/* eslint-disable no-var */
1616

17+
import {
18+
colorBrowser,
19+
TEST_PASSED,
20+
TEST_UNEXPECTED_FAIL,
21+
} from "./color_utils.mjs";
1722
import { copySubtreeSync, ensureDirSync } from "./testutils.mjs";
1823
import {
1924
COVERAGE_FORMAT_TO_REPORTER,
@@ -423,7 +428,7 @@ function handleSessionTimeout(session) {
423428
return;
424429
}
425430
console.log(
426-
`TEST-UNEXPECTED-FAIL | test failed ${session.name} has not responded in ${browserTimeout}s`
431+
`${TEST_UNEXPECTED_FAIL} | test failed ${session.name} has not responded in ${browserTimeout}s`
427432
);
428433
session.numErrors += session.remaining;
429434
session.remaining = 0;
@@ -558,7 +563,7 @@ async function checkEq(task, results, session, masterMode) {
558563
) === 0;
559564
if (!eq) {
560565
console.log(
561-
`TEST-UNEXPECTED-FAIL | ${taskType} ${taskId} | in ${session.name} | rendering of page ${page + 1} != reference rendering`
566+
`${TEST_UNEXPECTED_FAIL} | ${taskType} ${taskId} | in ${colorBrowser(session.name)} | rendering of page ${page + 1} != reference rendering`
562567
);
563568

564569
if (!testDirCreated) {
@@ -605,7 +610,9 @@ async function checkEq(task, results, session, masterMode) {
605610
if (numEqFailures > 0) {
606611
session.numEqFailures += numEqFailures;
607612
} else {
608-
console.log(`TEST-PASS | ${taskType} test ${taskId} | in ${session.name}`);
613+
console.log(
614+
`${TEST_PASSED} | ${taskType} test ${taskId} | in ${colorBrowser(session.name)}`
615+
);
609616
}
610617
}
611618

@@ -633,13 +640,13 @@ function checkFBF(task, results, session, masterMode) {
633640
// https://github.com/mozilla/pdf.js/issues/12371
634641
if (masterMode) {
635642
console.log(
636-
`TEST-SKIPPED | forward-back-forward test ${task.id} | in ${session.name} | page${page + 1}`
643+
`TEST-SKIPPED | forward-back-forward test ${task.id} | in ${colorBrowser(session.name)} | page${page + 1}`
637644
);
638645
continue;
639646
}
640647

641648
console.log(
642-
`TEST-UNEXPECTED-FAIL | forward-back-forward test ${task.id} | in ${session.name} | first rendering of page ${page + 1} != second`
649+
`${TEST_UNEXPECTED_FAIL} | forward-back-forward test ${task.id} | in ${colorBrowser(session.name)} | first rendering of page ${page + 1} != second`
643650
);
644651
numFBFFailures++;
645652
}
@@ -649,15 +656,17 @@ function checkFBF(task, results, session, masterMode) {
649656
session.numFBFFailures += numFBFFailures;
650657
} else {
651658
console.log(
652-
`TEST-PASS | forward-back-forward test ${task.id} | in ${session.name}`
659+
`${TEST_PASSED} | forward-back-forward test ${task.id} | in ${colorBrowser(session.name)}`
653660
);
654661
}
655662
}
656663

657664
function checkLoad(task, results, browser) {
658665
// Load just checks for absence of failure, so if we got here the
659666
// test has passed
660-
console.log(`TEST-PASS | load test ${task.id} | in ${browser}`);
667+
console.log(
668+
`${TEST_PASSED} | load test ${task.id} | in ${colorBrowser(browser)}`
669+
);
661670
}
662671

663672
async function checkRefTestResults(browser, id, results) {
@@ -685,7 +694,7 @@ async function checkRefTestResults(browser, id, results) {
685694
"TEST-SKIPPED | PDF was not downloaded " +
686695
id +
687696
" | in " +
688-
browser +
697+
colorBrowser(browser) +
689698
" | page" +
690699
(page + 1) +
691700
" round " +
@@ -698,16 +707,7 @@ async function checkRefTestResults(browser, id, results) {
698707
session.numErrors++;
699708
}
700709
console.log(
701-
"TEST-UNEXPECTED-FAIL | test failed " +
702-
id +
703-
" | in " +
704-
browser +
705-
" | page" +
706-
(page + 1) +
707-
" round " +
708-
(round + 1) +
709-
" | " +
710-
pageResult.failure
710+
`${TEST_UNEXPECTED_FAIL} | test failed ${id} | in ${colorBrowser(browser)} | page${page + 1} round ${round + 1} | ${pageResult.failure}`
711711
);
712712
}
713713
}
@@ -835,6 +835,16 @@ function onAllSessionsClosedAfterTests(name) {
835835
} else if (numErrors > 0) {
836836
console.log("OHNOES! Some " + name + " tests failed!");
837837
console.log(" " + numErrors + " of " + numRuns + " failed");
838+
console.log("Here are the failing tests:");
839+
for (const session of sessions) {
840+
for (const { description, error } of session.failures ?? []) {
841+
let line = ` - in ${colorBrowser(session.name)} | ${description}`;
842+
if (error) {
843+
line += ` | ${error.replaceAll(/\s+/g, " ").trim()}`;
844+
}
845+
console.log(line);
846+
}
847+
}
838848
} else {
839849
console.log("All " + name + " tests passed.");
840850
}
@@ -854,6 +864,7 @@ async function startUnitTest(testUrl, name) {
854864
initializeSession: session => {
855865
session.numRuns = 0;
856866
session.numErrors = 0;
867+
session.failures = [];
857868
},
858869
});
859870
}
@@ -868,15 +879,17 @@ async function startIntegrationTest() {
868879
initializeSession: session => {
869880
session.numRuns = 0;
870881
session.numErrors = 0;
882+
session.failures = [];
871883
},
872884
});
873885
global.integrationBaseUrl = `http://${host}:${server.port}/build/generic/web/viewer.html`;
874886
global.integrationSessions = sessions;
875887

876-
const results = { runs: 0, failures: 0 };
888+
const results = { runs: 0, failures: 0, failureList: [] };
877889
await runTests(results);
878890
sessions[0].numRuns = results.runs;
879891
sessions[0].numErrors = results.failures;
892+
sessions[0].failures = results.failureList;
880893
await Promise.all(sessions.map(session => closeSession(session.name)));
881894
}
882895

@@ -920,10 +933,20 @@ function unitTestPostHandler(parsedUrl, req, res) {
920933
}
921934
var session = getSession(data.browser);
922935
session.numRuns++;
936+
let status = data.status;
937+
if (status === "TEST-UNEXPECTED-FAIL") {
938+
status = TEST_UNEXPECTED_FAIL;
939+
} else if (status === "TEST-PASS") {
940+
status = TEST_PASSED;
941+
}
923942
var message =
924-
data.status + " | " + data.description + " | in " + session.name;
943+
status + " | " + data.description + " | in " + colorBrowser(session.name);
925944
if (data.status === "TEST-UNEXPECTED-FAIL") {
926945
session.numErrors++;
946+
session.failures.push({
947+
description: data.description,
948+
error: data.error,
949+
});
927950
}
928951
if (data.error) {
929952
message += " | " + data.error;

0 commit comments

Comments
 (0)