From 3d22a07ab5a986ca175f8a3415a8b847ae0c81b0 Mon Sep 17 00:00:00 2001 From: Michael Wu Date: Mon, 8 Jul 2019 16:15:18 -0700 Subject: [PATCH] docs --- CHANGELOG.md | 1 + packages/jest-phabricator/README.md | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c57e8fc17c7..9f1eeec07a13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/jest-phabricator/README.md b/packages/jest-phabricator/README.md index 97a3fdf505be..dd23a9d414e0 100644 --- a/packages/jest-phabricator/README.md +++ b/packages/jest-phabricator/README.md @@ -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 @@ -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(); } @@ -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); } @@ -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"; @@ -177,6 +193,7 @@ class JestUnitTestEngine extends ArcanistBaseUnitTestEngine { } $console->writeOut("Finished tests.\n"); + // $console->writeErr(implode(', ', $result_arrays)); return call_user_func_array('array_merge', $result_arrays); } @@ -184,8 +201,8 @@ class JestUnitTestEngine extends ArcanistBaseUnitTestEngine { $output_JSON = $this->getOutputJSON(); $options = array( '--colors', - '--findRelatedTests', '--json', + '--passWithNoTests true', '--outputFile=' . $output_JSON, '--testResultsProcessor=' . self::PROCESSOR ); @@ -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); }