Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
489 views
in Technique[技术] by (71.8m points)

node.js - Mocha requires make. Can't find a make.exe that works on Windows

Mocha (test framework for Node.js) uses make.

For the life of me I can't find a compatible make.exe for Windows.

Everything works fine on my Mac.

I've tried using VS's nmake.exe and a make.exe I found that was ported from Unix. But they are all incompatible.

It can't just be me

Here's the makefile:

test:
    @./node_modules/.bin/mocha -u tdd -R spec

.PHONY: test

make barfs on the . in PHONY, and even if I remove it, it never runs the mocha command (or at least there's no output).

Running ./node_modules/.bin/mocha -u -tdd -R spec directly gives me my test report:

first suite -
  ? ten should always be equal to 9+1
  ? zero is less all positive numbers
  ? There is no i in team

 ? 3 tests complete (8ms)

EDIT 3/25/12

  • In the end, the easiest way to deal with this is to use Cygwin and ensure that the developer packages for Cygwin are installed. In PowerShell I did Set-Alias make "c:devutilscygwininmake.exe" and now make test works on standard Mocha Makefiles.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Heh I feel you ;) I'm part of a team busy building a new startup using node. Two of our dev's are on on OSX, one is on Linux. I am on Windows.

I downloaded and use GNU's "Make for Windows" and can now quite happily make our installation & test suites.

Also, I STRONGLY encourage you to use PowerShell - it has a bunch of commands aliased to UNIX-friendly commands (e.g. Get-ChildItem -> ls). This allows several of our scripts to work on UNIX or Windows without change.

So, to your issue:

Try replacing your makefile above with the following:

# Detect if we're running Windows
ifdef SystemRoot
    # If so, set the file & folder deletion commands:
    FixPath = $(subst /,,$1)
else
    # Otherwise, assume we're running *N*X:
    FixPath = $1
endif

NODE_MODULES := ./node_modules/.bin/

test: 
    $(call FixPath, NODE_MODULES)mocha -u tdd -R spec

.PHONY: test

Note: with Makefiles, tasks within targets must be indented with tab characters, not spaces! Go figure!!

I stole the FixPath routine from this post (thanks Paul :)). It replaces a string's / with if run on Windows.

One of the problems with make on Windows is that it shells out to NT's command shell (via CreateProcess) in order to execute each task. This means that any NX-isms that Powershell would otherwise handle (e.g. ls, cat, etc.) won't work when executing makefiles. Thus, its advisable to replace inline commands with overridable aliases that you can set to one command for NT and another for NX.

Perhaps I'll get around to forking Gnu Make and seeing if I can get it to shell out to Powershell when executing commands instead of the NT command line. That would also eliminate the need for FixPaths above ;)

Ping me if you get stuck ;)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...