Skip to content

Commit

Permalink
Improved the session and build name in BrowserStack
Browse files Browse the repository at this point in the history
  • Loading branch information
chinleung committed Feb 4, 2025
1 parent 5218963 commit ff173f4
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions src/RunsOnBrowserStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,11 @@ protected function getBrowserSlug(): ?string
*/
protected function getBuildName(): string
{
$sha = env('GITHUB_SHA');

if ($sha === null) {
return gethostname();
}
$sha = env('GITHUB_SHA') ?? exec('git rev-parse HEAD');

return sprintf(
'%s @ %s',
'%s — %s — %s',
gethostname(),
str_replace('refs', '', $sha),
env('GITHUB_REF', config('app.env'))
);
Expand All @@ -308,23 +305,14 @@ protected function getSessionName(): string
{
$class = get_called_class();

$traces = collect(debug_backtrace());

$pest = $traces->where('class', 'Pest\Kernel')->first();

if ($pest) {
$function = Str::after(Arr::get($pest, 'args.0.4'), '::');
} else {
$function = Arr::get(
$traces->firstWhere('class', $class),
'function'
);
}
$name = Str::of($this->name())
->after('__pest_evaluable_')
->replace('_', ' ');

return sprintf(
'%s @ %s',
class_basename($class),
$function ?? 'Unknown function'
$name->toString()
);
}

Expand Down

0 comments on commit ff173f4

Please sign in to comment.