-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Custom reporters #3349
Custom reporters #3349
Conversation
9b77ab1
to
4d93360
Compare
Codecov Report
@@ Coverage Diff @@
## master #3349 +/- ##
==========================================
- Coverage 64.02% 63.81% -0.22%
==========================================
Files 177 179 +2
Lines 6580 6649 +69
Branches 5 5
==========================================
+ Hits 4213 4243 +30
- Misses 2365 2404 +39
Partials 2 2
Continue to review full report at Codecov.
|
*/ | ||
function createReporterError( | ||
reporterIndex: number, | ||
reporterValue: any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any? Shouldn't it demand at least "Object"?
function createArrayReporterError( | ||
reporterIndex: number, | ||
valueIndex: number, | ||
value: any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mixed?
@@ -32,6 +32,7 @@ const DEPRECATED_CONFIG = require('./deprecated'); | |||
const JSON_EXTENSION = '.json'; | |||
const PRESET_NAME = 'jest-preset' + JSON_EXTENSION; | |||
const ERROR = `${BULLET}Validation Error`; | |||
const {validateReporters} = require('./reporterValidationErrors'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this require should be in the block above.
|
||
constructor(options: Options) { | ||
constructor(options: GlobalConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deliberately changed this in the past to not include all config options. But I guess it is fine – can we change this variable name to _globalConfig
and globalConfig
?
"path": false, | ||
}, | ||
"options": Object { | ||
"christop": "pojer", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo? :P
exports[`Custom Reporters Integration invalid format for adding reporters 1`] = ` | ||
"● Reporter Validation Error: | ||
|
||
Unexpected value for Path at index 0 of reporter at index 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message is so not nice. index 0 of reporter at index 0
. Can we maybe print actual reporters value along with it?
const {stdout, status, stderr} = runJest('custom_reporters', [ | ||
'add-test.js', | ||
]); | ||
const parsedJSON = JSON.parse(stdout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about runJest.json
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but we're specifically testing a custom reporter :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, sure then :)
|
||
'use strict'; | ||
|
||
module.exports = function add(x, y) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you heard of arrow functions?
* Reporter to test for the flexibility of the interface we implemented. | ||
* The reporters shouldn't be required to implement all the methods | ||
* | ||
* This only implements one mehtod onRunComplete which should be called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"method"?
const onRunStart = this._statsCollected.onRunStart; | ||
|
||
onRunStart.called = true; | ||
onRunStart.config = typeof config; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this typeof call useful?
import type BaseReporter from './reporters/BaseReporter'; | ||
import type {ReporterOnStartOptions} from 'types/Reporters'; | ||
|
||
export type RunOptions = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be an exact type?
packages/jest-cli/src/TestRunner.js
Outdated
@@ -67,7 +69,7 @@ class TestRunner { | |||
this._setupReporters(); | |||
} | |||
|
|||
addReporter(reporter: BaseReporter) { | |||
addReporter(reporter: Object) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be a type for Reporter instances in types/TestRunner.js
or something?
packages/jest-cli/src/TestRunner.js
Outdated
@@ -273,14 +275,22 @@ class TestRunner { | |||
return Promise.race([runAllTests, onInterrupt]).then(cleanup, cleanup); | |||
} | |||
|
|||
_shouldAddDefaultReporters(reporters?: Array<ReporterConfig>): boolean { | |||
return !reporters || reporters.indexOf(DEFAULT_REPORTER_LABEL) !== -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when reporters.length
is 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd expect it to give no output, i think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should throw in that case, tbh.
packages/jest-cli/src/TestRunner.js
Outdated
_setupReporters() { | ||
const config = this._config; | ||
const reporters = config.reporters; | ||
const isDefault: boolean = this._shouldAddDefaultReporters(reporters); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this really need a type annotation inline? Flow should be able to figure it out.
Bunch of comments but feel free to merge it after one more iteration. |
Please don't forget to document the reporters option in the docs and adding "Available in Jest 20.0.0" like we do for other things (Like the expect.resolves API). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll request changes because you are doing some bigger rewrites and I'll take a look at it tomorrow :)
4d93360
to
d0c55f8
Compare
this error is not letting me lint 100% safe Reporter config 3 (#2) * add custom reporters option in TestRunner * add reporters option in jest-cli config * add flowtype for reporters option * add key for reporters in validConfig * add noDefaultReporters option noDefaultReporters option let's user turn off all the reporters set by default * Lint * add unit tests for _addCustomReporters * separate default reporters in method in TestRunner * add tests for errors which are thrown * add tests for .noDefaultReporters * modify Error thrown for _addCustomReporters * remove superfluous comment from TestRunner.js * remove reporter tests from TestRunner-test.js * add new custom reporters format in TestRunner.js * update the format for adding customReporter * add descriptive validations for reporters * add reporters attibute in normalize.js * add prettier to types * Seperate out ReporterDispatcher in a file * add elaborate messages for errors * add Facebook Copyright header to ReporterDispatcher.js * typecheck and lint properly * correcting a condition in ReporterDispatcher * rename method to `_shouldAddDefaultReporters` * add integration tests for custom_reporters * add more complete integration tests for reporters * remove AggregatedResults.js * remove any methods to be validated * correct _addDefaultReporters call * remove "reporters" validations from TestRunner.js * add pretty validations for custom reporters * remove comment * add reporter validation in normalize.js * keep comments precise remove unwanted * check if reporters exist before validation * pretty custom reporters * prettier integration_tests * prettier * yarn prettier * prettier * Remove unnecessary comments from TestRunner.js * make ReporterConfig type in types/Config simpler * remove comments * correct types and change method signatures * remove bug from reporterValidationErrors.js * make custom_reporters tests more concise * fix lint error in website this error is not letting me lint 100% safe * finalize types for reporters * yarn prettier * remove .vscode folder * all integration_tests are prettier now * remove validateReporters call * remove usage of \t in reporter validation errors * change spread operator with usage of .apply * modify custom_reporters integration_tests to suit node 4 * prettier validations * prettier ❤️ * pretty lint * update lock file
d0c55f8
to
deb2790
Compare
* This only implements one method onRunComplete which should be called | ||
*/ | ||
class IncompleteReporter { | ||
constructor(options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems unused.
Got: | ||
number | ||
Reporters config: | ||
[ 3243242 ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whitespace is really ugly. Why can we not just print this using prettyFormat like we always do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think i missed join('\n')
somewhere :)
packages/jest-cli/src/TestRunner.js
Outdated
this.addReporter( | ||
config.verbose | ||
? new VerboseReporter(config) | ||
: new DefaultReporter(this._globalConfig), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is passing config once and this._globalConfig on the other, even though they are the same.
packages/jest-cli/src/TestRunner.js
Outdated
} | ||
|
||
_addCustomReporters(reporters: Array<ReporterConfig>) { | ||
const customReporter = reporters.filter(reporter => reporter !== 'default'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be customReporters
, plural.
deb2790
to
57385b5
Compare
packages/jest-cli/src/TestRunner.js
Outdated
chalk.red( | ||
'An error occured while adding the reporter at path ' + path, | ||
), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does this write to console.error and then throw? Shouldn't it be:
throw new Error(
'An error occured while adding the reporter at path "' + path + '".' +
error.message
);
packages/jest-cli/src/TestRunner.js
Outdated
* Get properties of a reporter in an object | ||
* to make dealing with them less painful. | ||
*/ | ||
_getReporterProps(reporter: ReporterConfig): Object { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can remote Object
here because it is a private field. If not, then please type it properly :)
packages/jest-cli/src/TestRunner.js
Outdated
* to make dealing with them less painful. | ||
*/ | ||
_getReporterProps(reporter: ReporterConfig): Object { | ||
let props = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object.create(null)
.
import type {PathPattern} from '../SearchSource'; | ||
import type {ReporterOnStartOptions} from 'types/Reporters'; | ||
|
||
type SummaryReporterOptions = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exact type please.
@@ -4,8 +4,6 @@ | |||
* This source code is licensed under the BSD-style license found in the | |||
* LICENSE file in the root directory of this source tree. An additional grant | |||
* of patent rights can be found in the PATENTS file in the same directory. | |||
* | |||
* @emails oncall+jsinfra |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should remove this from all tests in this repo, actually.
@@ -255,6 +256,10 @@ function normalize(options: InitialOptions, argv: Object = {}) { | |||
exampleConfig: VALID_CONFIG, | |||
}); | |||
|
|||
if (options.reporters && Array.isArray(options.reporters)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is not an array, shouldn't we also validate it?
I left a few comments inline. The one missing piece is that the |
57385b5
to
8dec8ba
Compare
Alright, good to go. |
* Custom Reporters this error is not letting me lint 100% safe Reporter config 3 (jestjs#2) * add custom reporters option in TestRunner * add reporters option in jest-cli config * add flowtype for reporters option * add key for reporters in validConfig * add noDefaultReporters option noDefaultReporters option let's user turn off all the reporters set by default * Lint * add unit tests for _addCustomReporters * separate default reporters in method in TestRunner * add tests for errors which are thrown * add tests for .noDefaultReporters * modify Error thrown for _addCustomReporters * remove superfluous comment from TestRunner.js * remove reporter tests from TestRunner-test.js * add new custom reporters format in TestRunner.js * update the format for adding customReporter * add descriptive validations for reporters * add reporters attibute in normalize.js * add prettier to types * Seperate out ReporterDispatcher in a file * add elaborate messages for errors * add Facebook Copyright header to ReporterDispatcher.js * typecheck and lint properly * correcting a condition in ReporterDispatcher * rename method to `_shouldAddDefaultReporters` * add integration tests for custom_reporters * add more complete integration tests for reporters * remove AggregatedResults.js * remove any methods to be validated * correct _addDefaultReporters call * remove "reporters" validations from TestRunner.js * add pretty validations for custom reporters * remove comment * add reporter validation in normalize.js * keep comments precise remove unwanted * check if reporters exist before validation * pretty custom reporters * prettier integration_tests * prettier * yarn prettier * prettier * Remove unnecessary comments from TestRunner.js * make ReporterConfig type in types/Config simpler * remove comments * correct types and change method signatures * remove bug from reporterValidationErrors.js * make custom_reporters tests more concise * fix lint error in website this error is not letting me lint 100% safe * finalize types for reporters * yarn prettier * remove .vscode folder * all integration_tests are prettier now * remove validateReporters call * remove usage of \t in reporter validation errors * change spread operator with usage of .apply * modify custom_reporters integration_tests to suit node 4 * prettier validations * prettier ❤️ * pretty lint * update lock file * Custom Reporters (merge/fix) * Use jest-resolve to resolve reporters * Minor cleanups
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
i rebased/resolved/squashed #3064 which grew uncontrollably big.
also fixed a few issues and resolved conflicts with multi runner feature
cc @abdulhannanali