Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 2 additions & 35 deletions src/Plugins/Snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Pest\Plugins;

use Pest\Contracts\Plugins\HandlesArguments;
use Pest\Support\Ci;
use Pest\TestSuite;

/**
Expand All @@ -16,34 +17,9 @@ final class Snapshot implements HandlesArguments

public static bool $updateSnapshots = false;

/**
* @var list<string>
*/
private const array CI_ENVIRONMENT_VARIABLES = [
'CI',
'GITHUB_ACTIONS',
'GITLAB_CI',
'CIRCLECI',
'TRAVIS',
'APPVEYOR',
'BITBUCKET_BUILD_NUMBER',
'BUILDKITE',
'TEAMCITY_VERSION',
'JENKINS_URL',
'SYSTEM_COLLECTIONURI',
'CI_NAME',
'TASKCLUSTER_ROOT_URL',
'DRONE',
'WERCKER',
'NEVERCODE',
'SEMAPHORE',
'NETLIFY',
'NOW_BUILDER',
];

public static function shouldCreateMissingSnapshots(): bool
{
return self::$updateSnapshots || ! self::runningOnCI();
return self::$updateSnapshots || ! Ci::isRunning();
}

/**
Expand Down Expand Up @@ -149,13 +125,4 @@ private function isFullRun(array $arguments): bool

return true;
}

private static function runningOnCI(): bool
{
if (Environment::name() === Environment::CI) {
return true;
}

return array_any(self::CI_ENVIRONMENT_VARIABLES, fn (string $environmentVariable): bool => getenv($environmentVariable) !== false);
}
}
13 changes: 1 addition & 12 deletions src/Plugins/Tia.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ final class Tia implements AddsOutput, HandlesArguments, HandlesOriginalArgument

private bool $unreadableGraphReported = false;

private bool $detachedHead = false;

private bool $graphUnreachable = false;

/** @var array<int, string> */
Expand Down Expand Up @@ -281,19 +279,11 @@ private function discardUnreadableGraph(): void

private function deleteState(string $key): bool
{
if ($this->detachedHead) {
return false;
}

return $this->state->delete($key);
}

private function saveGraph(Graph $graph): bool
{
if ($this->detachedHead) {
return true;
}

$json = $graph->encode();

if ($json === null) {
Expand Down Expand Up @@ -849,7 +839,7 @@ private function handleParent(array $arguments, string $projectRoot, bool $force
$fingerprint = Fingerprint::compute($projectRoot);
$this->startFingerprint = $fingerprint;

if ($forceRebuild && ! $this->detachedHead) {
if ($forceRebuild) {
Storage::purge($projectRoot);
}

Expand Down Expand Up @@ -1943,7 +1933,6 @@ private function resolveBranch(string $projectRoot): void

$currentBranch = $changedFiles->currentBranch();

$this->detachedHead = $currentBranch === null;
$this->branch = $currentBranch ?? $this->fallbackBranch;
}

Expand Down
10 changes: 2 additions & 8 deletions src/Plugins/Tia/BaselineSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Pest\Panic;
use Pest\Plugins\Tia;
use Pest\Plugins\Tia\Contracts\State;
use Pest\Support\Ci;
use Pest\Support\View;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;
Expand Down Expand Up @@ -164,7 +165,7 @@ private function formatDuration(int $seconds): string

private function emitPublishInstructions(): void
{
if ($this->isCi()) {
if (Ci::isRunning()) {
$this->renderBadge('INFO', 'No baseline yet — this run will produce one.');

return;
Expand All @@ -174,13 +175,6 @@ private function emitPublishInstructions(): void
$this->renderChild('See https://pestphp.com/docs/tia for how to publish one from CI.');
}

private function isCi(): bool
{
return getenv('GITHUB_ACTIONS') === 'true'
|| getenv('GITLAB_CI') === 'true'
|| getenv('CIRCLECI') === 'true';
}

private function detectGitHubRepo(string $projectRoot): ?string
{
$gitConfig = $projectRoot.DIRECTORY_SEPARATOR.'.git'.DIRECTORY_SEPARATOR.'config';
Expand Down
47 changes: 47 additions & 0 deletions src/Support/Ci.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Pest\Support;

use Pest\Plugins\Environment;

/**
* @internal
*/
final class Ci
{
/**
* @var list<string>
*/
private const array ENVIRONMENT_VARIABLES = [
'CI',
'GITHUB_ACTIONS',
'GITLAB_CI',
'CIRCLECI',
'TRAVIS',
'APPVEYOR',
'BITBUCKET_BUILD_NUMBER',
'BUILDKITE',
'TEAMCITY_VERSION',
'JENKINS_URL',
'SYSTEM_COLLECTIONURI',
'CI_NAME',
'TASKCLUSTER_ROOT_URL',
'DRONE',
'WERCKER',
'NEVERCODE',
'SEMAPHORE',
'NETLIFY',
'NOW_BUILDER',
];

public static function isRunning(): bool
{
if (Environment::name() === Environment::CI) {
return true;
}

return array_any(self::ENVIRONMENT_VARIABLES, fn (string $env): bool => getenv($env) !== false);
}
}
12 changes: 6 additions & 6 deletions tests/Features/Tia/StateReclamation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Project::destroyAll();
});

test('a detached HEAD does not purge the graph on structural drift', function (array $arguments): void {
test('a detached HEAD can rebuild the graph on structural drift', function (array $arguments): void {
$project = Project::make('master');
$project->seed('master');

Expand All @@ -25,10 +25,10 @@

expect($result->exitCode)->toBe(0, $result->describe())
->and($project->graphExists())->toBeTrue('the detached run deleted graph.json')
->and($delta->isHardSuppressed())->toBeTrue($delta->summary());
->and($delta->structureMoved())->toBeTrue($delta->summary());
})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows();

test('a detached HEAD does not purge the graph with --fresh either', function (array $arguments): void {
test('a detached HEAD can rebuild the graph with --fresh', function (array $arguments): void {
$project = Project::make('master');
$project->seed('master');

Expand All @@ -39,10 +39,10 @@

expect($result->exitCode)->toBe(0, $result->describe())
->and($project->graphExists())->toBeTrue('the detached --fresh run deleted graph.json')
->and($delta->isHardSuppressed())->toBeTrue($delta->summary());
->and($delta->structureMoved())->toBeTrue($delta->summary());
})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows();

test('a detached HEAD leaves an unreadable graph for a checkout that can rebuild it', function (): void {
test('a detached HEAD can replace an unreadable graph for a checkout that can rebuild it', function (): void {
$project = Project::make('master');
$project->seed('master');

Expand All @@ -54,7 +54,7 @@

expect($result->exitCode)->toBe(0, $result->describe())
->and($result->tally())->toContain(Project::TOTAL_TESTS.' passed')
->and(file_get_contents($project->graphDir().'/graph.json'))->toBe('{not json');
->and(file_get_contents($project->graphDir().'/graph.json'))->not->toBe('{not json');
})->skipOnWindows();

test('a cached failure whose test file was deleted stops widening later runs', function (array $arguments): void {
Expand Down