Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmwu committed Jul 8, 2019
1 parent a501718 commit 3d22a07
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- `[docs]` Add information about using `jest.doMock` with ES6 imports ([#8573](https://github.com/facebook/jest/pull/8573))
- `[docs]` Fix variable name in custom-matcher-api code example ([#8582](https://github.com/facebook/jest/pull/8582))
- `[docs]` Fix example used in custom environment docs ([#8617](https://github.com/facebook/jest/pull/8617))
- `[docs]` Fix example reference implementation to use Jest with Phabricator ([#8662](https://github.com/facebook/jest/pull/8662))

### Performance

Expand Down
24 changes: 21 additions & 3 deletions packages/jest-phabricator/README.md
Original file line number Diff line number Diff line change
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": "(\\.jsx?$)"
}
```

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 All @@ -141,7 +157,7 @@ class JestUnitTestEngine extends ArcanistBaseUnitTestEngine {
$jest_paths = array();
foreach ($paths as $path) {
$ext = idx(pathinfo($path), 'extension');
if ($ext === 'js' || $ext === 'json') {
if ($ext === 'js' || $ext === 'json' || $ext === 'jsx') {
// Filter deleted modules because Jest can't do anything with them.
if (file_exists("$root/$path")) {
$jest_paths[] = "$root/$path";
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 3d22a07

Please sign in to comment.