mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
tests: refactor visual testing
This commit is contained in:
7
tests/.snapshots/allows-to-run-a-directory.txt
Normal file
7
tests/.snapshots/allows-to-run-a-directory.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
||||||
|
✓ it example 1
|
||||||
|
|
||||||
|
PASS Tests\Fixtures\ExampleTest
|
||||||
|
✓ it example 2
|
||||||
|
|
||||||
|
Tests: 2 passed
|
||||||
4
tests/.snapshots/allows-to-run-a-single-test.txt
Normal file
4
tests/.snapshots/allows-to-run-a-single-test.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
||||||
|
✓ it example 1
|
||||||
|
|
||||||
|
Tests: 1 passed
|
||||||
5
tests/.snapshots/disable-decorating-printer.txt
Normal file
5
tests/.snapshots/disable-decorating-printer.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
||||||
|
✓ [2mit example 1[22m
|
||||||
|
|
||||||
|
Tests: 1 passed
|
||||||
5
tests/.snapshots/has-ascii-chars.txt
Normal file
5
tests/.snapshots/has-ascii-chars.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
[30;42;1m PASS [39;49;22m[39m Tests\Fixtures\DirectoryWithTests\ExampleTest[39m
|
||||||
|
[32;1m✓[39;22m[39m [2mit example 1[22m[39m
|
||||||
|
|
||||||
|
[37;1mTests: [39;22m[32;1m1 passed[39;22m
|
||||||
@ -128,11 +128,11 @@
|
|||||||
PASS Tests\Visual\SingleTestOrDirectory
|
PASS Tests\Visual\SingleTestOrDirectory
|
||||||
✓ allows to run a single test
|
✓ allows to run a single test
|
||||||
✓ allows to run a directory
|
✓ allows to run a directory
|
||||||
✓ it has ascii chars (decorated printer)
|
✓ it has ascii chars
|
||||||
✓ it disable decorating printer when colors is set to never
|
✓ it disable decorating printer when colors is set to never
|
||||||
|
|
||||||
WARN Tests\Visual\Success
|
WARN Tests\Visual\Success
|
||||||
s visual snapshot of test suite on success
|
s visual snapshot of test suite on success
|
||||||
|
|
||||||
Tests: 6 skipped, 71 passed
|
Tests: 6 skipped, 71 passed
|
||||||
Time: 2.89s
|
Time: 2.87s
|
||||||
|
|||||||
@ -2,53 +2,42 @@
|
|||||||
|
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
$run = function (string $target) {
|
$run = function (string $target, $decorated = false) {
|
||||||
$process = new Process(['php', 'bin/pest', $target], dirname(__DIR__, 2));
|
$process = new Process(['php', 'bin/pest', $target], dirname(__DIR__, 2));
|
||||||
|
|
||||||
$process->run();
|
$process->run();
|
||||||
|
|
||||||
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
return $decorated ? $process->getOutput() : preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
|
||||||
};
|
};
|
||||||
|
|
||||||
test('allows to run a single test', function () use ($run) {
|
$testsPath = dirname(__DIR__);
|
||||||
assertStringContainsString(<<<EOF
|
$snapshot = fn (string $name) => file_get_contents(implode(DIRECTORY_SEPARATOR, [
|
||||||
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
$testsPath,
|
||||||
✓ it example 1
|
'.snapshots',
|
||||||
|
"$name.txt",
|
||||||
|
]));
|
||||||
|
|
||||||
Tests: 1 passed
|
test('allows to run a single test', function () use ($run, $snapshot) {
|
||||||
EOF, $run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'));
|
assertStringContainsString(
|
||||||
|
$snapshot('allows-to-run-a-single-test'),
|
||||||
|
$run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('allows to run a directory', function () use ($run) {
|
test('allows to run a directory', function () use ($run, $snapshot) {
|
||||||
assertStringContainsString(<<<EOF
|
assertStringContainsString(
|
||||||
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
$snapshot('allows-to-run-a-directory'),
|
||||||
✓ it example 1
|
$run('tests/Fixtures')
|
||||||
|
);
|
||||||
PASS Tests\Fixtures\ExampleTest
|
|
||||||
✓ it example 2
|
|
||||||
|
|
||||||
Tests: 2 passed
|
|
||||||
EOF, $run('tests/Fixtures'));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has ascii chars (decorated printer)', function () {
|
it('has ascii chars', function () use ($run, $snapshot) {
|
||||||
$process = new Process([
|
assertStringContainsString(
|
||||||
'php',
|
$snapshot('has-ascii-chars'),
|
||||||
'./bin/pest',
|
$run('tests/Fixtures/DirectoryWithTests/ExampleTest.php', true)
|
||||||
'tests/Fixtures/DirectoryWithTests/ExampleTest.php',
|
);
|
||||||
], dirname(__DIR__, 2));
|
|
||||||
|
|
||||||
$process->run();
|
|
||||||
$output = $process->getOutput();
|
|
||||||
assertStringContainsString(<<<EOF
|
|
||||||
\e[30;42;1m PASS \e[39;49;22m\e[39m Tests\Fixtures\DirectoryWithTests\ExampleTest\e[39m
|
|
||||||
\e[32;1m✓\e[39;22m\e[39m \e[2mit example 1\e[22m\e[39m
|
|
||||||
|
|
||||||
\e[37;1mTests: \e[39;22m\e[32;1m1 passed\e[39;22m
|
|
||||||
EOF, $output);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('disable decorating printer when colors is set to never', function () {
|
it('disable decorating printer when colors is set to never', function () use ($snapshot) {
|
||||||
$process = new Process([
|
$process = new Process([
|
||||||
'php',
|
'php',
|
||||||
'./bin/pest',
|
'./bin/pest',
|
||||||
@ -58,10 +47,8 @@ it('disable decorating printer when colors is set to never', function () {
|
|||||||
$process->run();
|
$process->run();
|
||||||
$output = $process->getOutput();
|
$output = $process->getOutput();
|
||||||
|
|
||||||
assertStringContainsString(<<<EOF
|
assertStringContainsString(
|
||||||
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
|
$snapshot('disable-decorating-printer'),
|
||||||
✓ \e[2mit example 1\e[22m
|
$output
|
||||||
|
);
|
||||||
Tests: 1 passed
|
|
||||||
EOF, $output);
|
|
||||||
});
|
});
|
||||||
|
|||||||
6
tests/Visual/foo.txt
Normal file
6
tests/Visual/foo.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
[30;42;1m PASS [39;49;22m[39m Tests\Fixtures\DirectoryWithTests\ExampleTest[39m
|
||||||
|
[32;1m✓[39;22m[39m [2mit example 1[22m[39m
|
||||||
|
|
||||||
|
[37;1mTests: [39;22m[32;1m1 passed[39;22m
|
||||||
|
[37;1mTime: [39;22m[39m0.04s[39m
|
||||||
Reference in New Issue
Block a user