Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update jest-phabricator documentation #8662

Merged
merged 3 commits into from
May 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
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": "(\\.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