mocha: Cannot find module 'tap', but tap isn't listed as a dependency

Description

On mocha 4.0.1 writing tests for backend node code. Upon running npm run test error is thrown saying ‘tap’ module can’t be found. Upon checking dependencies, TAP isn’t listed

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 15 (3 by maintainers)

Most upvoted comments

It’s something I run into as well. I think that 's because you run a test from your node_modules. You can prevent running test from node_modules by doing mocha \"./{,!(node_modules)/**/}*.test.js\" (uf you want to run *.test.js files

Meh, I don’t find it difficult to have an editor window with two tabs showing both code and corresponding test in different directories. I usually organize mine like this:

| -- myproj
     |-- /lib
         {source code}
     |-- /test
         |-- /unit
             |-- /fixtures
         |-- /e2e
             |-- /fixtures

But it’s a rather trivial cmdline change to incorporate your style…

$ NODE_ENV=test mocha --require @babel/register 'lib/**/*.spec.js' 'test/**/*.js'

try this:

npm la tap

you can figure out which dep depends on tap with that command