0

I am trying to learn Node test-driven frameworks.

I figured I should include a logging system, but can't seem to get it to work.

yourself@BDD0:~/BDD/simplest$ npm run test-browser

> simplest@1.0.0 test-browser /home/yourself/BDD/simplest
> ./node_modules/karma/bin/karma start

INFO [framework.browserify]: registering rebuild (autoWatch=true)
INFO [karma]: Karma v0.12.28 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 39.0.2171 (Linux)]: Connected on socket p0GQRPZBeIOsd2Uz1e0p with id 97681222
INFO [framework.browserify]: 103086 bytes written (2.52 seconds)
INFO [framework.browserify]: bundle built
Chrome 39.0.2171 (Linux) ERROR
    Uncaught Error: Problem reading log4js config { appenders: [ { type: 'console' } ], replaceConsole: false }. 
    Error was "Cannot find module 'console'" (Error: Cannot find module 'console'
  at s (/tmp/9e6dc093e0e34f105c98657867f51cb8bdd77edf.browserify:1:156)
          :      :
          :      :

I'm hoping someone recognizes the error and can tell me what it means.

The Chrome browser has a console. I have nodejs-console in my dependencies.

Am I trying something that log4js cannot do?

Thanx.

Martin Bramwell
  • 2,003
  • 2
  • 19
  • 35
  • Karma doesn't work on NodeJS code, only browser Javascript. And NodeJS code doesn't work in the browser, so you can't use log4JS in client scripts. – Kyle Hale Dec 04 '14 at 04:23
  • Ok. The declared purpose of browserify is to make Node.js packages work in the browser and it follows that the implicit purpose of karma-browserify is to facilitate testing Node.js packages running in the browser. But according you, in the case of log4js-node it can't be done? You know this for a fact? – Martin Bramwell Dec 05 '14 at 11:57
  • @KyleHale - you should only comment if you know for certain. – Martin Bramwell Dec 10 '14 at 21:07
  • Really? That seems like a good way to not get any real answers around here. But thanks for your constructive criticism. – Kyle Hale Dec 10 '14 at 21:57

1 Answers1

2

Ok I got it to work.

I found it necessary to clone the log4js project and edit log4js.js, in order to add a single line :

 require('./appenders/console');

I have posted a Pull Request for my solution : Force bundling of appenders/console

I have created a little demo that shows it in action : javascript-bdd-baby-steps

Possibly my pull request will be rejected with a description of the correct solution. If so I will update here.

I hope this helps someone somewhere someday.

Update 2015/04/20:

My PR was accepted.

Martin Bramwell
  • 2,003
  • 2
  • 19
  • 35