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

Cannot find module 'tap', but tap isn't listed as a dependency #3092

Closed
splitcircle opened this issue Nov 3, 2017 · 15 comments
Closed

Cannot find module 'tap', but tap isn't listed as a dependency #3092

splitcircle opened this issue Nov 3, 2017 · 15 comments
Labels
type: question support question

Comments

@splitcircle
Copy link

splitcircle commented Nov 3, 2017

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

@ORESoftware
Copy link

try this:

npm la tap

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

@ScottFreeCode
Copy link
Contributor

Unless you didn't npm i though, it's more likely that something is requireing tap without it being in the dependency tree. But it is probably somewhere in the project code, so it should be a simple matter of text searching. And if it is your code calling tap and it is supposed to be there, then it's just going to be a matter of npm i --save-dev tap to actually install it (and record it in the devDependencies).

@ScottFreeCode ScottFreeCode added the type: question support question label Nov 5, 2017
@pcowgill
Copy link

I also experienced this, and even though I couldn't find tap as a requirement anywhere, npm i --save-dev tap fixed the issue. Maybe mocha 5.0.1 needs to add it as a dependency?

@nchevobbe
Copy link

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

@pcowgill
Copy link

@nchevobbe You're right, that was it - thanks!

@AndersonZacharyT
Copy link

thank you @nchevobbe! It made no sense until you came along :)

@chanakyacool
Copy link

@nchevobbe thanks brother you saved a day 😄

@nitishbhushan2013
Copy link

thanks Nicolas .. perfect solution

@Miteshdv
Copy link

It worked for me thanks

@sinchi
Copy link

sinchi commented Sep 6, 2018

thank you @nchevobbe

@servel333
Copy link

servel333 commented Sep 11, 2018

For anyone who finds this like I did...

TLDR: Overly aggressive find (And same issue as @nchevobbe mentioned)

My package.lock scripts.test looked like this

  • "NODE_ENV=test mocha --compilers js:babel-core/register $(find . \\( -name '*.spec.js' -or -name '*.test.js' \\) -print) $(find ./test/ -name '*.js' -print)"

which will find al *.spec.js and *.test.js files, including those inside node_modules, and those tests typically depend on dev dependencies that are not installed in packages installed in node_modules.

My solution was to filter out node_modules from my test command.

  • "NODE_ENV=test mocha --compilers js:babel-core/register $(find . \\( -name '*.spec.js' -or -name '*.test.js' \\) -print | grep -v node_modules) $(find ./test/ -name '*.js' -print | grep -v node_modules)"

@Emmynash
Copy link

@nchevobbe just like magic it works!

@plroebuck
Copy link
Contributor

All your tests (e.g., "*.spec.js" and "*.test.js") should be in your "test" directory (or some subdirectory within). The find commands should be wholly unnecessary if you organize them as such.

Assuming this, the cmdline for recent versions of Mocha would be:

# Using Babel 6...
$ NODE_ENV=test mocha --require babel-core/register 'test/**/*.js'

# Using Babel 7...
$ NODE_ENV=test mocha --require @babel/register 'test/**/*.js'

@pcowgill
Copy link

One downside of that strategy is that it’s harder to visually verify that all files are tested at a glance. Putting test files right next to the files under test makes that easier.

@plroebuck
Copy link
Contributor

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question support question
Projects
None yet
Development

No branches or pull requests