-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Proposal] Watch plugins API (#5399)
* Start adding tapable * Use test_path_pattern as a plugin * Use test_name_pattern as a plugin * Use quit as a plugin * Fix test interruption * Use update snapshot as a plugin * Use update snapshot interactive as a plugin * Change API to use a class instance * A bit of clean up and make tests pass * Change plugin implementation to not use tapable * Better sorting implementation * Add back third party plugin functionality * Fix flow * Fix ESLint * Reset file to state of master * Update failing snapshot * Remove hasSnapshotFailure and hasSnapshotFailureInteractive * Async await for showPrompt and clear active plugin on file change * Fix snapshot failure * Reenable tests * Implement shouldRunTestSuite * Add changelog * Clean up watch.js a bit
- Loading branch information
Showing
16 changed files
with
694 additions
and
316 deletions.
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.