Skip to content

Commit

Permalink
refactor(test): extract extractMatchesFromString()
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Oct 17, 2023
1 parent 07e8b86 commit 8fec580
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions testing/tests/destructive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ function* walker(root) {
}
}

function extractMatchesFromString(pattern: RegExp, str: string) {
const matches = [];

let match: string[];
while ((match = pattern.exec(str)) !== null) {
matches.push(match[1] ?? match[0]);
}

return matches;
}

describe("fixing flaws", () => {
const pattern = path.join("web", "fixable_flaws");
const baseDir = path.resolve(".");
Expand Down Expand Up @@ -95,13 +106,10 @@ describe("fixing flaws", () => {
),
}).toString();

const wouldModify = [];
const regexPattern = /Would modify "(.*)"./g;

let match: string[];
while ((match = regexPattern.exec(stdout)) !== null) {
wouldModify.push(match[1]);
}
const wouldModify = extractMatchesFromString(
/Would modify "(.*)"./g,
stdout
);

expect(wouldModify).toHaveLength(4);
expect(wouldModify).toContain(
Expand Down

0 comments on commit 8fec580

Please sign in to comment.