Skip to content

Commit

Permalink
fix: remove slow test info from non slow integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
galargh committed Oct 7, 2024
1 parent 18c49c8 commit 97553ba
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions v-next/hardhat-node-test-reporter/integration-tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { run } from "node:test";

import { diff } from "jest-diff";

import { formatSlowTestInfo } from "../src/formatting.js";
import { hardhatTestReporter } from "../src/reporter.js";

let SHOW_OUTPUT = false;
Expand Down Expand Up @@ -95,8 +96,8 @@ for (const entry of entries) {
writeFileSync(entryPath + "/result.actual.txt", output);
const expectedOutput = readFileSync(entryPath + "/result.txt", "utf8");

const normalizedOutput = normalizeOutputs(output);
const normalizedExpectedOutput = normalizeOutputs(expectedOutput);
const normalizedOutput = normalizeOutput(entry, output);
const normalizedExpectedOutput = normalizeOutput(entry, expectedOutput);

if (normalizedOutput !== normalizedExpectedOutput) {
console.log("Normalized outputs differ:");
Expand All @@ -119,9 +120,22 @@ for (const entry of entries) {
}
}

function normalizeOutputs(output: string): string {
function normalizeOutput(name: string, output: string): string {
let normalizedOutput = output;

if (name !== "slow-test") {
// Remove slow test info from the output
const slowTestInfo = formatSlowTestInfo(0)
.replace(/[/\-\\^$*+?.()|[\]{}]/g, "\\$&")
.replace("0", "\\d+");
const slowTestRegex = new RegExp(slowTestInfo, "g");
normalizedOutput = normalizedOutput.replace(slowTestRegex, "");
}

return (
output
normalizedOutput
// Normalize the time it took to run the test
.replace(/\(\d+ms\)/g, "(Xms)")
// Remove the time it took to run the test because it was a source of flakiness
// This means we're not, in fact, testing how slow tests are displayed
.replace(/\s*\(\d+ms\)/g, "")
Expand Down

0 comments on commit 97553ba

Please sign in to comment.