Changeset View
Changeset View
Standalone View
Standalone View
src/unit/engine/KarmaTestEngine.php
- This file was added.
<?php | |||||
/** | |||||
* Karma wrapper. | |||||
*/ | |||||
final class KarmaTestEngine extends ArcanistUnitTestEngine { | |||||
protected function supportsRunAllTests() { | |||||
// In fact, this is the only mode that `karma` supports. | |||||
return true; | |||||
} | |||||
public function run() { | |||||
$working_copy = $this->getWorkingCopy(); | |||||
$project_root = $working_copy->getProjectRoot(); | |||||
$config_manager = $this->getConfigurationManager(); | |||||
$config = $config_manager->getConfigFromAnySource('unit.karma.config'); | |||||
$junit = $config_manager->getConfigFromAnySource('unit.karma.junit'); | |||||
$coverage = $config_manager->getConfigFromAnySource('unit.karma.coverage'); | |||||
if (!$config) { | |||||
throw new ArcanistUsageException( | |||||
'No configuration is configured. Set `unit.karma.config` '. | |||||
'in your `.arcconfig` file.'); | |||||
} | |||||
if (!$junit) { | |||||
throw new ArcanistUsageException( | |||||
'No JUnit output file is configured. Set `unit.karma.junit` '. | |||||
'in your `.arcconfig` file.'); | |||||
} | |||||
if ($this->getEnableCoverage() && !$coverage) { | |||||
throw new ArcanistUsageException( | |||||
'No coverage output file is configured. Set `unit.karma.coverage` '. | |||||
'in your `.arcconfig` file.'); | |||||
} | |||||
$future = $this->buildTestFuture($config); | |||||
$future->resolvex(); | |||||
return $this->parseTestResults($junit, $coverage); | |||||
} | |||||
private function buildTestFuture($config) { | |||||
$flags = array( | |||||
'--log-level=info', | |||||
'--no-colors', | |||||
); | |||||
$reporters = array(); | |||||
$reporters[] = 'junit'; | |||||
if ($this->getEnableCoverage()) { | |||||
$reporters[] = 'coverage'; | |||||
} | |||||
$flags[] = '--reporters='.implode(',', $reporters); | |||||
$future = id(new ExecFuture('karma start %Ls %s', $flags, $config)) | |||||
->setCWD($this->getWorkingCopy()->getProjectRoot()); | |||||
chengyin: Another note here. Unless I missed something, to run karma in non watch mode, `--single-run`… | |||||
return $future; | |||||
} | |||||
private function parseTestResults($junit) { | |||||
$parser = new ArcanistXUnitTestResultParser(); | |||||
return $parser->parseTestResults(Filesystem::readFile($junit)); | |||||
chengyinUnsubmitted Not Done Inline ActionsJust in case you want to ever revisit this again, this will read file that is relative to the current working directory instead of the project root directory, and arc diff/unit would only be run-able in the project root directory. We use $working_copy = $this->getWorkingCopy(); $project_root = $working_copy->getProjectRoot(); $parser = new ArcanistXUnitTestResultParser(); return $parser->parseTestResults(Filesystem::readFile($project_root . '/' . $junit)); chengyin: Just in case you want to ever revisit this again, this will read file that is relative to the… | |||||
} | |||||
} |
Another note here. Unless I missed something, to run karma in non watch mode, --single-run option will be needed. However, in the single run mode karma will exit with code 1 when the test fails.
This will cause arc to not parse the test result, and since the reporters on karma's option here is only coverage and junit, there will be no test result outputted by karma either, leaving no information about why arc unit / arc diff failed.