-
-
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
[Proposal] Watch plugins API #5399
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
396cd18
Start adding tapable
rogeliog c04edc7
Use test_path_pattern as a plugin
rogeliog 1f74aa1
Use test_name_pattern as a plugin
rogeliog 03b53b1
Use quit as a plugin
rogeliog 1aeafb8
Fix test interruption
rogeliog b40f604
Use update snapshot as a plugin
rogeliog 6e97a6e
Use update snapshot interactive as a plugin
rogeliog ef14ade
Change API to use a class instance
rogeliog 8b999ed
Merge branch 'master' into simpler-plugins
rogeliog 2604965
A bit of clean up and make tests pass
rogeliog ffc85f1
Change plugin implementation to not use tapable
rogeliog 053d9e4
Better sorting implementation
rogeliog 2036be9
Add back third party plugin functionality
rogeliog 40c4265
Fix flow
rogeliog 44c82ba
Merge branch 'master' into simpler-plugins
rogeliog 7767b71
Fix ESLint
rogeliog 2b084f8
Reset file to state of master
rogeliog 58f1717
Update failing snapshot
rogeliog 13f08e5
Merge branch 'master' into simpler-plugins
rogeliog d4ecb92
Remove hasSnapshotFailure and hasSnapshotFailureInteractive
rogeliog 8f6513e
Async await for showPrompt and clear active plugin on file change
rogeliog 401e44b
Fix snapshot failure
rogeliog 9ac7d94
Reenable tests
rogeliog 25e0c4b
Implement shouldRunTestSuite
rogeliog 4a68617
Add changelog
rogeliog 3dc8c06
Clean up watch.js a bit
rogeliog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import type {AggregatedResult} from 'types/TestResult'; | ||
|
||
type ShouldRunTestSuite = (testPath: string) => Promise<boolean>; | ||
type TestRunComplete = (results: AggregatedResult) => void; | ||
|
||
export type JestHookSubscriber = { | ||
shouldRunTestSuite: (fn: ShouldRunTestSuite) => void, | ||
testRunComplete: (fn: TestRunComplete) => void, | ||
}; | ||
|
||
export type JestHookEmitter = { | ||
shouldRunTestSuite: (testPath: string) => Promise<boolean>, | ||
testRunComplete: (results: AggregatedResult) => void, | ||
}; | ||
|
||
class JestHooks { | ||
_listeners: { | ||
shouldRunTestSuite: Array<ShouldRunTestSuite>, | ||
testRunComplete: Array<TestRunComplete>, | ||
}; | ||
|
||
constructor() { | ||
this._listeners = { | ||
shouldRunTestSuite: [], | ||
testRunComplete: [], | ||
}; | ||
} | ||
|
||
getSubscriber(): JestHookSubscriber { | ||
return { | ||
shouldRunTestSuite: fn => { | ||
this._listeners.shouldRunTestSuite.push(fn); | ||
}, | ||
testRunComplete: fn => { | ||
this._listeners.testRunComplete.push(fn); | ||
}, | ||
}; | ||
} | ||
|
||
getEmitter(): JestHookEmitter { | ||
return { | ||
shouldRunTestSuite: async testPath => | ||
Promise.all( | ||
this._listeners.shouldRunTestSuite.map(listener => | ||
listener(testPath), | ||
), | ||
).then(result => | ||
result.every(shouldRunTestSuite => shouldRunTestSuite), | ||
), | ||
testRunComplete: results => | ||
this._listeners.testRunComplete.forEach(listener => listener(results)), | ||
}; | ||
} | ||
} | ||
|
||
export default JestHooks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
import type {GlobalConfig} from 'types/Config'; | ||
import chalk from 'chalk'; | ||
|
||
const activeFilters = ( | ||
globalConfig: GlobalConfig, | ||
delimiter: string = '\n', | ||
) => { | ||
const {testNamePattern, testPathPattern} = globalConfig; | ||
if (testNamePattern || testPathPattern) { | ||
const filters = [ | ||
testPathPattern | ||
? chalk.dim('filename ') + chalk.yellow('/' + testPathPattern + '/') | ||
: null, | ||
testNamePattern | ||
? chalk.dim('test name ') + chalk.yellow('/' + testNamePattern + '/') | ||
: null, | ||
] | ||
.filter(f => f) | ||
.join(', '); | ||
|
||
const messages = ['\n' + chalk.bold('Active Filters: ') + filters]; | ||
|
||
return messages.filter(message => !!message).join(delimiter); | ||
} | ||
|
||
return ''; | ||
}; | ||
|
||
export default activeFilters; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 still weird -
messages
will always be an array of size 1