m1guelpf / better-pest

A better Pest test runner for VS Code
https://marketplace.visualstudio.com/items?itemName=m1guelpf.better-pest
45 stars 9 forks source link

Fails when config helper function is used #4

Open neeravp opened 3 years ago

neeravp commented 3 years ago

What are the steps to reproduce this issue?

test('it can read config values', function() {
    $this->assertEquals(config('my-package.name'), 'My Package');
}

When running the test using Cmd+K, Cmd+R

What happens

It gives an error Target class [config] does not exist.

What were you expecting to happen?

It should run the test without giving the above error. When I run the test from terminal it runs flawlessly without any error. I am running this test from within a local package using Orchestra Testbench.

Any logs, error output, etc?

Any other comments?

It's actually not picking up tests\Pest.php or even uses(Orchestra\Testbench\TestCase::class) in the file when run thru the extension in vscode (from within a local Laravel package) However, it picks up both tests\Pest.php and/or uses(Orchestra\Testbench\TestCase::class) in the file when run from the terminal (again from within a local Laravel Package)

What versions are you using?

Operating System: macOS 10.15.7 Package Version: 0.3.1

issue-label-bot[bot] commented 3 years ago

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.85. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

m1guelpf commented 3 years ago

@neeravp Can you copy the command that's being run? It should show before the error

neeravp commented 3 years ago
Executing task: /Users/neerav/Sites/pcg/modules/studeo/vendor/bin/pest /Users/neerav/Sites/pcg/modules/studeo/tests/Unit/StudeoTest.php --filter 'knows the path' --configuration /Users/neerav/Sites/pcg/modules/studeo/phpunit.xml <

   FAIL  Modules\studeo\vendor\pestphp\pest\bin\pest

Digging a little, I think the issue arises because the $rootPath in vendor/pestphp/pest/bin/pest as well as vendor/pestphp/pest/src/Actions/LoadStructure.php always takes the project root and not the package root.

My file structure is as below

LaravelApp
|-app
|- other default laravel folders/directories
|-modules
    |-mypackage
      |-src
      |-tests
        |-Unit
        |-Feature
      |-vendor (contains pestphp)

When I try running any test from within Unit or Feature folder within mypackage/tests the $rootPath is being set to LaravelApp and not mypackage so it doesn't pick up on the Pest.php file in the mypackage/tests directory.

If you look at the task being executed it is being executed from /Users/neerav/Sites/pcg/modules/studeo/vendor/bin/pest, however when I check for $rootPath in vendor/pestphp/pest/bin/pest or vendor/pestphp/pest/src/Actions/LoadStructure.php using dd($rootPath) I'm getting /Users/neerav/Sites/pcg

neeravp commented 3 years ago

@m1guelpf Any update?? I'm really missing the ease of running the tests directly from vscode.

neeravp commented 3 years ago

@m1guelpf Still awaiting update. Will you be able to spare time to look in to the issue and try to get it fixed soon? Or is it that your current commitments makes it difficult to spare time for the same. I would really be very happy to have a fix asap - I understand you may be busy with your other pressing commitments though Keeping fingers crossed

thinkstudeo commented 3 years ago

Hey @m1guelpf Tried to look in the code and solve the issue to submit a PR, however could not get to wrap my head around. Would you be able to spare time and look in the issue?