3.10.x: failure messages no longer appear in the test file when Pest reports relative paths (regression from 3.9.40)

Open Beginner friendly
#620 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php, typescript, vscode
Domain
devtools, testing

Research direction

Read TestResultObserver.message() and the test added in commit a6cf35b that covers absolute paths. Trace how relative paths in Pest's details become Uri.file() locations and stack frames; add coverage for tests/Feature/SomeTest.php and resolve it against the project root or cwd. Done when the inline failure message appears at the test location for relative paths while inherited and trait method locations still work.

Written by the indexing model from the issue text.

Description

bug
What happened?

Since updating from 3.9.40 to 3.10.1, failure messages are no longer shown inline in the test file. The test is marked as failed, but the message is not attached to the test file. Downgrading to 3.9.40 brings the inline message back. This is still the case on main (4b334f8).

Pest prints the stack frames in details relative to the project root (tests/Feature/SomeTest.php:146).

Cause: this was introduced in a6cf35b ("fix: point failures of inherited and trait test methods to their declaring file"), which changed the message location in TestResultObserver.message() from the test item's URI to the matched frame's path:

message.location = new Location(
    location ? Uri.file(location.file) : test.uri,
    new Range(new Position(line, 0), new Position(line, 0)),
);

location.file is the relative path from Pest. Uri.file() turns it into /tests/Feature/SomeTest.php at the filesystem root, a file that does not exist. The test added in that commit only covers absolute paths (/project/tests/TestCase.php). phpunit.paths cannot help, because it only rewrites absolute paths, and expandRelative() only handles paths starting with ./. The stack frames (TestMessageStackFrame) are built from the same relative paths, so they have the same problem.

Possible fix: resolve relative frame paths against the project root (or the cwd) before calling Uri.file(). That keeps the fix from a6cf35b for inherited and trait methods and works for Pest's relative paths. A test with a relative details path such as tests/Feature/SomeTest.php would cover it.

Steps to reproduce
  1. Write a Pest test whose failure comes from an exception in application code:
    it("fails", function () {
        Livewire::test(SomeComponent::class); // throws inside the component
    });
    
  2. Run it from the gutter or the Test Explorer.
  3. The test is marked as failed, but no message appears in the test file. Expected: the message at tests/Feature/SomeTest.php:146, as in 3.9.40.
Extension settings
{
    "phpunit.command": "docker compose exec -u sail -e XDEBUG_MODE=debug,coverage laravel.test",
    "phpunit.phpunit": "vendor/bin/pest",
    "phpunit.php": "php -dxdebug.start_with_request=1",
    "phpunit.args": ["-c", "phpunit.xml", "--coverage-cobertura", "cobertura.xml"],
    "phpunit.paths": { "${workspaceFolder}": "/var/www/html" }
}
Output channel log
##teamcity[testFailed name='it fails' message='...' details='at app/Livewire/SomeComponent.php:48|nat tests/Feature/SomeTest.php:146' flowId='...']
Environment
  • OS: Windows with WSL2 (Linux)
  • VS Code version: 1.145.0
  • Extension version: 3.10.1 (works in 3.9.40)
  • PHP version: 8.5.12
  • PHPUnit / Pest version: PHPUnit 12.5.33 / Pest 4.7.8
  • Run environment: Docker (Laravel Sail) via VS Code Remote - WSL
Project structure (if relevant)
project/
├── phpunit.xml
├── app/
└── tests/
    ├── Pest.php
    ├── TestCase.php
    └── Feature/
        └── SomeTest.php
Dominant language
TypeScript
Stars
169
Forks
72
Avg merge
8m
Merged PRs (30d)
184

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from recca0120/vscode-phpunit

All issues in recca0120/vscode-phpunit

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.