Add environment variable for duration of Make task
“Task” is not common make terminology. I assume that you mean a rule. If you're using GNU make, you can set a variable for a specific rule, or more precisely, for a specific target.
test-results: export PATH := $(shell npm bin):$$PATH
test-results: test-binary1 test-binary2 test-data2 reference-test-results
test-binary1 >test-results
test-binary2 test-data2 >>test-results
diff test-results reference-test-results
Note that the assignment is in make syntax, which is not the same as shell syntax. And note that when modifying a variable, you must use eager (“expanded”) assignment, not the =
lazy assignment which would create a circular reference.