Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Create a basic integration test #15

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 1 commit into from
Jul 19, 2022
Merged

Conversation

xeger
Copy link
Contributor

@xeger xeger commented Jul 2, 2022

Wow @kddnewton; when you said that writing tests for VS Code extensions was hard, you weren't kidding! I took it as a personal challenge -- and I have some other extension ideas, and wanted to delve into it a bit anyhow.

We now have a single test case, but it's a nominally useful one: prove that formatting works.

Not sure how actually-useful this is, especially if it isn't hooked into CI, but it's perhaps a bit easier than testing things by hand. Especially if we can use the APIs to inspect overlays, this should be sufficient to test basic functions, settings, and commands.

If you like the idea, I can look into adding a GitHub job for CI coverage. (I'm sure it will be pure joy getting Ruby, Node, Electron and all of the bells and whistles crammed into a container; at least Microsoft has some examples to get us started.)

@kddnewton
Copy link
Member

Yeah I think this will work. Shouldn't be too bad to integrate it into GitHub actions. I had to set up something similar with prettier which is here: https://github.com/prettier/plugin-ruby/blob/main/.github/workflows/main.yml#L23-L32 should get you close to what you need.

@xeger xeger force-pushed the tests branch 5 times, most recently from ef09e29 to 10d5715 Compare July 6, 2022 05:51
@xeger
Copy link
Contributor Author

xeger commented Jul 6, 2022

Here's something that runs, but hangs. Based on official reference docs. Works locally on my Mac laptop.

The dbus warnings are probably harmless but the "socket got disposed" stuff is suspect; something's not running right.

@xeger xeger force-pushed the tests branch 2 times, most recently from 89e7c26 to 9419faa Compare July 6, 2022 19:06
@kddnewton
Copy link
Member

@xeger looks like this is maybe working now? what's the status?

@xeger
Copy link
Contributor Author

xeger commented Jul 8, 2022

It's not quite working; I can get VS Code running in CI, but it hangs when we issue the command to format code. Need to SSH in and add tons of printf debugging. Thrilling!

The test suite is runnable in local dev; if you'd prefer, we could merge it now and hold off on the CI stuff. (Just merge everything except the .github changes in that case.)

@kddnewton
Copy link
Member

kddnewton commented Jul 8, 2022 via email

@xeger xeger force-pushed the tests branch 18 times, most recently from 46f8af2 to ee06e1c Compare July 9, 2022 07:51
@xeger xeger force-pushed the tests branch 14 times, most recently from b420dcf to 0acd3a9 Compare July 9, 2022 20:53
@xeger
Copy link
Contributor Author

xeger commented Jul 9, 2022

Okay @kddnewton: I have something that is workable if not ideal. Some issues are chronicled below.

Too Slow

The biggest issues with testing are performance and visibility: stuff is just slow; in CI it's very slow, and extremely difficult to understand what has happened when things fail.

I spent Friday evening hacking Xvfb and ffmpeg to grab videos of the Code window during test execution, which was the key to understanding. I'd like to make this more elaborate in future (e.g. new video for every test case) but as-is, our extension is probably in the top 1% of usability among all extension test suites (of the few that even have tests!) I will turn the dbus/xvfb/video stuff into a GitHub action at some point because it's useful with other extensions, and potentially with other GUI software.

Too interdependent

Another significant issue with testing is circularity: ideally we need to inspect the output channel to verify the extension is doing what we want, but Code's API makes it impossible to interact with output channels unless you're the owner -- so we need to use the "Show Output Channel" command - thereby interacting with the system under test - and then rely on hacks (e.g. the channel is a TextDocument as long as it is visible on screen) to get the output. And, we have no way to clear the channel, so we can't distinguish new output from old!

I spent hours on this and just gave up in the end; instead I spy on the extension state by exporting its language client. Not quite as black-box as I'd like, but it works.

Too many language clients!

My hunch about the hang I was seeing with "Format Document" is: the extension is getting activated twice in a row! We had no guard against this from a cursory glance at the source, so we happily spawned two language servers and that explains why I saw two options for Syntax Tree when issuing the format-document command. (There is no API for interacting with those modal popups so once one is visible, it's game over for the test runner.) Not sure why this only happens in CI and not on my laptop.

Once I made start/stop 100% idempotent by checking for an existing languageClient before making a new one, the hang during tests went away. Succedd!

TL;DR

I am happy with this; it's a good start, and I'm very proud of the screen-recording artifacts. Merge away!

@xeger xeger marked this pull request as ready for review July 9, 2022 21:07
@xeger xeger force-pushed the tests branch 2 times, most recently from 057a767 to 4dc0dd0 Compare July 11, 2022 02:32
@kddnewton
Copy link
Member

@xeger sorry but do you mind rebasing? Then I'll merge!

@xeger
Copy link
Contributor Author

xeger commented Jul 19, 2022

Done @kddnewton (& squashed to cleanup the commit history); good to merge once it goes green.

@kddnewton kddnewton merged commit 4adcd24 into ruby-syntax-tree:main Jul 19, 2022
@xeger xeger deleted the tests branch July 19, 2022 14:20
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.

2 participants