-
-
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
Show coverage of sources related to tests in changed files #9769
Show coverage of sources related to tests in changed files #9769
Conversation
11f20c8
to
e236946
Compare
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 looks great! Thanks for the thorough tests 👍
Codecov Report
@@ Coverage Diff @@
## master #9769 +/- ##
==========================================
- Coverage 64.39% 64.37% -0.02%
==========================================
Files 290 290
Lines 12361 12391 +30
Branches 3056 3059 +3
==========================================
+ Hits 7960 7977 +17
- Misses 3761 3770 +9
- Partials 640 644 +4
Continue to review full report at Codecov.
|
This is good to go from my side, I'd just like further review on it. With Easter holidays and the coronavirus things have slowed down a bit, I'm sure they'll review this soon enough 🙂 |
Oh I see. Hope you all good during this epidemic period 🙏 Take care 😷 |
754f365
to
e724874
Compare
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.
Nice improvement 👍 Left a few notes on how I think we could make it make it a bit more performant
packages/jest-core/src/runJest.ts
Outdated
testSchedulerContext.changedFiles = changedFilesInfo.changedFiles; | ||
const sourcesRelatedToTestsInChangedFilesArray = contexts | ||
.map(context => { | ||
const searchSource = new SearchSource(context); |
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.
Creating the SearchSource for a given context is already done earlier, when finding related tests. We could optimize this by storing the searchSources
in and array, when mapping context
s for testRunData
and reuse it. I think it's worth not doubling the efforts we already made.
return []; | ||
} | ||
const {changedFiles} = changedFilesInfo; | ||
const dependencyResolver = new DependencyResolver( |
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.
The same DependencyResolver is also created for findRelatedTests
. Can we cache it then?
private _testPathCases: TestPathCases = []; | ||
|
||
constructor(context: Context) { | ||
const {config} = context; | ||
this._context = context; | ||
this._dependencyResolver = null; |
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 may not immediately use DependencyResolver
in SearchSource
, so at first this._dependencyResolver
will be null
. When we need DependencyResolver
, just call _getDependencyResolver
to create/get it.
const isTestFile = this.isTestFilePath(filePath); | ||
if (isTestFile) { |
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.
const isTestFile = this.isTestFilePath(filePath); | |
if (isTestFile) { | |
if (this.isTestFilePath(filePath) { |
beforeEach(done => { | ||
const {options: config} = normalize( | ||
{ | ||
haste: { | ||
hasteImplModulePath: path.resolve( | ||
__dirname, | ||
'../../../jest-haste-map/src/__tests__/haste_impl.js', | ||
), | ||
providesModuleNodeModules: [], | ||
}, | ||
name: 'SearchSource-findRelatedSourcesFromTestsInChangedFiles-tests', | ||
rootDir, | ||
}, | ||
{} as Config.Argv, | ||
); | ||
Runtime.createContext(config, {maxWorkers, watchman: false}).then( | ||
context => { | ||
searchSource = new SearchSource(context); | ||
done(); | ||
}, | ||
); | ||
}); |
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.
beforeEach(done => { | |
const {options: config} = normalize( | |
{ | |
haste: { | |
hasteImplModulePath: path.resolve( | |
__dirname, | |
'../../../jest-haste-map/src/__tests__/haste_impl.js', | |
), | |
providesModuleNodeModules: [], | |
}, | |
name: 'SearchSource-findRelatedSourcesFromTestsInChangedFiles-tests', | |
rootDir, | |
}, | |
{} as Config.Argv, | |
); | |
Runtime.createContext(config, {maxWorkers, watchman: false}).then( | |
context => { | |
searchSource = new SearchSource(context); | |
done(); | |
}, | |
); | |
}); | |
beforeEach(async () => { | |
const {options: config} = normalize( | |
{ | |
haste: { | |
hasteImplModulePath: path.resolve( | |
__dirname, | |
'../../../jest-haste-map/src/__tests__/haste_impl.js', | |
), | |
providesModuleNodeModules: [], | |
}, | |
name: 'SearchSource-findRelatedSourcesFromTestsInChangedFiles-tests', | |
rootDir, | |
}, | |
{} as Config.Argv, | |
); | |
const context = await Runtime.createContext(config, {maxWorkers, watchman: false}) | |
searchSource = new SearchSource(context); | |
}); |
diff looks big, but async await instead of .then
and done
if (options.changedFiles) { | ||
if (!options.changedFiles.has(filename)) { |
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 (options.changedFiles) { | |
if (!options.changedFiles.has(filename)) { | |
if (options.changedFiles && !options.changedFiles.has(filename)) { |
9df97b2
to
913617b
Compare
* upstream/master: Prints the Symbol name into the error message with a custom asymmetric matcher (jestjs#9888) Show coverage of sources related to tests in changed files (jestjs#9769) fix: don't /// <reference types="jest" /> (jestjs#9875)
…pshots * upstream/master: (39 commits) Prints the Symbol name into the error message with a custom asymmetric matcher (jestjs#9888) Show coverage of sources related to tests in changed files (jestjs#9769) fix: don't /// <reference types="jest" /> (jestjs#9875) noCodeFrame respects noStackTrace (jestjs#9866) chore: update example to react-native@0.62 (jestjs#9746) Improve source map handling when instrumenting transformed code (jestjs#9811) Update .vscode/launch.json settings (jestjs#9868) chore: verify all packages have the same engine requirement (jestjs#9871) fix: pass custom cached realpath function to `resolve` (jestjs#9873) chore: mock stealthy-require in tests (jestjs#9855) chore: update resolve (jestjs#9872) chore: run CircleCI on node 14 (jestjs#9870) Add an option to vscode settings to always use workspace TS (jestjs#9869) fix(esm): handle parallel imports (jestjs#9858) chore: run CI on Node 14 (jestjs#9861) feat: add `@jest/globals` package for importing globals explici… (jestjs#9849) chore: bump resolve package (jestjs#9859) chore(runtime): simplify `createJestObjectFor` (jestjs#9857) chore: fix symlink creation failures on windows in tests (jestjs#9852) chore: skip mercurial tests when no hg installed (jestjs#9840) ...
…pshots * upstream/master: (39 commits) Prints the Symbol name into the error message with a custom asymmetric matcher (jestjs#9888) Show coverage of sources related to tests in changed files (jestjs#9769) fix: don't /// <reference types="jest" /> (jestjs#9875) noCodeFrame respects noStackTrace (jestjs#9866) chore: update example to react-native@0.62 (jestjs#9746) Improve source map handling when instrumenting transformed code (jestjs#9811) Update .vscode/launch.json settings (jestjs#9868) chore: verify all packages have the same engine requirement (jestjs#9871) fix: pass custom cached realpath function to `resolve` (jestjs#9873) chore: mock stealthy-require in tests (jestjs#9855) chore: update resolve (jestjs#9872) chore: run CircleCI on node 14 (jestjs#9870) Add an option to vscode settings to always use workspace TS (jestjs#9869) fix(esm): handle parallel imports (jestjs#9858) chore: run CI on Node 14 (jestjs#9861) feat: add `@jest/globals` package for importing globals explici… (jestjs#9849) chore: bump resolve package (jestjs#9859) chore(runtime): simplify `createJestObjectFor` (jestjs#9857) chore: fix symlink creation failures on windows in tests (jestjs#9852) chore: skip mercurial tests when no hg installed (jestjs#9840) ...
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. |
Summary
This PR fixes #8545 . It will show coverage of sources related to tests when jest is in watch mode (
--watch
) or--onlyChange
.As for implementation, this PR added
findRelatedSourceFromTestsInChangedFiles
inSearchSource
, and apply it when there arechangedFiles
, then pass the results into options ofshouldInstrument
. WhenchangedFiles
exist and the file is not in changedFiles norsourcesRelatedToTestsInChangedFiles
, we will not instrument it.Test plan
Add an e2e test case for the use case and some unit test case for
SearchSource
.