-
-
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
Pass “Test”s to reporters; update Test to contain contexts. #3289
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,7 +121,7 @@ class TestRunner { | |
return; | ||
} | ||
addResult(aggregatedResults, testResult); | ||
this._dispatcher.onTestResult(config, testResult, aggregatedResults); | ||
this._dispatcher.onTestResult(test, testResult, aggregatedResults); | ||
this._bailIfNeeded(aggregatedResults, watcher); | ||
}; | ||
|
||
|
@@ -132,11 +132,11 @@ class TestRunner { | |
const testResult = buildFailureTestResult(test.path, error); | ||
testResult.failureMessage = formatExecError( | ||
testResult, | ||
test.config, | ||
test.context.config, | ||
test.path, | ||
); | ||
addResult(aggregatedResults, testResult); | ||
this._dispatcher.onTestResult(config, testResult, aggregatedResults); | ||
this._dispatcher.onTestResult(test, testResult, aggregatedResults); | ||
}; | ||
|
||
const updateSnapshotState = () => { | ||
|
@@ -199,8 +199,12 @@ class TestRunner { | |
throw new CancelRun(); | ||
} | ||
|
||
this._dispatcher.onTestStart(test.config, test.path); | ||
return runTest(test.path, test.config, this._context.resolver); | ||
this._dispatcher.onTestStart(test); | ||
return runTest( | ||
test.path, | ||
test.context.config, | ||
test.context.resolver, | ||
); | ||
}) | ||
.then(result => onResult(test, result)) | ||
.catch(err => onFailure(test, err))), | ||
|
@@ -228,17 +232,17 @@ class TestRunner { | |
|
||
// Send test suites to workers continuously instead of all at once to track | ||
// the start time of individual tests. | ||
const runTestInWorker = ({config, path}) => | ||
const runTestInWorker = test => | ||
mutex(() => { | ||
if (watcher.isInterrupted()) { | ||
return Promise.reject(); | ||
} | ||
this._dispatcher.onTestStart(config, path); | ||
this._dispatcher.onTestStart(test); | ||
return worker({ | ||
config, | ||
path, | ||
config: test.context.config, | ||
path: test.path, | ||
rawModuleMap: watcher.isWatchMode() | ||
? this._context.moduleMap.getRawModuleMap() | ||
? test.context.moduleMap.getRawModuleMap() | ||
: null, | ||
}); | ||
}); | ||
|
@@ -439,14 +443,13 @@ class ReporterDispatcher { | |
); | ||
} | ||
|
||
onTestResult(config, testResult, results) { | ||
onTestResult(test, testResult, results) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Types onTestResult (test: Test, testResult: TestResult, results: AggregatedResult) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, Flow isn't asking for it. Is this about readability? If Flow isn't asking it means the type isn't ambiguous to flow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, sorry about that, I'm checking it through GH, so I don't know if Flow infers something :D |
||
this._reporters.forEach(reporter => | ||
reporter.onTestResult(config, testResult, results, this._runnerContext)); | ||
reporter.onTestResult(test, testResult, results, this._runnerContext)); | ||
} | ||
|
||
onTestStart(config, path) { | ||
this._reporters.forEach(reporter => | ||
reporter.onTestStart(config, path, this._runnerContext)); | ||
onTestStart(test) { | ||
this._reporters.forEach(reporter => reporter.onTestStart(test)); | ||
} | ||
|
||
onRunStart(config, results, options) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
'use strict'; | ||
|
||
import type {AggregatedResult} from 'types/TestResult'; | ||
import type {Config} from 'types/Config'; | ||
import type {Context} from 'types/Context'; | ||
import type {Tests} from 'types/TestRunner'; | ||
|
||
const fs = require('fs'); | ||
|
@@ -19,20 +19,22 @@ const getCacheFilePath = require('jest-haste-map').getCacheFilePath; | |
const FAIL = 0; | ||
const SUCCESS = 1; | ||
|
||
type Cache = { | ||
[key: string]: [0 | 1, number], | ||
}; | ||
|
||
class TestSequencer { | ||
_config: Config; | ||
_cache: Object; | ||
_context: Context; | ||
_cache: Cache; | ||
|
||
constructor(config: Config) { | ||
this._config = config; | ||
constructor(context: Context) { | ||
this._context = context; | ||
this._cache = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be nice to type perf cache too |
||
} | ||
|
||
_getTestPerformanceCachePath() { | ||
return getCacheFilePath( | ||
this._config.cacheDirectory, | ||
'perf-cache-' + this._config.name, | ||
); | ||
const {config} = this._context; | ||
return getCacheFilePath(config.cacheDirectory, 'perf-cache-' + config.name); | ||
} | ||
|
||
// When running more tests than we have workers available, sort the tests | ||
|
@@ -44,7 +46,7 @@ class TestSequencer { | |
// subsequent runs we use that to run the slowest tests first, yielding the | ||
// fastest results. | ||
sort(testPaths: Array<string>): Tests { | ||
const config = this._config; | ||
const context = this._context; | ||
const stats = {}; | ||
const fileSize = filePath => | ||
stats[filePath] || (stats[filePath] = fs.statSync(filePath).size); | ||
|
@@ -54,7 +56,7 @@ class TestSequencer { | |
|
||
this._cache = {}; | ||
try { | ||
if (this._config.cache) { | ||
if (context.config.cache) { | ||
this._cache = JSON.parse( | ||
fs.readFileSync(this._getTestPerformanceCachePath(), 'utf8'), | ||
); | ||
|
@@ -82,7 +84,7 @@ class TestSequencer { | |
}); | ||
|
||
return testPaths.map(path => ({ | ||
config, | ||
context, | ||
duration: this._cache[path] && this._cache[path][1], | ||
path, | ||
})); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,11 +84,13 @@ const runJest = async ( | |
|
||
if ( | ||
data.paths.length === 1 && | ||
config.silent !== true && | ||
config.verbose !== false | ||
hasteContext.config.silent !== true && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be renamed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is happening somewhere in the larger PR, yes. It creates more merge conflicts if I do it in this one. |
||
hasteContext.config.verbose !== false | ||
) { | ||
// $FlowFixMe | ||
config = Object.assign({}, config, {verbose: true}); | ||
config = (hasteContext.config = Object.assign({}, hasteContext.config, { | ||
verbose: true, | ||
})); | ||
} | ||
|
||
return data; | ||
|
@@ -131,7 +133,7 @@ const runJest = async ( | |
|
||
const data = await source.getTestPaths(patternInfo); | ||
processTests(data); | ||
const sequencer = new TestSequencer(config); | ||
const sequencer = new TestSequencer(hasteContext); | ||
const tests = sequencer.sort(data.paths); | ||
const results = await runTests(tests); | ||
sequencer.cacheResults(tests, results); | ||
|
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.
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.
Flow isn't asking me to annotate this which means it infers the proper type. Why should I change it? I don't want to add superfluous types.