'Webpack bundler breaking tests (global variable management works differently)

After introducing bundler to one of my extensions some tests stopped working at all. I must admit that is little bit hacky solution but that's pretty much what I got recommended here: https://github.com/microsoft/vscode/issues/23814. Anyway, let me give you some context. Extension I'm trying to test has a lot of completions and I wrote integration tests to check if those completions show up properly in different code contexts.

To achieve that I need to use commands to trigger completion and then cycle between completions to collect all of those which were shown. As per the issue mentioned above I went with hacky solution to use resolveCompletionItem and set global variable there which then I read from the test. This way after cycling through all completions I have a list of all of them and I can compare that with expected values.
This solution works fine but only without a bundler.
I have prepared two simple repro repositories: unbundled and bundled.
The only difference is that one is bundled and the other not. The logic is the same.
The test is here and the code being tested here. It uses the same mechanism as my original extension which basically is a global variable set on each call to resolveCompletionItem.
I also print value of this variable in the extension code itself for debugging purposes and the results are as follows:

  1. Unbundled:
    enter image description here
  2. Bundled:
    enter image description here

The last log is different and this is the one trying to read global variable from the extension and it's trying to read it from the test.

After some research I found two different workarounds for that problem:

  1. Don't bundle for running tests
  2. Use filesystem to keep state between extension and test

The second one is even more hacky and adds more redundant code to production code so I'd rather not do that. First one is not so bad but would be better to run integration tests in real bundled scenario - this may potentially find some bugs I couldn't find otherwise.

The question is if anyone knows different way of passing global state between the extension itself and the test. Another option would be to just read currently selected suggestion programmatically but as per issue mentioned at the beginning this was not possible back then. VSCode API has changed a lot since then but there is no good documentation for such things. I've tried looking at VSCode codebase but it's too big and already too complex to easily find any clues.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source