Skip to content

Commit

Permalink
Update TransloaditTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
kvz committed Nov 26, 2024
1 parent 434548a commit 63ad07d
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions test/simple/TransloaditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ private function getExpectedUrl(array $params): ?string {
return null;
}

if (system('which tsx > /dev/null 2>&1') === false) {
throw new \RuntimeException('tsx not found. Please install it with: npm install -g tsx');
// Check for tsx before trying to use it
exec('which tsx 2>/dev/null', $output, $returnVar);
if ($returnVar !== 0) {
throw new \RuntimeException('tsx command not found. Please install it with: npm install -g tsx');
}

$scriptPath = __DIR__ . '/../../tool/node-smartcdn-sig.ts';
Expand Down Expand Up @@ -324,4 +326,32 @@ public function testSignedSmartCDNUrl() {
);
$this->assertParityWithNode($url, $params);
}

public function testTsxRequiredForParityTesting(): void {
if (getenv('TEST_NODE_PARITY') !== '1') {
$this->markTestSkipped('Parity testing not enabled');
}

// Temporarily override PATH to simulate missing tsx
$originalPath = getenv('PATH');
putenv('PATH=/usr/bin:/bin');

try {
$params = [
'workspace' => 'test',
'template' => 'test',
'input' => 'test.jpg',
'auth_key' => 'test',
'auth_secret' => 'test'
];
$this->getExpectedUrl($params);
$this->fail('Expected RuntimeException when tsx is not available');
} catch (\RuntimeException $e) {
$this->assertStringContainsString('tsx command not found', $e->getMessage());
$this->assertStringContainsString('npm install -g tsx', $e->getMessage());
} finally {
// Restore original PATH
putenv("PATH=$originalPath");
}
}
}

0 comments on commit 63ad07d

Please sign in to comment.