1

I am trying to create a MakeFile to run my Mocha unit tests with NPM. So I have Mocha installed and a unit test created in:

{project_root}/test/test.js

Now, when I try 'make test' Make replies with:

make: Nothing to be done for `test'.

Here's my MakeFile:

test:
    @./node_modules/.bin/mocha -u tdd
.PHONY: test

So real basic. I've read that Mocha will run all tests in the 'test' dir automatically. Is my MakeFile syntax incorrect?

Thanks!

Nick
  • 19,198
  • 51
  • 185
  • 312
  • 1
    your command seems to be ok , but you could try this : `make -f MakeFile test` . Also i would put the .Phony line before the test target and check my makefile with the command cat -e -t -v MakeFile --> it shows tabs as ^I and line endings as $ . let me know if it still dosent work – Nitin4873 Jun 01 '13 at 18:31
  • Thanks. make -f did it. I will look up the meaning of that argument. – Nick Jun 01 '13 at 23:01
  • @ Nick , the -f command just says that the name after it is a file .... that it!! – Nitin4873 Jun 02 '13 at 03:59
  • @Nick This is old, but make expects a file called `makefile` or `Makefile`. The uppercase F in `makeFile`/`MakeFile` is what trips this error. Case matters! – Adam Terlson Dec 01 '14 at 19:30

3 Answers3

5

Sorry I can't help with make syntax, but could I suggest instead to just create a test alias in your package.json so that you can run your tests with npm test. Here's a nice example: https://github.com/sequelize/sequelize/blob/master/package.json

Dan Kohn
  • 33,811
  • 9
  • 84
  • 100
  • That's good advice. This would be supported by Windows as well as unix based systems. I'll take a look. – Nick Jun 02 '13 at 02:26
  • Yep... I like it. Ditched the MakeFile and just added "scripts": { "test": "mocha" }, to my package.json. Works great. Less moving parts. – Nick Jun 02 '13 at 02:38
  • I want to have two test commands, eg: testThis, testThat. I don't want a makefile and npm doesn't support it what should i use? – eguneys Jul 15 '14 at 08:38
  • @facebook see http://stackoverflow.com/questions/20376269/how-to-run-mocha-and-mocha-phantomjs-tests-from-one-npm-test-command-in-node-j/20384739#20384739 on how to create multiple test commands, then run with `npm run testThis`. – Dan Kohn Jul 15 '14 at 13:29
  • It's funny that the package.json from sequelize now just calls out to the Makefile :) – Jure Triglav Sep 09 '15 at 12:52
3

Did you try tabs instead of spaces?

test:
  @NODE_ENV=test ./node_modules/.bin/mocha
.PHONY: test

Greetings,

jgatjens
  • 682
  • 1
  • 8
  • 16
2

I suspect this is caused by an improperly named makefile.

Rename your makefile to makefile or Makefile and do not use a capital F.

Adam Terlson
  • 12,610
  • 4
  • 42
  • 63