Question

I want to use api-easy to test my REST app. I have it in the dependences inside the package.json, so when I run npm install it's installed in ./node_modules

I'm trying to add the api-easy to the path like this question.

Since I'm using a Makefile I have this:

test:
    @PATH="./node_modules/api-easy/node_modules/.bin:$PATH"
    @echo $PATH
    vows
    @node ./test/tests.js

Note: api-easy depends on vows

The PATH var in not being updated, when I do the echo it returns me "ATH"(not the value), and then the command vows in not found. How can I set properly the PATH in a Makefile?

Était-ce utile?

La solution

In a make recipe, each command is executed as a separate process, so setting an environment variable in one command will not affect the others. To do what you want, you need to make sure all the related commands run in a single instance of the shell, where environment variables are passed as you would expect:

test:
    @PATH="./node_modules/api-easy/node_modules/.bin:$$PATH"; \
    echo $$PATH; \
    vows; \
    node ./test/tests.js

The trailing backslash tells make to concatenate a line with the one that follows it. Note also that you need to quote $ characters if you want them interpreted by the shell. Hence the $$.

Autres conseils

I think something like this should do it:

export PATH="./node_modules/api-easy/node_modules/.bin:$PATH"

test:
  vows
  @node ./test/tests.js
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top