Skip to content

Commit 0fbd7a8

Browse files
lPadierFacebook Github Bot 9
authored andcommitted
Add config.testResultsProcessor
Summary:The aim of this config is to allow hooks into the runResults, for instance to generate jUnit test reports. The json that jest --json outputs only shows part of the runResults object Closes jestjs#850 Differential Revision: D3121902 fb-gh-sync-id: fecd0aa344f9bf59369e28be7b4e58f2eeeb9d73 fbshipit-source-id: fecd0aa344f9bf59369e28be7b4e58f2eeeb9d73
1 parent f5e7d48 commit 0fbd7a8

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

docs/API.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Jest uses Jasmine 2 by default. An introduction to Jasmine 2 can be found
6868
- [`config.testPathDirs` [array<string>]](#config-testpathdirs-array-string)
6969
- [`config.testPathIgnorePatterns` [array<string>]](#config-testpathignorepatterns-array-string)
7070
- [`config.testPathPattern` [string]](#config-testpathpattern-string)
71+
- [`config.testResultsProcessor` [string]](#config-testresultsprocessor-string)
7172
- [`config.testRunner` [string]](#config-testrunner-string)
7273
- [`config.unmockedModulePathPatterns` [array<string>]](#config-unmockedmodulepathpatterns-array-string)
7374
- [`config.verbose` [boolean]](#config-verbose-boolean)
@@ -508,6 +509,48 @@ A regexp pattern string that is matched against all test paths before executing
508509

509510
This is useful if you need to override the default. If you are testing one file at a time the default will be set to `/.*/`, however if you pass a blob rather than a single file the default will then be the absolute path of each test file. The override may be needed on windows machines where, for example, the test full path would be `C:/myproject/__tests__/mystest.jsx.jest` and the default pattern would be set as `/C:\myproject\__tests__\mystest.jsx.jest/`.
510511

512+
### `config.testResultsProcessor` [string]
513+
(default: `undefined`)
514+
515+
This option allows the use of a custom results processor. This processor must be a node module that exports a function expecting an object with the following structure as the first argument:
516+
517+
```
518+
{
519+
"success": bool,
520+
"startTime": epoch,
521+
"numTotalTestSuites": number,
522+
"numPassedTestSuites": number,
523+
"numFailedTestSuites": number,
524+
"numRuntimeErrorTestSuites": number,
525+
"numTotalTests": number,
526+
"numPassedTests": number,
527+
"numFailedTests": number,
528+
"numPendingTests": number,
529+
"testResults": [{
530+
"numFailingTests": number,
531+
"numPassingTests": number,
532+
"numPendingTests": number,
533+
"testResults": [{
534+
"title": string (message in it block),
535+
"status": "failed" | "pending" | "passed",
536+
"ancestorTitles": [string (message in describe blocks)],
537+
"failureMessages": [string],
538+
"numPassingAsserts": number
539+
},
540+
...
541+
],
542+
"perfStats": {
543+
"start": epoch,
544+
"end": epoch
545+
},
546+
"testFilePath": absolute path to test file,
547+
"coverage": {}
548+
},
549+
...
550+
]
551+
}
552+
```
553+
511554
### `config.testRunner` [string]
512555
(default: `jasmine2`)
513556

src/config/normalize.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ function normalize(config, argv) {
150150
case 'testRunner':
151151
case 'scriptPreprocessor':
152152
case 'setupTestFrameworkScriptFile':
153+
case 'testResultsProcessor':
153154
value = path.resolve(
154155
config.rootDir,
155156
_replaceRootDirTags(config.rootDir, config[key])

src/jest.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ function runJest(config, argv, pipe, onComplete) {
137137
})
138138
.then(testPaths => testRunner.runTests(testPaths))
139139
.then(runResults => {
140+
if (config.testResultsProcessor) {
141+
const processor = require(config.testResultsProcessor);
142+
processor(runResults);
143+
}
140144
if (argv.json) {
141145
process.stdout.write(
142146
JSON.stringify(formatTestResults(runResults))

0 commit comments

Comments
 (0)