hbenl / vscode-mocha-test-adapter

Mocha Test Adapter for the VS Code Test Explorer
MIT License
91 stars 31 forks source link

Cannot find module 'tape-catch' #113

Closed kakins closed 4 years ago

kakins commented 4 years ago

Has anyone ever run into this error? I have run npm install. Our test project works on other machines but not mine, not sure if perhaps I've updated the test runner and they haven't.

I get this error when refreshing the tests in Test Explorer. Tests do not appear in explorer.

{ Error: Cannot find module 'tape-catch'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
...
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
...
    at Array.forEach (<anonymous>)
...
    at Mocha.run (d:\x\node_modules\mocha\lib\mocha.js:811:10) code: 'MODULE_NOT_FOUND' }
hbenl commented 4 years ago

Is tape-catch actually in your dependencies or is it perhaps installed globally on the other machines? Do you use a lockfile (i.e. package-lock.json)? That is necessary to ensure that npm install will have the exact same result on all machines.

Snepsts commented 4 years ago

Getting a very similar error on a fresh npm install and a barebones project:

Error: Cannot find module 'tape'
Require stack:
- /home/snepsts/mocha-test-explorer-test/node_modules/isarray/test.js
- /home/snepsts/mocha-test-explorer-test/node_modules/mocha/lib/esm-utils.js
- /home/snepsts/mocha-test-explorer-test/node_modules/mocha/lib/mocha.js
- /home/snepsts/mocha-test-explorer-test/node_modules/mocha/index.js
- /home/snepsts/.vscode/extensions/hbenl.vscode-mocha-test-adapter-2.5.0/out/worker/bundle.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
    at Function.Module._load (internal/modules/cjs/loader.js:842:27)
    at Module.require (internal/modules/cjs/loader.js:1026:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/home/snepsts/mocha-test-explorer-test/node_modules/isarray/test.js:2:12)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Module.require (internal/modules/cjs/loader.js:1026:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/snepsts/mocha-test-explorer-test/node_modules/isarray/test.js',
    '/home/snepsts/mocha-test-explorer-test/node_modules/mocha/lib/esm-utils.js',
    '/home/snepsts/mocha-test-explorer-test/node_modules/mocha/lib/mocha.js',
    '/home/snepsts/mocha-test-explorer-test/node_modules/mocha/index.js',
    '/home/snepsts/.vscode/extensions/hbenl.vscode-mocha-test-adapter-2.5.0/out/worker/bundle.js'
  ]
}

Any clue what this could be?

EDIT: This message is from the output part of the terminal, after clicking the Error while loading tests - click to show button in the test explorer.

Snepsts commented 4 years ago

After rereading I noticed kakins mentioned he doesn't know if he has updated this plugin but other machines may not have.

I do not get this error on version 2.3.0, but 2.4.0 and 2.5.0 do have this error. Hopefully that is useful information!

Snepsts commented 4 years ago

Alright, final update from me:

I looked through commits between 2.3.0 and 2.4.0 and noticed this commit: https://github.com/hbenl/vscode-mocha-test-adapter/commit/15c19b54f3d2aa18a62c4604cba85e336c99a568

This commit is why these errors are showing up (at least for me). Let me explain:

My team uses ${servicename}-test.js to house the tests for our ${servicename}.js files. If you have a very open-ended glob like so to match it: **/*test.js... then it will run any file with the name test.js, including ones in node_modules. Thus causing these failures. We use this glob bc we want to catch all of our tests ending with test.js, but I suppose it is too liberal.

Hopefully that helps you @kakins

kakins commented 4 years ago

@Snepsts Thank you, I will certainly take a look! And I will confirm whether that solves the issue for me.

kakins commented 4 years ago

@Snepsts It looks like I have the same glob **/*test.js. What ended up being your solution for fixing this while still grabbing all the tests in your project?

kakins commented 4 years ago

Actually I ended up doing this:

    "mochaExplorer.files": "**[!node_modules]/*test.js",
Snepsts commented 4 years ago

My solution was to do {app,src}/**/*test.{js,ts} since that is how our structures are, but I think I like yours more! Thanks for sharing it!

kakins commented 4 years ago

Actually your solution worked better. Mine didn't seem to grab all of the folders I needed. Specifying folders got it working.