Skip to content

Commit

Permalink
Update jest-phabricator documentation (#8662)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmwu committed May 2, 2020
1 parent 1cc205c commit b6052e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -19,6 +19,7 @@
- `[jest-runtime]` [**BREAKING**] Remove long-deprecated `require.requireActual` and `require.requireMock` methods ([#9854](https://github.com/facebook/jest/pull/9854))
- `[expect, jest-mock, pretty-format]` [**BREAKING**] Remove `build-es5` from package ([#9945](https://github.com/facebook/jest/pull/9945))
- `[jest-haste-map]` [**BREAKING**] removed `providesModuleNodeModules` ([#8535](https://github.com/facebook/jest/pull/8535))
- `[docs]` Fix example reference implementation to use Jest with Phabricator ([#8662](https://github.com/facebook/jest/pull/8662))

### Performance

Expand Down
22 changes: 20 additions & 2 deletions packages/jest-phabricator/README.md
Expand Up @@ -16,6 +16,15 @@ You need to add the jest unit engine to your .arcconfig:
...
```

Or use the `ArcanistConfigurationDrivenUnitTestEngine` and add an entry to your .arcunit

```json
"jest": {
"type": "jest",
"include": "(\\.js$)"
}
```

In `JestUnitTestEngine` there are a couple of constants you probably need to modify:

- `PROCESSOR` points to the path or the processor
Expand All @@ -26,12 +35,16 @@ If you need to pass to Jest a custom configuration you can either use `JEST_PATH
## Reference implementation

```php
class JestUnitTestEngine extends ArcanistBaseUnitTestEngine {
final class JestUnitTestEngine extends ArcanistUnitTestEngine {
const PROCESSOR = 'jest/packages/jest-phabricator/build/index.js';
const JEST_PATH = 'jest/packages/jest/bin/jest.js';
const TOO_MANY_FILES_TO_COVER = 100;
const GIGANTIC_DIFF_THRESHOLD = 200;

public function getEngineConfigurationName() {
return 'jest';
}

private function getRoot() {
return $this->getWorkingCopy()->getProjectRoot();
}
Expand Down Expand Up @@ -129,6 +142,9 @@ class JestUnitTestEngine extends ArcanistBaseUnitTestEngine {
$results[] = $this->getFutureResults($future);
}

if (empty($results)) {
return array();
}
return call_user_func_array('array_merge', $results);
}

Expand Down Expand Up @@ -177,15 +193,16 @@ class JestUnitTestEngine extends ArcanistBaseUnitTestEngine {
}

$console->writeOut("Finished tests.\n");
// $console->writeErr(implode(', ', $result_arrays));
return call_user_func_array('array_merge', $result_arrays);
}

private function getJestOptions($paths) {
$output_JSON = $this->getOutputJSON();
$options = array(
'--colors',
'--findRelatedTests',
'--json',
'--passWithNoTests true',
'--outputFile=' . $output_JSON,
'--testResultsProcessor=' . self::PROCESSOR
);
Expand All @@ -194,6 +211,7 @@ class JestUnitTestEngine extends ArcanistBaseUnitTestEngine {
// A better solution would involve knowing what's the machine buffer size limit
// for exec and check if the command can stay within it.
if (count($paths) < self::TOO_MANY_FILES_TO_COVER) {
$options[] = '--findRelatedTests ' . join(' ', $paths);
$options[] = '--coverage';
$options[] = '--collectCoverageOnlyFrom '. join(' ', $paths);
}
Expand Down

0 comments on commit b6052e0

Please sign in to comment.