Skip to content

🐛 Bug: Stock unit tests failing with Vitest 4 #2305

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Expected

Running pnpm run test in a newly created repository should pass.

Actual

As of Vitest 4:

$ pnpm run test run

> cta-yml-yaml-testing@0.0.0 test /Users/josh/repos/cta-yml-yaml-testing
> vitest run


 RUN  v4.0.15 /Users/josh/repos/cta-yml-yaml-testing

 ❯ src/greet.test.ts (4 tests | 2 failed) 5ms
   ❯ greet (4)
     × logs to the console once when message is provided as a string 3ms
     × logs to the console once when message is provided as an object 0ms
     ✓ logs once when times is not provided in an object 0ms
     ✓ logs a specified number of times when times is provided 1ms

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  src/greet.test.ts > greet > logs to the console once when message is provided as a string
 FAIL  src/greet.test.ts > greet > logs to the console once when message is provided as an object
Error: Oh no! Your test called the following console method:
  * log (1 call)
    > Call 0: "Yay, testing!"
 ❯ createComplaint node_modules/.pnpm/console-fail-test@0.5.0/node_modules/console-fail-test/lib/esm/complaining/createComplaint.js:5:17
 ❯ node_modules/.pnpm/console-fail-test@0.5.0/node_modules/console-fail-test/lib/esm/cft.js:37:23
 ❯ node_modules/.pnpm/console-fail-test@0.5.0/node_modules/console-fail-test/lib/esm/environments/vitest.js:9:24

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯


 Test Files  1 failed (1)
      Tests  2 failed | 2 passed (4)
   Start at  08:47:52
   Duration  95ms (transform 19ms, setup 14ms, import 15ms, tests 5ms, environment 0ms)

 ELIFECYCLE  Test failed. See above for more details.
josh ~/repos/cta-yml-yaml-testing $ 

Additional Info

I looked at this a little and it looks like the console spying/mocking isn't overriding the global implementation:

https://github.com/JoshuaKGoldberg/cta-yml-yaml-testing/blob/d4072f988430052303435e67cd4440cd48fec920/src/greet.test.ts#L9

🎁

Metadata

Metadata

Labels

status: accepting prsPlease, send a pull request to resolve this!type: bugSomething isn't working :(

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions