-
Notifications
You must be signed in to change notification settings - Fork 294
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
Sidebar support #357
Sidebar support #357
Conversation
# Conflicts: # package.json # src/JestExt.ts # src/Settings/index.ts # src/diagnostics.ts # src/extension.ts # tests/JestExt.test.ts # tests/diagnostics.test.ts # tests/extension.test.ts
Has anybody reviewed this? |
Usually, a PR is ready for review when it passes the ci tests, unless there is a good reason for an exception... @gstamac looks like the ci test didn't finish travis test suite, maybe some new tests trigger async ops that stopped them from completing? Feel free to discuss here is you need some help. |
Pull Request Test Coverage Report for Build 488
💛 - Coveralls |
It looks like Travis has problems with console.log. I removed it from a test (not my test) and now it works. I also added changelog entry. |
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.
Hey @gstamac thanks for the PR, this is a highly requested feature.
However, I didn't get very far when trying to test run it... it crashed in a vanilla CRA app. I took a quick pass to call out a few obvious issues, please take a look. thx.
src/SideBar/TestResultTree.ts
Outdated
} | ||
|
||
private parseAssertionResults(results: JestAssertionResults, parsedResults: TestResult[]) { | ||
const suite = this.getSuite((<any>results).ancestorTitles, this.suites) |
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.
this crashed when the test file doesn't have the "describe" block outside of the "it" blocks, such as a default CRA app:
results.assertionResults=[{"failureMessages":[],"status":"passed","title":"renders without crashing"}]
TypeError: Cannot read property 'forEach' of undefined
at TestResultFile.getSuite (/Users/vsun/ConnectDotz/External/vscode-jest/out/src/SideBar/TestResultTree.js:28:16)
at TestResultFile.parseAssertionResults (/Users/vsun/ConnectDotz/External/vscode-jest/out/src/SideBar/TestResultTree.js:11:28)
at TestResultFile.results.assertionResults.forEach.r (/Users/vsun/ConnectDotz/External/vscode-jest/out/src/SideBar/TestResultTree.js:8:52)
at Array.forEach ()
at new TestResultFile (/Users/vsun/ConnectDotz/External/vscode-jest/out/src/SideBar/TestResultTree.js:8:34)
at JestTreeProvider.loadTestResultsForFile (/Users/vsun/ConnectDotz/External/vscode-jest/out/src/SideBar/JestTreeProvider.js:35:16)
at data.testResults.map.r (/Users/vsun/ConnectDotz/External/vscode-jest/out/src/SideBar/JestTreeProvider.js:30:58)
at Array.map ()
at JestTreeProvider.loadTestResults (/Users/vsun/ConnectDotz/External/vscode-jest/out/src/SideBar/JestTreeProvider.js:30:44)
at JestTreeProvider.refresh (/Users/vsun/ConnectDotz/External/vscode-jest/out/src/SideBar/JestTreeProvider.js:15:14)
at JestExt.updateWithData (/Users/vsun/ConnectDotz/External/vscode-jest/out/src/JestExt.js:304:30)
@@ -364,6 +369,8 @@ export class JestExt { | |||
const statusList = this.testResultProvider.updateTestResults(normalizedData) | |||
updateDiagnostics(statusList, this.failDiagnostics) | |||
|
|||
this.sidebarProvider.refresh(data) |
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.
not sure if we should process all the tests up front like this, giving we will only need to display the tree when the file is actually displayed in the editor... please see if you can move the logic to triggerUpdateActiveEditor
instead.
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.
The tree is displayed every time the tests are run not only when the file is selected. You probably mean the outline tree but what we are showing here is the test sidebar tree.
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.
indeed, I was thinking about the outline view, my bad.
trying it again on vscode-jest itself, added a few fake tests and encountered the following issues:
- looks like under the root "Tests" are the describe blocks instead of the file. So if a test file doesn't have a root describe block or it has multiple parallel describe blocks, they will not show any hierarchical relationship. Is that intended? Is there a particular reason we don't want to use the test file for grouping?
- (update) ok, I saw you have a
jest.showFilesInSidebar
setting, however- when I update the setting, the sidebar display didn't change until I restart/reload vscode.
- it displays the full path instead of the filename, which is by far the most important info but now is almost always truncated... can we find a way to display the filename first, maybe use tooltip or other visual hints for path if necessary?
- on the other hand, I wonder if there is really a common use case without grouping the tests by file... maybe at least to make the default of
jest.showFilesInSidebar
to true?
- (update) ok, I saw you have a
- the root level
it
blocks are not shown, and if reload/restart vscode, it crashed the plugin, put it in the never-ending spinning "Starting watch mode" and the Test sidebar is empty... (same error as mentioned in earlier comment.)
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.
I added support for root tests, removed the folder name from filename and changed the default setting to show files by default. My practice has always been to have all tests inside describe and to have only one describe per file. That's why I chose the implementation I did.
I see you have to reload the window when the settings change but I think that's the case for all vscode-jest settings because getExtensionSettings
is called on extension.activate
event.
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.
I see you have to reload the window when the settings change but I think that's the case for all vscode-jest settings because getExtensionSettings is called on extension.activate event.
Please take a look at triggerUpdateSettings
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.
the crash is gone, 👍
a few usability issues:
-
if watch-mode only triggered partial tests, the test sidebar would show the partial results instead of the full test results like you intended.
-
I saw you now display the file nodes with the relative path, which is definitely shorter, but it could still truncate the actual file name. I wonder, instead of a flat file-path structure, how about a hierarchical one?
following are nice-to-have:
-
can we have a command or shortcut to do the on-demand "deep" collapse or expand, it's like toggling the
jest.autoExpandSidebar
settings, so developers can quickly zoom in/out dynamically. -
in the explorer view, the file in the active editor gained autofocus; is it possible to do the same with the test sidebar? at least scroll/expand to the file level if not the test level by cursor...
# Conflicts: # CHANGELOG.md
Finally had some time to look into this again.
I fixed the partial test run so it updates the results. The match is done based on file name so if you delete the test file partial run will not notice it. But if you stop/start jest it will rerun all tests and refresh the whole tree.
I don't agree with this. If you have a deep tree structure this will look terrible. I think this is OK for first version.
I believe this is more for vscode than vscode-jest. But later we can add some button to the top like mocha extension does. Again good enough for first version.
You can go to the test or even line of the test failure already with a double-click. |
Can somebody review this again. Thanks. |
@gstamac Thanks for following up , sorry for the delayed response, fell sick last 2 weeks... I see the partial update is fixed, awesome! 👍
that's fine.
A hierarchical tree structure is the standard way vscode display files (see Explore view), while UI is objective, I don't think vscode Explore look terrible, quite the contrary IMHO 😏. UI aside, the biggest problem I have with flat mode is that it hides the most important information - filename:
I think you are thinking from the sidebar to file, but I meant the other direction. From the test file, I would like to see the sidebar scroll to the active file accordingly. please also take a look of the comments earlier regarding setting changes not get reflected, you would need to add the new settings in I will take a more indepth look at the code once we settle the discussion above. Thanks for your patient. |
I've implemented settings update on
Regarding file structure I understand your issues but I believe it shouldn't be used anyway. For tests there is another tree structure defined with
I think this is also related to the last request you had. I would see a better feature to scroll to the test you're on but I'm afraid this is too difficult to do with the current API. It would be too time intensive and it would make editing impossible. There is a feature request for VSCode (#5455) which would make it possible to click on the gutter decorator and go to the test. I believe this would be a much better solution. |
As a tool provider, we don't get to decide users' test structure or practice. You might have a strong preference and good reason for having a root A good tool adapts to users environment, not the other way around. I am not arguing which test structure is better, only to emphasize that, as a tool provider, we need to support both. Having a setting
indeed it would be nice if we can scroll to the particular test when clicked, but looks like VSCode (#5455) has been sitting for over 2 years, i.e. unlikely to be implemented soon, I think the next best thing is to scoll and expand the file/root-describe when active doc changed, once the test level event is available, it can be easily enhanced. JextExt has a |
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.
hey @gstamac your code is neat, I like it.
Let's do this, if you didn't have time to implement the file => treeView sync, we can table it for later. But I think the file display issue needs to be addressed. If you agree, we can finalize this PR once the change is in.
package.json
Outdated
"type": "boolean", | ||
"default": true | ||
}, | ||
"jest.autoExpandSidebar": { |
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.
vscode displays settings in alphabetic order, thus the 2 sidebar variables don't appear together in the setting editor. Maybe you can rename these 2 identifiers (put sidebar
up front?).
@gstamac let me know if there's anything I can do to help get this finished up. Thanks for adding it! |
@smith Sorry haven't had time to work on this for a while. I renamed the config names. File display issue is not important in my opinion because that's not how it should be done anyway. If you look at Mocha addon it doesn't even support filename display. If you believe it's not done correctly I can remove it. |
@smith Have you had time to check this? |
@gstamac no it's kind of fallen of my radar for now. Sorry. |
@gstamac we are preparing for the next major release that will incorporate multi-root and hopefully sidebar support too. see #442 I was trying to merge this PR to |
@connectdotz I'll try to do it this weekend. |
@gstamac do you need any help with rebase? |
The images show that the test result indicator implemented as a circle with color indicator: green (pass) / red (failed). I think that this feature should also use the icon indicator for colorblind people and for uniform look & feel... |
Hey guys, I see last comment in this PR on December. Any chance I could help with finishing this PR? |
@gerich-home If I remember correctly, it was last discussed that we should use vscode's standard hierarchical tree structure (like the Explore view) when |
The sidebar view is super nice, it gives way clearer information than the console window. Would it not be an option to merge this as-is, and add the file tree later? |
Just as a heads up - I've raised #625 which makes the test results from this extension available to other extensions. The aim being to enable an extension that I maintain to have access to the test results so they can be displayed in a side bar using Vs Code Test Explorer. It might be desirable to not merge this and not reinvent the wheel. Either way, feel free to comment on #625 as I'm pretty keen to get it across the line. I've done some initial spike work with my extension and it seems to be able to access |
close this in favor of the upcoming vscode testing API/Explorer. @gstamac sorry we did not reach the action plan sooner but thanks for the contribution nevertheless. |
I implemented Test sidebar support for vscode. It is just a first version where you can see the status of test run and locate the test by clicking on it. It will also show the test result (with errors) in the tooltip. Next version should support some commands like run and debug.
jest-editor-support
has a shortcoming and will not parse describe blocks (described here #351). That means it cannot distinct between tests with the same name in the same file. So now when you click on such test it will always put the cursor on the first one. When describe block parsing will be implemented I can update sidebar to support it also.Here are the screenshots....