Skip to content

Use fullName(to show ancestor titles) for test name pattern plugin #26

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

Merged
merged 2 commits into from
Mar 14, 2019
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## master

### Chore & Maintenance

- Bump dated dependencies ([#25](https://github.com/jest-community/jest-watch-typeahead/pull/25))

### Fixes

- Use fullName(to show ancestor titles) for test name pattern plugin ([#26](https://github.com/jest-community/jest-watch-typeahead/pull/26))

## 0.2.1

- Fix cursor in terminal app ([#21](https://github.com/jest-community/jest-watch-typeahead/pull/21))
Expand Down
61 changes: 49 additions & 12 deletions src/test_name_plugin/__tests__/__snapshots__/plugin.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`can select a pattern that matches a describe block 1`] = `

[MOCK - cursorLeft]

pattern › s
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]


Pattern matches 4 tests from cached test suites

› some description foo 1

› some description bar 1

› other description foo 2

› other description bar 2
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]

[MOCK - cursorLeft]

pattern › so
[MOCK - cursorSavePosition]
[MOCK - cursorLeft]


Pattern matches 2 tests from cached test suites

› some description foo 1

› some description bar 1
[MOCK - cursorTo(13, 5)]
[MOCK - cursorRestorePosition]
`;

exports[`can select a pattern that matches multiple tests 1`] = `

[MOCK - cursorLeft]
Expand All @@ -11,9 +48,9 @@ exports[`can select a pattern that matches multiple tests 1`] = `

Pattern matches 2 tests from cached test suites

› foo 1
some description foo 1

› foo 2
other description foo 2
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]

Expand All @@ -26,9 +63,9 @@ exports[`can select a pattern that matches multiple tests 1`] = `

Pattern matches 2 tests from cached test suites

› foo 1
some description foo 1

› foo 2
other description foo 2
[MOCK - cursorTo(13, 5)]
[MOCK - cursorRestorePosition]
`;
Expand All @@ -44,9 +81,9 @@ exports[`can use arrows to select a specific test 1`] = `

Pattern matches 2 tests from cached test suites

› foo 1
some description foo 1

› foo 2
other description foo 2
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]

Expand All @@ -59,9 +96,9 @@ exports[`can use arrows to select a specific test 1`] = `

Pattern matches 2 tests from cached test suites

› foo 1
some description foo 1

› foo 2
other description foo 2
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]

Expand All @@ -74,9 +111,9 @@ exports[`can use arrows to select a specific test 1`] = `

Pattern matches 2 tests from cached test suites

› foo 1
some description foo 1

› foo 2
other description foo 2
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]
`;
Expand Down Expand Up @@ -138,9 +175,9 @@ exports[`test matching is case insensitive 1`] = `

Pattern matches 2 tests from cached test suites

› foo 1
some description foo 1

› foo 2
other description foo 2
[MOCK - cursorTo(13, 5)]
[MOCK - cursorRestorePosition]
`;
35 changes: 32 additions & 3 deletions src/test_name_plugin/__tests__/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import TestNamePlugin from '../plugin';

const testResults = [
{
testResults: [{ title: 'foo 1' }, { title: 'bar 1' }],
testResults: [
{ title: 'foo 1', fullName: 'some description foo 1' },
{ title: 'bar 1', fullName: 'some description bar 1' },
],
},
{
testResults: [{ title: 'foo 2' }, { title: 'bar 2' }],
testResults: [
{ title: 'foo 2', fullName: 'other description foo 2' },
{ title: 'bar 2', fullName: 'other description bar 2' },
],
},
];

Expand Down Expand Up @@ -54,7 +60,7 @@ it('can use arrows to select a specific test', async () => {

expect(updateConfigAndRun).toHaveBeenCalledWith({
mode: 'watch',
testNamePattern: 'foo 2',
testNamePattern: 'other description foo 2',
});
});

Expand All @@ -81,6 +87,29 @@ it('can select a pattern that matches multiple tests', async () => {
});
});

it('can select a pattern that matches a describe block', async () => {
const {
stdout,
hookEmitter,
updateConfigAndRun,
plugin,
type,
} = pluginTester(TestNamePlugin);

hookEmitter.onTestRunComplete({ testResults });
const runPromise = plugin.run({}, updateConfigAndRun);
stdout.write.mockReset();
type('s', 'o', KEYS.ENTER);
expect(stdout.write.mock.calls.join('\n')).toMatchSnapshot();

await runPromise;

expect(updateConfigAndRun).toHaveBeenCalledWith({
mode: 'watch',
testNamePattern: 'so',
});
});

it('can configure the key and prompt', async () => {
const { plugin } = pluginTester(TestNamePlugin, {
key: 'l',
Expand Down
4 changes: 2 additions & 2 deletions src/test_name_plugin/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class TestNamePatternPrompt extends PatternPrompt {
return this._cachedTestResults.reduce((matchedTests, { testResults }) => {
return matchedTests.concat(
testResults
.filter(({ title }) => regex.test(title))
.map(({ title }) => title),
.filter(({ fullName }) => regex.test(fullName))
.map(({ fullName }) => fullName),
);
}, []);
}
Expand Down