Closed dcblogdev closed 3 years ago
I managed to make it work coping the Pest.php
file to de Modules
folder. And to run the tests I ran in the console ./vendor/bin/pest --test-directory Modules
. I think that will be better if we can run all tests, both in tests
and Modules
folders.
Pest.php inside Modules:
uses(Tests\TestCase::class)->in('');
Thanks you! this test now runs:
use App\Http\Livewire\Counter;
use function Pest\Livewire\livewire;
uses(Tests\TestCase::class);
it('can be incremented', function () {
livewire(Counter::class)
->call('increment')
->assertSee(1);
});
As you mentioned running the test runner with options runs ./vendor/bin/pest --test-directory Modules
It would be nice it the normal ./vendor/bin/pest
worked but this workaround works for me.
In PhpStorm the default ./vendor/bin/pest
test runner is used to add the options edit the test configuration:
To have all tests configurations have this out the box add --test-directory Modules
to the test runner options in the configuration template:
Running ./vendor/bin/pest --test-directory Modules --parallel
returns the original error
Call to undefined method Tests\TestCase::livewire()
But at least I can run the tests without using parallel for now.
No plans to investigate this issue. Fell free to submit a pull request that addresses this issue.
Hi @dcblogdev , are you still using PESTPHP with Laravel Modules? I currently use Laravel Modules and am learning PESTPHP.
Could you tell us a little about your experience so far?
I'm thinking about getting started using Inertia.js in my projects too, so I'm still studying about that.
Thanks
@garbinmarcelo pest works fine with modules now.
most of the time you only need to import:
uses(Tests\TestCase::class);
for example:
<?php
use Modules\Contacts\Models\Contact;
uses(Tests\TestCase::class);
test('can see contact list', function() {
$this->authenticate();
$this->get(route('app.contacts.index'))->assertOk();
});
It seems to me that the best option is to specify the full path to the module Example:
// Pest.php
uses(Tests\TestCase::class)->in(
'Feature',
__DIR__ . '/../Modules/TestModule/Tests/Feature',
);
uses(Illuminate\Foundation\Testing\RefreshDatabase::class)->in(
'Feature',
__DIR__ . '/../Modules/TestModule/Tests/Feature',
);
@dcblogdev did you have some update with parallel testing?
It's working fine for me, but I need coverage in parallel mode
For me, nothing worked except following what's mentioned in the documentation lol.
I tried the method specified above like this but it didn't work:
uses(
DuskTestCase::class,
DatabaseMigrations::class
)->in(__DIR__ . '/../Modules/TestModule/Tests/Feature');
But adding the module pattern like this worked like a charm:
uses(
DuskTestCase::class,
DatabaseMigrations::class
)->in('../Modules/*/Tests/Feature');
Plus we don't need to mention it for every single module 🥳.
I would really like to use PEST with Laravel Modules package. (https://github.com/nWidart/laravel-modules)
PEST runs with modules by itself but where the problem lies is the plugins for example I have a fresh Laravel install with a contacts module which has this test file
ContactTest.php
When I run the test I get:
I have these installed:
I've uploaded a demo project to show this.
https://github.com/dcblogdev/laravel-module-pest-demo/blob/master/Modules/Contacts/Tests/Feature/ContactTest.php
Are there any steps I need to complete?