Skip to content

Commit

Permalink
Use fullName(to show ancestor titles) for test name pattern plugin (#26)
Browse files Browse the repository at this point in the history
Fixes: #24 

This should allow the test name pattern plugin to display "describe" blocks.

![Screen Shot 2019-03-13 at 4 46 15 PM](https://user-images.githubusercontent.com/574806/54321760-a2892100-45af-11e9-8c3e-01a806f7c7a5.png)


I think we don't need to check for `fullName` and `title` because watch plugins were introduced in Jest@23 and `fullName` [was added in Jest@21](https://github.com/facebook/jest/blob/master/CHANGELOG.md#jest-2100)

* Should we decorate the output to better format each of the nested describe block(by using `ancestorTitles`) instead of a sentence? Or should we keep it as a sentence-ish? @SimenB
  • Loading branch information
rogeliog committed Mar 14, 2019
1 parent e8b683a commit b981b69
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 17 deletions.
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

0 comments on commit b981b69

Please sign in to comment.