Skip to content
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

Make testNamePattern and testPathPattern play better together #3327

Merged
merged 7 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/jest-cli/src/TestNamePatternPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const stringLength = require('string-length');
const Prompt = require('./lib/Prompt');
const formatTestNameByPattern = require('./lib/formatTestNameByPattern');

const pluralizeTest = (total: number) => (total === 1 ? 'test' : 'tests');
const pluralizeTest = (total: number) => total === 1 ? 'test' : 'tests';

const usage = () =>
`\n ${chalk.bold('Pattern Mode Usage')}\n` +
`\n${chalk.bold('Pattern Mode Usage')}\n` +
` ${chalk.dim('\u203A Press')} Esc ${chalk.dim('to exit pattern mode.')}\n` +
` ${chalk.dim('\u203A Press')} Enter ` +
`${chalk.dim('to apply pattern to all tests.')}\n` +
Expand All @@ -40,9 +40,12 @@ module.exports = class TestNamePatternPrompt {
this._prompt = prompt;
}

run(onSuccess: Function, onCancel: Function) {
run(onSuccess: Function, onCancel: Function, options?: {header: string}) {
this._pipe.write(ansiEscapes.cursorHide);
this._pipe.write(ansiEscapes.clearScreen);
if (options && options.header) {
this._pipe.write(options.header);
}
this._pipe.write(usage());
this._pipe.write(ansiEscapes.cursorShow);

Expand Down Expand Up @@ -121,8 +124,7 @@ module.exports = class TestNamePatternPrompt {
if (regex.test(title)) {
matchedTests.push(title);
}
}),
);
}));

return matchedTests;
}
Expand Down
12 changes: 7 additions & 5 deletions packages/jest-cli/src/TestPathPatternPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type SearchSources = Array<{|
searchSource: SearchSource,
|}>;

const pluralizeFile = (total: number) => (total === 1 ? 'file' : 'files');
const pluralizeFile = (total: number) => total === 1 ? 'file' : 'files';

const usage = () =>
`\n ${chalk.bold('Pattern Mode Usage')}\n` +
`\n${chalk.bold('Pattern Mode Usage')}\n` +
` ${chalk.dim('\u203A Press')} Esc ${chalk.dim('to exit pattern mode.')}\n` +
` ${chalk.dim('\u203A Press')} Enter ` +
`${chalk.dim('to apply pattern to all filenames.')}\n` +
Expand All @@ -48,9 +48,12 @@ module.exports = class TestPathPatternPrompt {
this._prompt = prompt;
}

run(onSuccess: Function, onCancel: Function) {
run(onSuccess: Function, onCancel: Function, options?: {header: string}) {
this._pipe.write(ansiEscapes.cursorHide);
this._pipe.write(ansiEscapes.clearScreen);
if (options && options.header) {
this._pipe.write(options.header);
}
this._pipe.write(usage());
this._pipe.write(ansiEscapes.cursorShow);

Expand Down Expand Up @@ -109,8 +112,7 @@ module.exports = class TestPathPatternPrompt {
return highlight(path, filePath, pattern, context.config.rootDir);
})
.forEach(filePath =>
this._pipe.write(`\n ${chalk.dim('\u203A')} ${filePath}`),
);
this._pipe.write(`\n ${chalk.dim('\u203A')} ${filePath}`));

if (total > max) {
const more = total - max;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,30 @@ exports[`Watch mode flows Pressing "P" enters pattern mode 8`] = `
[MOCK - cursorRestorePosition]"
`;

exports[`Watch mode flows Pressing "c" clears the filters 1`] = `
"[MOCK - cursorHide]
[MOCK - clearScreen]



Pattern Mode Usage
› Press Esc to exit pattern mode.
› Press Enter to apply pattern to all filenames.


[MOCK - cursorShow]



pattern ›
[MOCK - cursorSavePosition]


Start typing to filter by a filename regex pattern.
[MOCK - cursorTo(11, 5)]
[MOCK - cursorRestorePosition]"
`;

exports[`Watch mode flows Results in pattern mode get truncated appropriately 1`] = `
"

Expand Down Expand Up @@ -312,3 +336,128 @@ exports[`Watch mode flows Results in pattern mode get truncated appropriately 3`
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]"
`;

exports[`Watch mode flows Shows the appropiate header when both filters are active 1`] = `
"[MOCK - cursorHide]
[MOCK - clearScreen]

Active Filters: filename /p.*10/, test name /test/


Pattern Mode Usage
› Press Esc to exit pattern mode.
› Press Enter to apply pattern to all tests.


[MOCK - cursorShow]



pattern ›
[MOCK - cursorSavePosition]


Start typing to filter by a test name regex pattern.
[MOCK - cursorTo(11, 5)]
[MOCK - cursorRestorePosition]"
`;

exports[`Watch mode flows Shows the appropiate header when the filename filter is active 1`] = `
"[MOCK - cursorHide]
[MOCK - clearScreen]

Active Filters: filename /p.*10/


Pattern Mode Usage
› Press Esc to exit pattern mode.
› Press Enter to apply pattern to all filenames.


[MOCK - cursorShow]



pattern ›
[MOCK - cursorSavePosition]


Start typing to filter by a filename regex pattern.
[MOCK - cursorTo(11, 5)]
[MOCK - cursorRestorePosition]"
`;

exports[`Watch mode flows Shows the appropiate header when the filename filter is active 2`] = `
"[MOCK - cursorHide]
[MOCK - clearScreen]

Active Filters: filename /p/


Pattern Mode Usage
› Press Esc to exit pattern mode.
› Press Enter to apply pattern to all filenames.


[MOCK - cursorShow]



pattern ›
[MOCK - cursorSavePosition]


Start typing to filter by a filename regex pattern.
[MOCK - cursorTo(11, 5)]
[MOCK - cursorRestorePosition]"
`;

exports[`Watch mode flows Shows the appropiate header when the test name filter is active 1`] = `
"[MOCK - cursorHide]
[MOCK - clearScreen]

Active Filters: test name /test/


Pattern Mode Usage
› Press Esc to exit pattern mode.
› Press Enter to apply pattern to all tests.


[MOCK - cursorShow]



pattern ›
[MOCK - cursorSavePosition]


Start typing to filter by a test name regex pattern.
[MOCK - cursorTo(11, 5)]
[MOCK - cursorRestorePosition]"
`;

exports[`Watch mode flows Shows the appropiate header when the test name filter is active 2`] = `
"[MOCK - cursorHide]
[MOCK - clearScreen]

Active Filters: test name /t/


Pattern Mode Usage
› Press Esc to exit pattern mode.
› Press Enter to apply pattern to all tests.


[MOCK - cursorShow]



pattern ›
[MOCK - cursorSavePosition]


Start typing to filter by a test name regex pattern.
[MOCK - cursorTo(11, 5)]
[MOCK - cursorRestorePosition]"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Array [
Watch Usage
› Press o to only run tests related to changed files.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press q to quit watch mode.
› Press Enter to trigger a test run.
",
Expand Down
Loading