Can't run tests with Mocha on Express.js app - node.js

I am trying to setup mocha to test an ExpressJs app.
When I run tests using npm test I got the following error:
TypeError: undefined is not a function
at Object.<anonymous> (/myapp/bin/www:11:18)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.cls_wrapMethod (/Users/nathanzylbersztejn/git/airdesk-api/node_modules/newrelic/lib/shimmer.js:230:38)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/nathanzylbersztejn/git/airdesk-api/controllers/session.js:13:11)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.cls_wrapMethod (/Users/nathanzylbersztejn/git/airdesk-api/node_modules/newrelic/lib/shimmer.js:230:38)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/nathanzylbersztejn/git/airdesk-api/app.js:10:25)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478: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 Object.<anonymous> (/Users/nathanzylbersztejn/git/airdesk-api/test/test.js:5:11)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478: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 /Users/nathanzylbersztejn/git/airdesk-api/node_modules/mocha/lib/mocha.js:185:27
at Array.forEach (native)
at Mocha.loadFiles (/Users/nathanzylbersztejn/git/airdesk-api/node_modules/mocha/lib/mocha.js:182:14)
at Mocha.run (/Users/nathanzylbersztejn/git/airdesk-api/node_modules/mocha/lib/mocha.js:394:31)
at loadAndRun (/Users/nathanzylbersztejn/git/airdesk-api/node_modules/mocha/bin/_mocha:349:22)
at Object.<anonymous> (/Users/nathanzylbersztejn/git/airdesk-api/node_modules/mocha/bin/_mocha:366:3)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
Where /myapp/bin/www:11:5 refers to the following line:
var app = require('../app')
app.set('port', process.env.PORT || 3000); // <- this line
^
The app works well, so it's not related to the app setup.
Any idea?

First guess is you have a circular dependency, which node handles by returning an empty object until the circle is finished. Do you do something like require("./bin/www"); inside app.js?
If you post app.js and bin/www we should be able to confirm.
Second guess is app.js just isn't getting the commonjs exports correct.
I'm also pretty sure you should be able to test your express app with supertest loading just app.js and leaving bin/www just for when you launch a real server instance.

Related

Parse dashboard error

I successfully installed parse dashboard using the commands on the github repo.
When I try to run it from the command line I get the following error
/usr/local/lib/node_modules/parse-dashboard/Parse-Dashboard/index.js:10
const path = require('path');
^^^^^
SyntaxError: Use of const in strict mode.
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478: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 Object.<anonymous> (/usr/local/lib/node_modules/parse-dashboard/bin/parse-dashboard:2:1)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
Any one have any idea of what is going on here and how I can fix it?

rawmemchr: symbol not found in nodegit with docker

When I run the server in the Docker container, everything works fine until I include the line nodegit = require 'nodegit'. If NodeGit is required, on docker-compose up I get the following error:
Error: Error relocating
/usr/myContainer/node_modules/nodegit/build/Release/nodegit.node:
__rawmemchr: symbol not found
I tried NodeGit v.0.12.1 (the latest version) and v.0.11.0.
Without Docker, NodeGit works fine in the same project.
I am new to Docker and virtual machines generally. Any advice on how to troubleshoot this would really help. Thanks!
Update: here are the logs of my container:
[00:22:03] Requiring external module coffee-script/register
[00:22:04] Using gulpfile /usr/lada/gulpfile.coffee
[00:22:04] Starting 'lada-up'...
[00:22:04] Finished 'lada-up' after 23 ms
livereload[tiny-lr] listening on 35729 ...
Error: Error relocating /usr/lada/node_modules/nodegit/build/Release/nodegit.node: __rawmemchr: symbol not found
at Error (native)
at Object.Module._extensions..node (module.js:440:18)
at Module.load (/usr/lib/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/usr/lada/node_modules/nodegit/lib/nodegit.js:9:12)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (/usr/lib/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/usr/lada/app/post.coffee:1:11)
at Object.<anonymous> (/usr/lada/app/post.coffee:1:1)
at Module._compile (module.js:413:34)
at Object.loadFile (/usr/lib/node_modules/coffee-script/lib/coffee-script/register.js:16:19)
at Module.load (/usr/lib/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/usr/lada/app/index.coffee:8:6)
at Object.<anonymous> (/usr/lada/app/index.coffee:1:1)
at Module._compile (module.js:413:34)
at Object.exports.run (/usr/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:134:23)
at compileScript (/usr/lib/node_modules/coffee-script/lib/coffee-script/command.js:224:29)
at compilePath (/usr/lib/node_modules/coffee-script/lib/coffee-script/command.js:174:14)
at Object.exports.run (/usr/lib/node_modules/coffee-script/lib/coffee-script/command.js:98:20)
at Object.<anonymous> (/usr/lib/node_modules/coffee-script/bin/coffee:7:41)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:142:18)
at node.js:939:3

mathjs DimensionError thown on load

Trying to use the mathjs module for some matrix maths in NodeJS. The require statement seems to throw an exception
var math = require("mathjs");
Exception is:
DimensionError
at Object.<anonymous> (C:\Users\jon_000\workspace\RobotInvKin\node_modules
\mathjs\lib\error\DimensionError.js:30:28)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478: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 Object.<anonymous> (C:\Users\jon_000\workspace\RobotInvKin\node_modules
\mathjs\lib\utils\array.js:8:22)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478: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 Object.<anonymous> (C:\Users\jon_000\workspace\RobotInvKin\node_modules
\mathjs\lib\utils\index.js:3:17)
This must be something simple. Any ideas gratefully received?

NodeJS application start error

When i try to start my app i see the following error. How can i fix it?
Error: Module version mismatch. Expected 11, got 13.
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/okoz/node_modules/xml2json/node_modules/node-expat/lib/node-expat.js:4:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)

Cannot find module './lib/should'

i have a test code and trying to run it
var should = require("should")
describe('Array', function(){
describe('#indexOf()', function(){
it('should return -1 when the value is not present',function(){
[1,2,3].indexOf(5).should.equal(-1);
[1,2,3].indexOf(0).should.equal(-1);
})
})
})
when i run it i am getting error
Error: Cannot find module './lib/should'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/ritesh/projects/passport-topcoder/node_modules/should/index.js:2:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/ritesh/projects/passport-topcoder/test/module.test.js:1:76)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /usr/local/lib/node_modules/mocha/lib/mocha.js:152:27
at Array.forEach (native)
at Mocha.loadFiles (/usr/local/lib/node_modules/mocha/lib/mocha.js:149:14)
at Mocha.run (/usr/local/lib/node_modules/mocha/lib/mocha.js:306:31)
at Object.<anonymous> (/usr/local/lib/node_modules/mocha/bin/_mocha:348:7)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
i included mocha and should in package.json but why i am facing this error .should is showing in my node modules also.please guideline
I faced the same issue, and I think it is because should package has been updated two hours ago (and it may have broken something).
npm install should#1.3.0
did the trick.
EDIT
Version 2.0.1 fixed the issue.
It simply means should from the NPM is not installed. Simply use
sudo npm install should
This means that it should install should from the node package manage.
Hope it makes stuff clearer.
Cheers.

Resources