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

Sidebar support #357

Closed
wants to merge 21 commits into from
Closed

Sidebar support #357

wants to merge 21 commits into from

Conversation

gstamac
Copy link
Contributor

@gstamac gstamac commented Aug 6, 2018

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....
image
image

# 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
@gstamac
Copy link
Contributor Author

gstamac commented Aug 14, 2018

Has anybody reviewed this?

@connectdotz
Copy link
Collaborator

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.

@coveralls
Copy link

coveralls commented Aug 20, 2018

Pull Request Test Coverage Report for Build 488

  • 117 of 121 (96.69%) changed or added relevant lines in 5 files are covered.
  • 41 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+1.5%) to 85.499%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/JestExt.ts 3 4 75.0%
src/SideBar/JestTreeNode.ts 58 59 98.31%
src/SideBar/JestTreeProvider.ts 28 29 96.55%
src/extension.ts 0 1 0.0%
Files with Coverage Reduction New Missed Lines %
src/extension.ts 1 69.44%
src/JestExt.ts 40 64.73%
Totals Coverage Status
Change from base Build 449: 1.5%
Covered Lines: 807
Relevant Lines: 931

💛 - Coveralls

@gstamac
Copy link
Contributor Author

gstamac commented Aug 20, 2018

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.

Copy link
Collaborator

@connectdotz connectdotz left a 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.

}

private parseAssertionResults(results: JestAssertionResults, parsedResults: TestResult[]) {
const suite = this.getSuite((<any>results).ancestorTitles, this.suites)
Copy link
Collaborator

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)
Copy link
Collaborator

@connectdotz connectdotz Aug 21, 2018

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

@connectdotz connectdotz Aug 21, 2018

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?
  • 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.)

Copy link
Contributor Author

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.

Copy link
Collaborator

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

Copy link
Collaborator

@connectdotz connectdotz left a 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:

  1. if watch-mode only triggered partial tests, the test sidebar would show the partial results instead of the full test results like you intended.

  2. 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:

  1. 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.

  2. 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...

@gstamac
Copy link
Contributor Author

gstamac commented Sep 25, 2018

Finally had some time to look into this again.

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 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 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?

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.

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.

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.

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...

You can go to the test or even line of the test failure already with a double-click.

@gstamac
Copy link
Contributor Author

gstamac commented Oct 5, 2018

Can somebody review this again. Thanks.

@connectdotz
Copy link
Collaborator

@gstamac Thanks for following up , sorry for the delayed response, fell sick last 2 weeks...

I see the partial update is fixed, awesome! 👍

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.

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.

that's fine.

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?

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.

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:

sidebar-snapshot
(a snapshot from vscode-jest itself)

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...

You can go to the test or even line of the test failure already with a double-click.

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 triggerUpdateSettings.

I will take a more indepth look at the code once we settle the discussion above. Thanks for your patient.

@gstamac
Copy link
Contributor Author

gstamac commented Oct 6, 2018

I've implemented settings update on triggerUpdateSettings.

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:

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 describe blocks and I believe this should be the tree displayed in the sidebar. If you look at Mocha sidebar it doesn't have a file tree structure. I implemented it per your request but I still think it shouldn't be used. If somebody has a need for it and wants to add features to it they can do that.

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.

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.

@connectdotz
Copy link
Collaborator

connectdotz commented Oct 7, 2018

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 describe blocks and I believe this should be the tree displayed in the sidebar.

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 describe block, it doesn't mean other users' preferences or reasons are less valid. Actually, if you look at a few popular open source projects, you will see many of their tests do not have root describes: jest, yarn, or the default react apps generated by CRA. For projects without root describe blocks, the test file is its scope, equivalent to the root describe, therefore should be displayed accordingly; and the most intuitive UI is to adopt vscode's standard hierarchical tree struture that the Explore view used.

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 showFilesInSidebar as you implemented is a great way to do this: for projects using root describes, they could simply turn off showFilesInSidebar and you got mocha like display; for the others, turn on showFilesInSidebar. Now, we just need to make sure the files do display clearly and intuitively when the flag is on.


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...There is a feature request for VSCode (#5455) which would make it possible to click on the gutter decorator and go to the test.

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 triggerUpdateActiveEditor to handle active editor change event, you can simply add the following tree view code there. Reading up the vscode api, it seems that you can get a TreeView by using createTreeView instead of registerTreeDataProvider; once you have the TreeView instance, you can scroll to the position with reval; and of course you already know how to do item expansion. Thus it seems relatively simple, but I haven't implemented it myself so could be wrong...

Copy link
Collaborator

@connectdotz connectdotz left a 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": {
Copy link
Collaborator

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?).

@smith
Copy link

smith commented Dec 11, 2018

@gstamac let me know if there's anything I can do to help get this finished up. Thanks for adding it!

@gstamac
Copy link
Contributor Author

gstamac commented Feb 7, 2019

@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.

@gstamac
Copy link
Contributor Author

gstamac commented Mar 11, 2019

@smith Have you had time to check this?

@smith
Copy link

smith commented Mar 11, 2019

@gstamac no it's kind of fallen of my radar for now. Sorry.

@connectdotz connectdotz mentioned this pull request Apr 12, 2019
12 tasks
@connectdotz
Copy link
Collaborator

@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 beta but multi-root has introduced some structural change that I figure you might want to do the merge yourself. It would be great if you can rebase this PR against beta branch, then I will merge it and help to get this feature out for the next release.

@gstamac
Copy link
Contributor Author

gstamac commented Apr 17, 2019

@connectdotz I'll try to do it this weekend.

@escaton
Copy link
Contributor

escaton commented Jun 16, 2019

@gstamac do you need any help with rebase?

@rhalaly
Copy link
Contributor

rhalaly commented Dec 25, 2019

The images show that the test result indicator implemented as a circle with color indicator: green (pass) / red (failed).
But in this PR, they changed the indicator to an icon (✘, ✔) for colorblind people.

I think that this feature should also use the icon indicator for colorblind people and for uniform look & feel...

@gerich-home
Copy link

Hey guys, I see last comment in this PR on December. Any chance I could help with finishing this PR?
What should be done? (any checklist?)

@connectdotz
Copy link
Collaborator

@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 showFilesInSidebar is true`. Would be great if we can get this completed 👍

@wmertens
Copy link

wmertens commented May 8, 2020

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?
There are some other sidebar extensions, but they don't have all the other integrations that vscode-jest has.

@rossknudsen
Copy link

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 vscode-jest and get updates when the test results change.

@connectdotz
Copy link
Collaborator

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.

@connectdotz connectdotz closed this Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants