antonioribeiro / tddd

A Laravel Continuous Integration Package
MIT License
721 stars 57 forks source link

No route to access the dashboard in readme #11

Closed nWidart closed 6 years ago

nWidart commented 6 years ago

The readme doesn't say anything about which URI to go to.

The routes has a bunch, none worked for me.

antonioribeiro commented 6 years ago

As stated here, it should now be

 http://<domain.dev>/tests-watcher/dashboard
nWidart commented 6 years ago

This was added in this commit https://github.com/antonioribeiro/ci/commit/280c0f2cc1d85ae465a8434e49b8eeed7c0ebced

Which wasn't there before.

antonioribeiro commented 6 years ago

Yeah, the video was a preview. Version wasn't tagged when the video was tweeted. Sorry about that. But we still have a lot to improve in the docs.

nWidart commented 6 years ago

I see.

Since it's an application, would be nice to have an actual full project (compose create-project), with a docker container setup for instance. Instead of having to create the laravel project, require the package etc.

antonioribeiro commented 6 years ago

The starter app is here: https://github.com/antonioribeiro/tests-watcher-starter

nWidart commented 6 years ago

Nice. 👍 With docker doesn't seem it'll be possible to access other files sadly.

nWidart commented 6 years ago

Tried to access another folder

image

antonioribeiro commented 6 years ago

This directory

image

exists?

antonioribeiro commented 6 years ago

And, will you watch only your tests, not the code? Or those tests are your code?

nWidart commented 6 years ago

Yes, as you can see I ran ll on the directory path I copied, with the results. I'm not sure about what to watch, I'm first trying to make the thing work :D

I suspect however it's because the path is not accessible from within the docker container.

antonioribeiro commented 6 years ago

Somehow vendor/symfony/finder/Finder.php is not being able to find that directory

antonioribeiro commented 6 years ago

This is the command related to that error:

$files = Finder::create()->files()->in($suite->testsFullPath);

It could be permissions, does the PHP process has permissions to read all your files?

nWidart commented 6 years ago

I suspect however it's because the path is not accessible from within the docker container.

nWidart commented 6 years ago

I can confirm it was because of docker. Had to set the project up with mamp.

It's able to show my test files now, however when running, it fails with the message (empty), in the modal.

And the output in terminal:

---------------------------------------------------------------------------------------------------------------------------
Executing vendor/bin/phpunit  /Users/nicolaswidart/Sites/Asguard/Platform/Modules/Page/Tests/EloquentPageRepositoryTest.php
retrying...
retrying...
FAILED
antonioribeiro commented 6 years ago

Had to make some changes to it, enable script on your phpunit tester and add the bin:

    /**
     * script
     *
     */
    'script' => '/usr/bin/script -q %s %s', // sprintf()

    /**
     * Testers
     *
     */
    'testers' => [

        'phpunit' => [
            'command' => 'vendor/bin/phpunit',
            'require_script' => true,
        ],
nWidart commented 6 years ago

Thanks. I'm now getting:

script: vendor/bin/phpunit: No such file or directory

In the modal.

I changed the phpunit path to the one in the project:

'phpunit' => [
            'command' => '/Users/nicolaswidart/Sites/Asguard/Platform/vendor/bin/phpunit',
            'require_script' => true,
        ],

But still same error.

(Btw it could be nice to specify a phpunit path per project.)

antonioribeiro commented 6 years ago

Still on docker, right?

Tester show in terminal the exact command it is executing, could you test it manually, please?

Here's an example:

image

All paths are relative to projects, including execution

$this->shell->exec($command, $test->suite->project->path, ...

// which calls

public function exec($command, $runDir = null, Closure $callback = null, $timeout = null)
{
    $process = new Process($command, $runDir);
     ...   
}

That's why there's no starting slash in

'command' => 'vendor/bin/phpunit',

But, yes, it could also be nice to have it by project, makes sense, thanks!

nWidart commented 6 years ago

No, I had to setup with MAMP as mentionned, because inside the docker container, it had no access to local files.

This was the full output:

xecuting /usr/bin/script -q /private/var/folders/y7/ydfs5zlj2d92fk_1gywl_3680000gn/T/tw-Mq5tr5 vendor/bin/phpunit  /Users/nicolaswidart/Sites/Asguard/Platform/Modules/Page/Tests/PageContentIsRenderingTest.php
retrying...
retrying...
FAILED

It's still using vendor/bin/phpstorm still while I set the config to be the full path

        'phpunit' => [
            'command' => '/Users/nicolaswidart/Sites/Asguard/Platform/vendor/bin/phpunit',
            'require_script' => true,
        ],
antonioribeiro commented 6 years ago

script (/usr/bin/script) is installed, I presume.

works if you run it manually?:

/usr/bin/script -q /private/var/folders/y7/ydfs5zlj2d92fk_1gywl_3680000gn/T/tw-Mq5tr5 vendor/bin/phpunit  /Users/nicolaswidart/Sites/Asguard/Platform/Modules/Page/Tests/PageContentIsRenderingTest.php
nWidart commented 6 years ago

Hm I don't know what it is, but it exists yes. :P

Indeed, manually it runs:

image

antonioribeiro commented 6 years ago

Please try disabling script:

'require_script' => false,

It will not use script (it grabs everything printed in your terminal and send to a file) anymore, but you'll have to reboot watcher and tester.

I'm pretty sure it will make no difference, but that's already odd, because it's basically executing that line of code. It passes that command (and project path) to http://php.net/manual/en/function.proc-open.php.

nWidart commented 6 years ago

It indeed still fails with script: vendor/bin/phpunit: No such file or directory.

Full terminal output:

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Executing /usr/bin/script -q /private/var/folders/y7/ydfs5zlj2d92fk_1gywl_3680000gn/T/tw-N5GZ7a vendor/bin/phpunit  /Users/nicolaswidart/Sites/Asguard/Platform/Modules/Page/Tests/PageContentIsRenderingTest.php
retrying...
retrying...
FAILED
antonioribeiro commented 6 years ago

Still executing script

Executing /usr/bin/script -q

nWidart commented 6 years ago

Yup, but it's set to false.

I'm assuming that config isn't used, since the path to phpunit isn't read from the config either.

        'phpunit' => [
            'command' => '/Users/nicolaswidart/Sites/Asguard/Platform/vendor/bin/phpunit',
            'require_script' => false,
        ],
antonioribeiro commented 6 years ago

It is stored in a table, but updated on Watcher boot:

image

So if I change it to

image

And reboot watcher:

killall php
php artisan ci:watch

It changes here:

image

nWidart commented 6 years ago

Ah I see ok.

Now erroring with

PHPUnit 6.3.1 by Sebastian Bergmann and contributors.

Cannot open file "/Users/nicolaswidart/Sites/Asguard/Platform/Modules/Page/vendor/autoload.php".

This is normal as autoload is not in that folder.

Is it possible for this package to read the phpunit.xml file? For example to set up the test suites: https://github.com/AsgardCms/Platform/blob/3.0/phpunit.xml#L11

Tests are in the folder ./Modules/Page/Tests(for example) but, run it from the root dir of the project. Which I already do now with phpunit, reading the config file.

antonioribeiro commented 6 years ago

Project must be the root of your project, everything else, if you don't add a starting slash, is (almost a must be) relative to that path.

So if your app root is

/Users/nicolaswidart/Sites/Asguard

Your phpunit is probably at

/Users/nicolaswidart/Sites/Asguard/vendor/bin/phpunit

So your project config could be something like this:

'Asguard' => [
    'path' => '/Users/nicolaswidart/Sites/Asguard',
    'watch_folders' => [
        'Modules/Page/App',
        'Modules/Page/Tests'
    ],
    'exclude' => [
        'Modules/Page/Tests/console/',
        'Modules/Page/Tests/screenshots/',
    ],
    'depends' => [],
    'tests_path' => 'Modules/Page/Tests',
    'suites' => [
        'unit' => [
            'tester' => 'phpunit',
            'tests_path' => '',
            'command_options' => '',
            'file_mask' => '*Test.php',
            'retries' => 0,
        ],
        'browser' => [
            'tester' => 'dusk',
            'tests_path' => 'Browser',  // relative to the tests path
            'command_options' => '',
            'file_mask' => '*Test.php',
            'retries' => 0,
        ],
    ],
],

Of course this is just an example.

And, yes, I think it's possible to read the phpunit.xml and get some information from it.

nWidart commented 6 years ago

Yes, but I have more tests path. As you can see from the phpunit config file, there are multiple tests path.

nWidart commented 6 years ago

For now I had to duplicate the whole config section you posted, basically 1 project for each folder.

It works, tho not very easy to maintain. :D

image

antonioribeiro commented 6 years ago

Adding more suites could help you with your different tests paths:

    'Multiple suites' => [
        'path' => $basePath,
        'watch_folders' => [
            '.',
            'resources/assets/js/tests'
        ],
        'exclude' => [
            'storage',
            '.idea',
        ],
        'depends' => [],
        'tests_path' => 'tests/Multiple/',
        'suites' => [
            'module_page' => [
                'tester' => 'phpunit',
                'tests_path' => 'Page',
                'command_options' => '',
                'file_mask' => '*Test.php',
                'retries' => 0,
            ],
            'module_media' => [
                'tester' => 'phpunit',
                'tests_path' => 'Media',
                'command_options' => '',
                'file_mask' => '*Test.php',
                'retries' => 0,
            ],
        ],
    ],

image

nWidart commented 6 years ago

Hm interesting, I can try that.

nWidart commented 6 years ago

I tried this, but the watcher stops running w/o error, and dashboard has empty tests

'AsgardCMS' => [
    'path' => '/Users/nicolaswidart/Sites/Asguard/Platform',
    'watch_folders' => [
        'Modules/Page',
    ],
    'tests_path' => 'tests/Something',
    'exclude' => [],
    'depends' => [],
    'suites' => [
        'page_module' => [
            'tester' => 'phpunit',
            'tests_path' => 'Modules/Page/Tests',
            'command_options' => '',
            'file_mask' => '*Test.php',
            'retries' => 0,
        ],
        'core_module' => [
            'tester' => 'phpunit',
            'tests_path' => 'Modules/Core/Tests',
            'command_options' => '',
            'file_mask' => '*Test.php',
            'retries' => 0,
        ],
    ],
],
nWidart commented 6 years ago

Oh I see, I can leave the main "tests_path" empty. 👍

nWidart commented 6 years ago

It might be better to have multiple projects per folder, so that only the relevant tests are re-run with the watcher.

Ie, only run the tests in Modules/User/Tests if something in Modules/User was changed, and so on.

This is my full config:

https://gist.github.com/nWidart/bc029a875ea51e36a0bbbfc372d35ce0

antonioribeiro commented 6 years ago

Yes, in this case it's the best option, we could add an option in the suite to not watch for files outside the suite, but I think it could be even more confusing...

antonioribeiro commented 6 years ago

Can we close this one already?

nWidart commented 6 years ago

Yes. Thanks for your help! 👍