1

How would one unittest, with the default mocha framework for extensions, the action of selecting one of the items in an information/warning/error message that is part of a VSCode extension?

function foo() {
  const GoToHelp = 'Go to Help';
  vscode.window.showInformationMessage('Click for more Info', GoToHelp).then(selection => {
    if (selection === GoToHelp) {
      vscode.env.openExternal(vscode.Uri.parse('example.com'));
    }
  });
}

I know that you can test the individual items associate with an action, but doing so will not catch bugs arising from how the item selection integrates with the rest of the extension e.g. the action downloads an external tool, which is spawned as a process and needs to be awaited for the process to complete successfully before the next window action is performed.

gnikit
  • 1,031
  • 15
  • 25
  • you can mock the `showInformationMessage` and return it the Promise you want, clicked or not clicked, you have to use a mock library like simple-mock – rioV8 Sep 19 '22 at 03:13
  • I was hoping not to have to rely on something like simple-mock. If I am to go down that path, using RedHat's vscode-extension-tester would be better I think. – gnikit Sep 19 '22 at 11:15
  • testing against an API without a mock functionality is impossible and mocha does not do mocking so you need a separate mock module and why not use the simplest – rioV8 Sep 19 '22 at 13:24

1 Answers1

0

A solution to this would be to use RedHat's vscode-extension-tester, specifically https://github.com/redhat-developer/vscode-extension-tester/wiki/Notification. Although, this would not be ideal since you would have to rely on an additional package and not pure mocha.js.

gnikit
  • 1,031
  • 15
  • 25