mirror of
https://github.com/pestphp/pest.git
synced 2026-09-06 14:53:35 +02:00
fix(tia): replayable scenarios running afterEach
This commit is contained in:
@@ -18,7 +18,7 @@ $run = function (string $target): array {
|
||||
};
|
||||
|
||||
test('reports missing datasets as errors for a single file run', function () use ($run): void {
|
||||
$result = $run('tests/.tests/IssueOnly.php');
|
||||
$result = $run('tests/Fixtures/Suites/IssueOnly.php');
|
||||
|
||||
expect($result['output'])
|
||||
->toContain("A dataset with the name `missing` does not exist. You can create it using `dataset('missing', ['a', 'b']);`.")
|
||||
@@ -28,7 +28,7 @@ test('reports missing datasets as errors for a single file run', function () use
|
||||
})->skipOnWindows();
|
||||
|
||||
test('reports missing datasets as errors alongside passing tests', function () use ($run): void {
|
||||
$result = $run('tests/.tests/IssueWithPassing.php');
|
||||
$result = $run('tests/Fixtures/Suites/IssueWithPassing.php');
|
||||
|
||||
expect($result['output'])
|
||||
->toContain("A dataset with the name `missing` does not exist. You can create it using `dataset('missing', ['a', 'b']);`.")
|
||||
@@ -38,7 +38,7 @@ test('reports missing datasets as errors alongside passing tests', function () u
|
||||
})->skipOnWindows();
|
||||
|
||||
test('reports dataset closure exceptions as errors', function () use ($run): void {
|
||||
$result = $run('tests/.tests/DatasetClosureThrows.php');
|
||||
$result = $run('tests/Fixtures/Suites/DatasetClosureThrows.php');
|
||||
|
||||
expect($result['output'])
|
||||
->toContain('boom from dataset')
|
||||
|
||||
@@ -142,7 +142,7 @@ it('works as higher order test')
|
||||
|
||||
it('fails after exhausting all retries', function (): void {
|
||||
$process = new Process(
|
||||
['php', 'bin/pest', 'tests/.tests/FlakyFailure.php'],
|
||||
['php', 'bin/pest', 'tests/Fixtures/Suites/FlakyFailure.php'],
|
||||
dirname(__DIR__, 2),
|
||||
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'],
|
||||
);
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
use Pest\Plugins\Tia;
|
||||
use Pest\Plugins\Tia\ChangedFiles;
|
||||
use Pest\Plugins\Tia\FileState;
|
||||
use Pest\Plugins\Tia\Fingerprint;
|
||||
use Pest\Plugins\Tia\Graph;
|
||||
use Pest\Plugins\Tia\Storage;
|
||||
use Pest\Support\Str;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
it('does not run user hooks when replaying cached skipped and incomplete results', function (): void {
|
||||
$projectRoot = dirname(__DIR__, 2);
|
||||
$home = sys_get_temp_dir().'/pest-tia-'.bin2hex(random_bytes(8));
|
||||
$fixture = 'tests/Fixtures/Suites/TiaReplayHooks.php';
|
||||
|
||||
mkdir($home, 0755, true);
|
||||
|
||||
try {
|
||||
$changedFiles = new ChangedFiles($projectRoot);
|
||||
$branch = $changedFiles->currentBranch() ?? 'main';
|
||||
$sha = $changedFiles->currentSha();
|
||||
|
||||
$id = fn (string $description): string => 'P\Tests\Fixtures\Suites\TiaReplayHooks::'.Str::evaluable($description);
|
||||
|
||||
$graph = new Graph($projectRoot);
|
||||
$graph->setFingerprint(Fingerprint::compute($projectRoot));
|
||||
$graph->setRecordedAtSha($branch, $sha);
|
||||
// Hashes the working tree as it stands, so the replay sees nothing as changed.
|
||||
$graph->setLastRunTree($branch, $changedFiles->snapshotTree($changedFiles->since($sha) ?? []));
|
||||
$graph->markKnownTestFiles([$fixture]);
|
||||
$graph->setResult($branch, $id('replayed pass'), 0, '', 0.01, 1, $fixture);
|
||||
$graph->setResult($branch, $id('replayed skip'), 1, 'cached skip', 0.01, 0, $fixture);
|
||||
$graph->setResult($branch, $id('replayed incomplete'), 2, 'cached incomplete', 0.01, 0, $fixture);
|
||||
|
||||
$json = $graph->encode();
|
||||
|
||||
expect($json)->not->toBeNull();
|
||||
|
||||
$originalHome = getenv('HOME');
|
||||
putenv('HOME='.$home);
|
||||
|
||||
try {
|
||||
$storage = new FileState(Storage::tempDir($projectRoot));
|
||||
} finally {
|
||||
putenv($originalHome === false ? 'HOME' : 'HOME='.$originalHome);
|
||||
}
|
||||
|
||||
expect($storage->write(Tia::KEY_GRAPH, (string) $json))->toBeTrue();
|
||||
|
||||
$process = new Process(
|
||||
['php', 'bin/pest', $fixture, '--tia'],
|
||||
$projectRoot,
|
||||
[
|
||||
'COLLISION_PRINTER' => 'DefaultPrinter',
|
||||
'COLLISION_IGNORE_DURATION' => 'true',
|
||||
'PARATEST' => 0,
|
||||
'PAO_DISABLE' => '1',
|
||||
'HOME' => $home,
|
||||
],
|
||||
);
|
||||
|
||||
$process->run();
|
||||
|
||||
$output = removeAnsiEscapeSequences($process->getOutput().$process->getErrorOutput());
|
||||
|
||||
// Both hooks throw, so the run stays green only if neither one ran.
|
||||
expect($output)->toContain('3 replayed')
|
||||
->and($output)->not->toContain('must not run for replayed tests')
|
||||
->and($output)->toContain('1 incomplete, 1 skipped, 1 passed')
|
||||
->and($process->getExitCode())->toBe(0);
|
||||
} finally {
|
||||
$paths = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($home, FilesystemIterator::SKIP_DOTS),
|
||||
RecursiveIteratorIterator::CHILD_FIRST,
|
||||
);
|
||||
|
||||
foreach ($paths as $path) {
|
||||
$path->isDir() ? @rmdir($path->getPathname()) : @unlink($path->getPathname());
|
||||
}
|
||||
|
||||
@rmdir($home);
|
||||
}
|
||||
})->skipOnWindows();
|
||||
Reference in New Issue
Block a user