Improve peer dependency warning assertions in tests

Replace brittle substring assertions with more robust patterns:
- Line 3916: Use line-anchored pattern /^warn:[^\n]*...$/ to avoid
  matching across lines
- Line 7637: Use line-based check with split/some to ensure no
  individual line contains the warning
- Line 7720: Use line-based check with split/every for same purpose
- Line 7828: Use word-boundary regex /\bunmet peer dependency\b/i
- Line 7893: Use package-specific regex to target known packages
- Line 7959: Normalize stderr by stripping ANSI codes before checking

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2026-01-15 00:27:36 +00:00
parent 7978a79339
commit 669ffe3749

View File

@@ -3913,7 +3913,8 @@ describe("hoisting", async () => {
expect(err).not.toContain("error:");
// New improved peer dependency warning format shows the requiring package, expected version, and actual version
// Match: "warn: ...peer-deps-fixed has unmet peer dependency no-deps@^1.0.0 (found 2.0.0)"
expect(err).toMatch(/warn:.*peer-deps-fixed has unmet peer dependency no-deps@\^1\.0\.0 \(found 2\.0\.0\)/);
// Use line-anchored pattern to avoid matching across lines
expect(err).toMatch(/^warn:[^\n]*peer-deps-fixed has unmet peer dependency no-deps@\^1\.0\.0 \(found 2\.0\.0\)$/m);
expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
expect.stringContaining("bun install v1."),
@@ -7634,7 +7635,8 @@ describe("yarn tests", () => {
expect(err).toContain("Saved lockfile");
expect(err).not.toContain("error:");
expect(err).not.toContain("not found");
expect(err).not.toContain("unmet peer dependency");
// Use line-based check to ensure no line contains the peer dependency warning
expect(err.split(/\r?\n/).some((line: string) => /unmet peer dependency/i.test(line))).toBe(false);
expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
expect.stringContaining("bun install v1."),
"",
@@ -7717,7 +7719,8 @@ describe("yarn tests", () => {
expect(err).toContain("Saved lockfile");
expect(err).not.toContain("error:");
expect(err).not.toContain("not found");
expect(err).not.toContain("unmet peer dependency");
// Use line-based check to ensure no line contains the peer dependency warning
expect(err.split(/\r?\n/).every((line: string) => !/unmet peer dependency/i.test(line))).toBe(true);
expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
expect.stringContaining("bun install v1."),
"",
@@ -7825,7 +7828,8 @@ describe("yarn tests", () => {
expect(err).toContain("Saved lockfile");
expect(err).not.toContain("error:");
expect(err).not.toContain("not found");
expect(err).not.toContain("unmet peer dependency");
// Use word-boundary regex to match exact warning token
expect(err).not.toMatch(/\bunmet peer dependency\b/i);
expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
expect.stringContaining("bun install v1."),
"",
@@ -7890,7 +7894,8 @@ describe("yarn tests", () => {
expect(err).toContain("Saved lockfile");
expect(err).not.toContain("error:");
expect(err).not.toContain("not found");
expect(err).not.toContain("unmet peer dependency");
// Use regex to match the specific packages in this test, avoiding false positives
expect(err).not.toMatch(/unmet peer dependency.*(forward-peer-deps|no-deps)/i);
expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
expect.stringContaining("bun install v1."),
"",
@@ -7956,7 +7961,9 @@ describe("yarn tests", () => {
expect(err).toContain("Saved lockfile");
expect(err).not.toContain("error:");
expect(err).not.toContain("not found");
expect(err).not.toContain("unmet peer dependency");
// Normalize stderr (strip ANSI codes) and use case-insensitive regex
const normalizedErr = err.replace(/\x1b\[[0-9;]*m/g, "");
expect(normalizedErr).not.toMatch(/unmet peer dependency/i);
expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
expect.stringContaining("bun install v1."),
"",