Skip to content

Commit b981b69

Browse files
authored
Use fullName(to show ancestor titles) for test name pattern plugin (#26)
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
1 parent e8b683a commit b981b69

File tree

4 files changed

+91
-17
lines changed

4 files changed

+91
-17
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
## master
22

3+
### Chore & Maintenance
4+
5+
- Bump dated dependencies ([#25](https://github.com/jest-community/jest-watch-typeahead/pull/25))
6+
7+
### Fixes
8+
9+
- Use fullName(to show ancestor titles) for test name pattern plugin ([#26](https://github.com/jest-community/jest-watch-typeahead/pull/26))
10+
311
## 0.2.1
412

513
- Fix cursor in terminal app ([#21](https://github.com/jest-community/jest-watch-typeahead/pull/21))

src/test_name_plugin/__tests__/__snapshots__/plugin.test.js.snap

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`can select a pattern that matches a describe block 1`] = `
4+
5+
[MOCK - cursorLeft]
6+
7+
pattern › s
8+
[MOCK - cursorSavePosition]
9+
[MOCK - cursorLeft]
10+
11+
12+
Pattern matches 4 tests from cached test suites
13+
14+
› some description foo 1
15+
16+
› some description bar 1
17+
18+
› other description foo 2
19+
20+
› other description bar 2
21+
[MOCK - cursorTo(12, 5)]
22+
[MOCK - cursorRestorePosition]
23+
24+
[MOCK - cursorLeft]
25+
26+
pattern › so
27+
[MOCK - cursorSavePosition]
28+
[MOCK - cursorLeft]
29+
30+
31+
Pattern matches 2 tests from cached test suites
32+
33+
› some description foo 1
34+
35+
› some description bar 1
36+
[MOCK - cursorTo(13, 5)]
37+
[MOCK - cursorRestorePosition]
38+
`;
39+
340
exports[`can select a pattern that matches multiple tests 1`] = `
441
542
[MOCK - cursorLeft]
@@ -11,9 +48,9 @@ exports[`can select a pattern that matches multiple tests 1`] = `
1148
1249
Pattern matches 2 tests from cached test suites
1350
14-
› foo 1
51+
some description foo 1
1552
16-
› foo 2
53+
other description foo 2
1754
[MOCK - cursorTo(12, 5)]
1855
[MOCK - cursorRestorePosition]
1956
@@ -26,9 +63,9 @@ exports[`can select a pattern that matches multiple tests 1`] = `
2663
2764
Pattern matches 2 tests from cached test suites
2865
29-
› foo 1
66+
some description foo 1
3067
31-
› foo 2
68+
other description foo 2
3269
[MOCK - cursorTo(13, 5)]
3370
[MOCK - cursorRestorePosition]
3471
`;
@@ -44,9 +81,9 @@ exports[`can use arrows to select a specific test 1`] = `
4481
4582
Pattern matches 2 tests from cached test suites
4683
47-
› foo 1
84+
some description foo 1
4885
49-
› foo 2
86+
other description foo 2
5087
[MOCK - cursorTo(12, 5)]
5188
[MOCK - cursorRestorePosition]
5289
@@ -59,9 +96,9 @@ exports[`can use arrows to select a specific test 1`] = `
5996
6097
Pattern matches 2 tests from cached test suites
6198
62-
› foo 1
99+
some description foo 1
63100
64-
› foo 2
101+
other description foo 2
65102
[MOCK - cursorTo(12, 5)]
66103
[MOCK - cursorRestorePosition]
67104
@@ -74,9 +111,9 @@ exports[`can use arrows to select a specific test 1`] = `
74111
75112
Pattern matches 2 tests from cached test suites
76113
77-
› foo 1
114+
some description foo 1
78115
79-
› foo 2
116+
other description foo 2
80117
[MOCK - cursorTo(12, 5)]
81118
[MOCK - cursorRestorePosition]
82119
`;
@@ -138,9 +175,9 @@ exports[`test matching is case insensitive 1`] = `
138175
139176
Pattern matches 2 tests from cached test suites
140177
141-
› foo 1
178+
some description foo 1
142179
143-
› foo 2
180+
other description foo 2
144181
[MOCK - cursorTo(13, 5)]
145182
[MOCK - cursorRestorePosition]
146183
`;

src/test_name_plugin/__tests__/plugin.test.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ import TestNamePlugin from '../plugin';
44

55
const testResults = [
66
{
7-
testResults: [{ title: 'foo 1' }, { title: 'bar 1' }],
7+
testResults: [
8+
{ title: 'foo 1', fullName: 'some description foo 1' },
9+
{ title: 'bar 1', fullName: 'some description bar 1' },
10+
],
811
},
912
{
10-
testResults: [{ title: 'foo 2' }, { title: 'bar 2' }],
13+
testResults: [
14+
{ title: 'foo 2', fullName: 'other description foo 2' },
15+
{ title: 'bar 2', fullName: 'other description bar 2' },
16+
],
1117
},
1218
];
1319

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

5561
expect(updateConfigAndRun).toHaveBeenCalledWith({
5662
mode: 'watch',
57-
testNamePattern: 'foo 2',
63+
testNamePattern: 'other description foo 2',
5864
});
5965
});
6066

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

90+
it('can select a pattern that matches a describe block', async () => {
91+
const {
92+
stdout,
93+
hookEmitter,
94+
updateConfigAndRun,
95+
plugin,
96+
type,
97+
} = pluginTester(TestNamePlugin);
98+
99+
hookEmitter.onTestRunComplete({ testResults });
100+
const runPromise = plugin.run({}, updateConfigAndRun);
101+
stdout.write.mockReset();
102+
type('s', 'o', KEYS.ENTER);
103+
expect(stdout.write.mock.calls.join('\n')).toMatchSnapshot();
104+
105+
await runPromise;
106+
107+
expect(updateConfigAndRun).toHaveBeenCalledWith({
108+
mode: 'watch',
109+
testNamePattern: 'so',
110+
});
111+
});
112+
84113
it('can configure the key and prompt', async () => {
85114
const { plugin } = pluginTester(TestNamePlugin, {
86115
key: 'l',

src/test_name_plugin/prompt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ class TestNamePatternPrompt extends PatternPrompt {
8989
return this._cachedTestResults.reduce((matchedTests, { testResults }) => {
9090
return matchedTests.concat(
9191
testResults
92-
.filter(({ title }) => regex.test(title))
93-
.map(({ title }) => title),
92+
.filter(({ fullName }) => regex.test(fullName))
93+
.map(({ fullName }) => fullName),
9494
);
9595
}, []);
9696
}

0 commit comments

Comments
 (0)