-
-
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
Changes from 8 commits
396cd18
c04edc7
1f74aa1
03b53b1
1aeafb8
b40f604
6e97a6e
ef14ade
8b999ed
2604965
ffc85f1
053d9e4
2036be9
40c4265
44c82ba
7767b71
2b084f8
58f1717
13f08e5
d4ecb92
8f6513e
401e44b
9ac7d94
25e0c4b
4a68617
3dc8c06
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 |
---|---|---|
@@ -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) | ||
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.
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. Sorry, I just moved that from watch.js, changing it now |
||
.join(', '); | ||
|
||
const messages = ['\n' + chalk.bold('Active Filters: ') + filters]; | ||
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. Why in an array? Did you mean 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. Yeah this doesn't seem to be needed, same as above just moved to from watch.js |
||
|
||
return messages.filter(message => !!message).join(delimiter); | ||
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. this is still weird - |
||
} | ||
|
||
return ''; | ||
}; | ||
|
||
export default activeFilters; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* 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 WatchPlugin from '../watch_plugin'; | ||
|
||
class QuitPlugin extends WatchPlugin { | ||
showPrompt(): Promise<void> { | ||
this._stdout.write('\n'); | ||
process.exit(0); | ||
return Promise.resolve(); | ||
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. can just mark the function as (would be cool if babel just wrapped the return value in |
||
} | ||
|
||
getUsageRow() { | ||
return { | ||
key: 'q'.codePointAt(0), | ||
prompt: 'quit watch mode', | ||
}; | ||
} | ||
} | ||
|
||
export default QuitPlugin; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* 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 {JestHooks} from '../types'; | ||
import type {GlobalConfig} from 'types/Config'; | ||
import WatchPlugin from '../watch_plugin'; | ||
import TestNamePatternPrompt from '../test_name_pattern_prompt'; | ||
import activeFilters from '../lib/active_filters_message'; | ||
import Prompt from '../lib/Prompt'; | ||
|
||
class TestNamePatternPlugin extends WatchPlugin { | ||
_prompt: Prompt; | ||
|
||
constructor(options: { | ||
stdin: stream$Readable | tty$ReadStream, | ||
stdout: stream$Writable | tty$WriteStream, | ||
}) { | ||
super(options); | ||
this._prompt = new Prompt(); | ||
} | ||
|
||
getUsageRow() { | ||
return { | ||
key: 't'.codePointAt(0), | ||
prompt: 'filter by a test regex pattern', | ||
}; | ||
} | ||
|
||
onData(key: string) { | ||
this._prompt.put(key); | ||
} | ||
|
||
showPrompt( | ||
globalConfig: GlobalConfig, | ||
updateConfigAndRun: Function, | ||
): Promise<void> { | ||
return new Promise((res, rej) => { | ||
const testPathPatternPrompt = new TestNamePatternPrompt( | ||
this._stdout, | ||
this._prompt, | ||
); | ||
|
||
testPathPatternPrompt.run( | ||
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. would be great if this was promise-friendly by default. Not for this PR though 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. It is sorta odd 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. I agree |
||
(value: string) => { | ||
updateConfigAndRun({testNamePattern: value}); | ||
res(); | ||
}, | ||
rej, | ||
{ | ||
header: activeFilters(globalConfig), | ||
}, | ||
); | ||
}); | ||
} | ||
} | ||
|
||
export default TestNamePatternPlugin; |
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.
seems like something we'd want, isn't it?
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.
Correct, this is one of the pending items that I have at the top.