feat(tia): let a project leave paths out of read capture (#2030)

* feat(tia): let a project leave paths out of read capture

* Verify TIA watch fallbacks and refresh snapshots

---------

Co-authored-by: Sylvain Valienne <2300259+sylouuu@users.noreply.github.com>
Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com>
This commit is contained in:
Syl
2026-11-20 14:11:03 +01:00
committed by GitHub
parent fdc57f77b7
commit 41af35a3f2
8 changed files with 366 additions and 3 deletions
+100
View File
@@ -2,8 +2,11 @@
declare(strict_types=1);
use Pest\Plugins\Tia\Configuration;
use Pest\Plugins\Tia\ReadCapture;
use Pest\Plugins\Tia\Recorder;
use Pest\Plugins\Tia\WatchPatterns;
use Pest\Support\Container;
use Tests\Fixtures\Tia\LoggingFileWrapper;
/**
@@ -294,3 +297,100 @@ describe('a wrapper already registered for file://', function (): void {
->and(tiaReadCaptureWrapperClass())->toBe(LoggingFileWrapper::class);
});
});
describe('withoutReadCapture()', function (): void {
beforeEach(function (): void {
Container::getInstance()->add(WatchPatterns::class, new WatchPatterns);
$this->excluded = (string) realpath(dirname(__DIR__, 4).'/src/Plugins/Tia/ReadCapture.php');
$this->kept = (string) realpath(dirname(__DIR__, 4).'/src/Plugins/Tia/Recorder.php');
});
afterEach(function (): void {
Container::getInstance()->add(WatchPatterns::class, new WatchPatterns);
});
it('does not link a file matching an excluded glob', function (): void {
(new Configuration)->withoutReadCapture(['src/Plugins/Tia/Read*.php']);
expect(tiaReadCaptureLinks(fn (): string|false => file_get_contents($this->excluded)))->toBeEmpty();
});
it('still links a file outside the excluded globs', function (): void {
(new Configuration)->withoutReadCapture(['src/Plugins/Tia/Read*.php']);
$links = tiaReadCaptureLinks(function (): void {
file_get_contents($this->excluded);
file_get_contents($this->kept);
});
expect($links)->toBe([$this->kept]);
});
it('keeps the file wrapper registered while globs are excluded', function (): void {
(new Configuration)->withoutReadCapture(['src/Plugins/Tia/Read*.php']);
$during = '';
tiaReadCaptureLinks(function () use (&$during): void {
$during = tiaReadCaptureWrapperType();
});
expect($during)->toBe('user-space');
});
it('links every read when the list of globs is empty', function (): void {
(new Configuration)->withoutReadCapture([]);
expect(tiaReadCaptureLinks(fn (): string|false => file_get_contents($this->excluded)))->toBe([$this->excluded]);
});
it('registers no wrapper and links no read when called without globs', function (): void {
(new Configuration)->withoutReadCapture();
$during = '';
$links = tiaReadCaptureLinks(function () use (&$during): void {
$during = tiaReadCaptureWrapperType();
file_get_contents($this->kept);
});
expect($during)->toBe('plainfile')
->and($links)->toBeEmpty()
->and(tiaReadCaptureWrapperType())->toBe('plainfile');
});
it('keeps the explicit links when called without globs', function (): void {
(new Configuration)->withoutReadCapture();
$recorder = new Recorder;
$recorder->activateLinkTracking();
$recorder->beginTest('Some\Missing\TestClass', 'it links', '/project/tests/Feature/LinksTest.php');
$recorder->linkSource('/project/resources/views/welcome.blade.php');
$recorder->endTest();
expect($recorder->perTestFiles())
->toBe(['/project/tests/Feature/LinksTest.php' => ['/project/resources/views/welcome.blade.php']]);
});
it('leaves a wrapper already registered for file:// untouched when called without globs', function (): void {
(new Configuration)->withoutReadCapture();
LoggingFileWrapper::enable();
try {
$during = null;
$links = tiaReadCaptureLinks(function () use (&$during): void {
$during = tiaReadCaptureWrapperClass();
file_get_contents($this->kept);
});
} finally {
LoggingFileWrapper::disable();
}
expect($during)->toBe(LoggingFileWrapper::class)
->and($links)->toBeEmpty();
});
});