chore: uses snapshot testing in some visual testing

This commit is contained in:
Nuno Maduro
2023-06-17 13:36:39 +01:00
parent 36b585835d
commit b1c6f247e0
8 changed files with 14 additions and 31 deletions

View File

@ -76,7 +76,7 @@
"test:inline": "php bin/pest --colors=always --configuration=phpunit.inline.xml",
"test:parallel": "php bin/pest --colors=always --exclude-group=integration --parallel --processes=10",
"test:integration": "php bin/pest --colors=always --group=integration",
"update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always",
"update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always --update-snapshots",
"test": [
"@test:refacto",
"@test:lint",

View File

@ -107,6 +107,10 @@ final class Help implements HandlesArguments
'arg' => '--parallel',
'desc' => 'Run tests in parallel',
],
[
'arg' => '--update-snapshots',
'desc' => 'Update snapshots for tests using the "toMatchSnapshot" expectation',
],
], ...$content['Execution']];
$content['Selection'] = [[

View File

@ -34,6 +34,7 @@
EXECUTION OPTIONS:
--parallel ........................................... Run tests in parallel
--update-snapshots Update snapshots for tests using the "toMatchSnapshot" expectation
--process-isolation ................ Run each test in a separate PHP process
--globals-backup ................. Backup and restore $GLOBALS for each test
--static-backup ......... Backup and restore static properties for each test

View File

@ -1,12 +1,6 @@
<?php
test('collision', function (array $arguments) {
$snapshot = __DIR__.'/../.snapshots/collision.txt';
if (in_array('--parallel', $arguments)) {
$snapshot = __DIR__.'/../.snapshots/collision-parallel.txt';
}
$output = function () use ($arguments) {
$process = (new Symfony\Component\Process\Process(
array_merge(['php', 'bin/pest', 'tests/Fixtures/CollisionTest.php'], $arguments),
@ -19,7 +13,6 @@ test('collision', function (array $arguments) {
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
};
if (getenv('REBUILD_SNAPSHOTS')) {
$outputContent = explode("\n", $output());
array_pop($outputContent);
array_pop($outputContent);
@ -30,12 +23,7 @@ test('collision', function (array $arguments) {
array_pop($outputContent);
}
file_put_contents($snapshot, implode("\n", $outputContent));
$this->markTestSkipped('Snapshot rebuilt.');
}
expect($output())->toContain(file_get_contents($snapshot));
expect(implode("\n", $outputContent))->toMatchSnapshot();
})->with([
[['']],
[['--parallel']],

View File

@ -1,8 +1,6 @@
<?php
test('visual snapshot of help command output', function () {
$snapshot = __DIR__.'/../.snapshots/help-command.txt';
$output = function () {
$process = (new Symfony\Component\Process\Process(['php', 'bin/pest', '--help'], null, ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true']));
@ -11,11 +9,5 @@ test('visual snapshot of help command output', function () {
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
};
if (getenv('REBUILD_SNAPSHOTS')) {
file_put_contents($snapshot, $output());
$this->markTestSkipped('Snapshot rebuilt.');
}
expect($output())->toContain(file_get_contents($snapshot));
expect($output())->toMatchSnapshot();
})->skipOnWindows();

View File

@ -11,8 +11,6 @@ $run = function () {
$process->run();
// expect($process->getExitCode())->toBe(0);
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
};