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

Mocha: Error: Cannot find module 'vscode' #5

Closed
deerawan opened this issue Dec 19, 2015 · 8 comments
Closed

Mocha: Error: Cannot find module 'vscode' #5

deerawan opened this issue Dec 19, 2015 · 8 comments
Assignees

Comments

@deerawan
Copy link

Hi,

I was trying to run the testing with command

mocha out/test

but got this error

Error: Cannot find module 'vscode'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:286:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/deerawan/Work/Sites/opensource/vscode-wordcount/out/test/extension.test.js:10:14)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at /usr/local/lib/node_modules/mocha/lib/mocha.js:216:27
    at Array.forEach (native)
    at Mocha.loadFiles (/usr/local/lib/node_modules/mocha/lib/mocha.js:213:14)
    at Mocha.run (/usr/local/lib/node_modules/mocha/lib/mocha.js:453:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/mocha/bin/_mocha:393:18)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
    at startup (node.js:118:18)
    at node.js:952:3
@chrisdias
Copy link
Member

hi - did you run npm install?

@deerawan
Copy link
Author

@chrisdias yes, I did. Did you get this error too?

@chrisdias
Copy link
Member

@bpasero any ideas here? i can run tests under the debugger, but not from the command line.

@bpasero
Copy link
Member

bpasero commented Jan 5, 2016

We do not support to run tests from the command line at the moment. The only exception is https://code.visualstudio.com/docs/extensions/testing-extensions#_running-tests-automatically-on-travis-ci-build-machines

@bpasero bpasero closed this as completed Jan 5, 2016
@cmstead
Copy link

cmstead commented Jan 12, 2016

Tangentially related, I found this on a google search for the same issue.

My solution has been the following:

As I have been developing my extension, I abstract away all of the vscode module dependencies and wrap up my novel code in modules which don't rely on the vscode module. This makes my code testable in the large without adding a dependency on a third party module.

I don't know how complex any other extensions might end up being for people who find this, but I thought it might help kick off a new thought process for anyone who runs into a similar issue. Ultimately it's not useful to test whether the vscode module is working properly if you are developing an extension, so hopefully, your code is basically testable except where it touches the VS Code API.

@bpasero
Copy link
Member

bpasero commented Jan 13, 2016

Totally right way of writing tests 👍

john-patterson added a commit to john-patterson/vscode-cpptools that referenced this issue Jul 24, 2018
tanishiking added a commit to tanishiking/metals-vscode that referenced this issue Sep 1, 2022
This commit adds a test for `needCheckForUpdates`.
(because, even though `metals-vscode` has a complicated logic, it lacks
unit-tests to verify the behaviors).

For adding unit tests, this commit abstract away the logics that need
an access to vscode APIs, becuase we need to run integration test for
accessing vscode APIs.
see: microsoft/vscode-wordcount#5 (comment)
microsoft/vscode#82471 (comment)
tanishiking added a commit to tanishiking/metals-vscode that referenced this issue Sep 1, 2022
This commit adds a test for `needCheckForUpdates`.
(because, even though `metals-vscode` has a complicated logic, it lacks
unit-tests to verify the behaviors).

For adding unit tests, this commit abstract away the logics that need
an access to vscode APIs, becuase we need to run integration test for
accessing vscode APIs.
see: microsoft/vscode-wordcount#5 (comment)
microsoft/vscode#82471 (comment)
tanishiking added a commit to tanishiking/metals-vscode that referenced this issue Sep 2, 2022
scalameta#1144

This commit adds a test for `needCheckForUpdates`.

For adding unit tests, this commit abstract away the logic that needs
access to vscode APIs, becuase we need to run an integration test for
accessing vscode APIs.
see: microsoft/vscode-wordcount#5 (comment)
microsoft/vscode#82471 (comment)
tanishiking added a commit to tanishiking/metals-vscode that referenced this issue Sep 2, 2022
scalameta#1144

This commit adds a test for `needCheckForUpdates`.

For adding unit tests, this commit abstract away the logic that needs
access to vscode APIs, becuase we need to run an integration test for
accessing vscode APIs.
see: microsoft/vscode-wordcount#5 (comment)
microsoft/vscode#82471 (comment)
@prmichaelsen
Copy link

Tangentially related, I found this on a google search for the same issue.

My solution has been the following:

As I have been developing my extension, I abstract away all of the vscode module dependencies and wrap up my novel code in modules which don't rely on the vscode module. This makes my code testable in the large without adding a dependency on a third party module.

I don't know how complex any other extensions might end up being for people who find this, but I thought it might help kick off a new thought process for anyone who runs into a similar issue. Ultimately it's not useful to test whether the vscode module is working properly if you are developing an extension, so hopefully, your code is basically testable except where it touches the VS Code API.

I'm so miffed. I thought my tests were failing because I was using jest as my test runner. I was initially going to use this approach by defining types myself but I decided I should just set everything up with mocha. I spent all this time figuring out mocha only to find out that even with mocha you can't actually run the tests from the command line. I--

@cmstead
Copy link

cmstead commented Aug 25, 2024

@prmichaelsen:

I definitely think you should consider breaking the dependency with a facade or something similar, defining a contract just for the facade, lift the interface definition out of the facade file, import it where you need the type, and do a cheap and dirty (or not so cheap and dirty) DI so you can text your module in isolation.

I run all of my extension tests from the command line. I simply fake the output from the vscode module and then test the behavior from there. This should all work from jest. Ultimately, the real vscode module requires a full running instance of vscode which can be massively frustrating.

Separately, if you want to test functionality in a live environment, you might be able to test electron applications with selenium. I haven't tried it myself, but I believe it is doable.

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

No branches or pull requests

5 participants