-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Test Runner fails to exit process when watch Plugin is included in tsconfig. #276
Conversation
Thanks for feedback. There is no call to
In TSTyche the output is written to
Could you provide more details about the plugin you are using? Also: why it is "blocking the cli from exiting naturally"? On surface it sounds like the plugin is causing the problem. Why this can’t be fixed there? |
By the way, is that plugin needed for type testing? Perhaps it is worth to consider to exclude it from the |
Im happy to elaborate ^^ First of all, yes the plugin is quite important for the testing. Im using the graphQLSP plugin which provides an array of features, but the two i am using is autocompletion in queries and an analysis whether the queried fields are used in the file the query is in. Because the Plugin is reporting the unused fields via the language server it is quite hard to access these diagnostics, as tsc does not include them on its own. This is how i stumbled upon your package, though this is not the main intend of tstyche, it does work beautifully: Every issue reported by the typescript plugin is now testable in the terminal (which i needed to make it part of the pipeline). I am too unexperienced in the lower levels of typescript development to tell whether or not the plugin should handle this issue on its own; it is however designed to run in the background. To give further inside here is the output of "why-is-node-running" (I modified the paths for privacy) Output of "why-is-node-running"The code used for logging: import { Cli } from 'tstyche/tstyche';
import process from 'node:process';
import why from 'why-is-node-running';
const cli = new Cli();
await cli.run(process.argv.slice(2));
why();
process.exit(); the output:
link to the plugin in question: https://github.com/0no-co/GraphQLSP |
The solution of mine is incomplete as the macos build fails for a few tests. When testing locally the test cases succeed when adding a timeout of one second before exiting the process, which of course is not an option for an actual solution. There seems to be some operation of tstyche that is running past resolving of the cli.run promise. I wouldn't mind using the stdout/stderr channel with a custom wrapper but if i want know whether the test completed without errors i would need to listen for an output including a hard coded string (like "Ran all test files.") which is also quite unstable. Assuming graphqlsp is not at fault the possible solutions i see are:
Im open for any ideas or insight on this |
I took a quick look at failing tests and I see that the test runner is truncating the output. We talked about that with the author of the test runner yesterday. And it seems like the culprit is It is very interesting how you are using TSTyche. I was playing with LSP plugins some time ago. Hm.. Somehow I was sure they simple respond to queries from language service. I can take a deeper look in a day or two. If that is possible, could I ask to crate a minimal reproduction repo? It would be very useful how you put all the tools together. |
Another idea. In case if there is no way to make the plugin exit, I could add |
I have created a reproduction repository for you to try out: https://github.com/FyndetNeo/tstyche-process-exit-reproduction When you pull it, run yarn and then run yarn tstyche you should see the warning from the App.tsx because of an unused field. Also the process does not exit. fyi, the useQuery function is from Apollo but is unrelated to the issue, in the project i am working on we use a different approach for the actual querying and also do not utilise the type generation from gql.tada. I see nothing wrong with implementing the process.exit behind a flag like rollup does, but i feel like nonetheless we should investigate the error that appears on macOS. Looking forward to contributing to this :D |
Thanks. I will take a look. Hm.. I was thinking about LSP process. It isn't designed to exit. It is a long running process that may be force restarted or force closed. Plugins should not care to exit. Most probably. In this light, the Good question: how to implement it so that output wouldn't get truncated. I will think about that. But first I will take deeper look at the plugin. Perhaps adding a simple |
After a quick look I have noticed that the plugin keeps on writing something into Output of
Edit: This is not a solution. See next comment. |
Sorry, the suggestion above does not report the error anymore. So it does not work. I think the Actually I will dig into |
Actually i think this is not the case. In the original project another tool is used for type generation instead, the tool used is not a typescript plugin and is instead run in its own process. Tstyche does not exit even if that tool is not running. Now it still might be that this means graphQLSP is running unnecessary operations in the context of tadaOutputLocation being undefined. |
Interesting. What are you passing to the
The error is printed after output from TSTyche test run. As if it comes from some unhandled promise? Hard to say. Hm.. I will try to draft |
Yes that error comes from graphQLSP trying to save the introspection file to the path "undefined" which is neither a .ts or .d.ts file causing the error. I have made a pull request to graphQLSP to fix this issue. I think it would be in the interest of this package to be able to ensure that it will exit. But if there are potentially unfinished operations in tstyche this can lead to problems. From my understanding the dispatch of EventEmitter does not allow this as it does not await each event being run. I will try to make a draft this eveneing (Berlin Time) showcasing what i mean, each handleEvent function would need to be async. That means it would be a breaking change |
I was playing with async events some time ago. That was not working, because reporter depends sequence of the events. If I remember it right, this was main limitation why I kept sync events. That was long ago, so might be I am mixing up something. Perhaps It could set a timeout that calls What do you think? (Hm.. That does not work with the watch mode.) |
Ah.. If Line 140 in 03e802d
That should make the watch mode exit too. Also there is no need to check for events, because there are none anymore. Only wait for stale The option must be defined here (with tstyche/source/config/OptionDefinitionsMap.ts Lines 73 to 78 in 03e802d
After adding the definition, run |
Actually, if events are not taken into account this can simply be a private method on the |
Just found root of the problem! It comes from Just follow the logic and in the @FyndetNeo Could I ask to try removing the branch with |
@FyndetNeo By the way, do you know why Reading the description it sounds like the error should be caught, but I can't make this work. I was thinking that in this case it makes more sense to use |
41f9c74
to
4fbf42d
Compare
@FyndetNeo Is this still important for you? Could you take a look at my comment above, please? |
Let me know if this is still important. Since there is no reply for some time, I assume the issue is solved and it can be closed. Also I think that |
When i tried to use the cli of tstyche i noticed that the process never exited for me. I tried the cli on the examples of the Repo which worked fine.
After digging through the code i found that there was no explicit process.exit() call, so i added one inside the bin.js which fixed the problem.
I ran why from the package 'why-is-node-running' which revealed the culprit: a typescript plugin that im using is running in watch mode blocking the cli from exiting naturally.
It would also be possible to include the process.exit() at the end of the CLI.run method but i figured that would reduce flexibility for future uses.
I really like what you have created here and will definitely use this package more in the future.
Have a great day!
Looking forward to your feedback,
Leo