Skip to content

Commit

Permalink
module: fix NODE_MODULE environment works (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
yorkie committed Aug 8, 2018
1 parent 74ab766 commit 92c2ceb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -31,6 +31,7 @@ cscope.*
# Dependency directories
node_modules/
!tools/node_modules
!test/run_pass/require2/node_modules

# Coverage directory used by tools like istanbul
coverage
Expand Down
3 changes: 2 additions & 1 deletion src/js/iotjs.js
Expand Up @@ -15,6 +15,8 @@

(function() {
this.global = this;
// update the process.env firstly
updateEnviron();

function Module(id) {
this.id = id;
Expand Down Expand Up @@ -517,7 +519,6 @@
process.env[key] = val;
});
}
updateEnviron();

// compatible with stdout
process.stdout = {
Expand Down
4 changes: 4 additions & 0 deletions test/run_pass/require2/node_modules/foobar/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions test/run_pass/test_module_require2.js
@@ -0,0 +1,5 @@
'use strict';

var assert = require('assert');
var foobar = require('foobar');
assert.equal(foobar, 'foobar');
5 changes: 5 additions & 0 deletions test/testsets.json
Expand Up @@ -56,6 +56,11 @@
{ "name": "test_module_cache.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" },
{ "name": "test_module_json.js" },
{ "name": "test_module_require.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" },
{ "name": "test_module_require2.js",
"env": {
"NODE_PATH": "require2"
}
},
{ "name": "test_net_1.js" },
{ "name": "test_net_2.js" },
{ "name": "test_net_3.js", "skip": ["linux", "nuttx"], "reason": "[linux]: flaky on Travis, [nuttx]: requires too many socket descriptors and too large buffers" },
Expand Down
21 changes: 18 additions & 3 deletions tools/testrunner.py
Expand Up @@ -22,6 +22,7 @@
import subprocess
import sys
import time
import os

from collections import OrderedDict
from common_py import path
Expand Down Expand Up @@ -198,7 +199,12 @@ def run_testset(self, testset, tests):

append_coverage_code(testfile, self.coverage)

exitcode, output, runtime = self.run_test(testfile, timeout)
options = {
"root": fs.join(path.TEST_ROOT, testset),
"env": test.get("env"),
"timeout": timeout,
}
exitcode, output, runtime = self.run_test(testfile, options)
expected_failure = test.get("expected-failure", False)

remove_coverage_code(testfile, self.coverage)
Expand All @@ -221,7 +227,9 @@ def run_testset(self, testset, tests):
self.results["fail"] += 1


def run_test(self, testfile, timeout):
def run_test(self, testfile, options):
"run the specify test case"

command = [self.iotjs, testfile]

if self.valgrind:
Expand All @@ -233,12 +241,19 @@ def run_test(self, testfile, timeout):

command = ["valgrind"] + valgrind_options + command

signal.alarm(timeout)
my_env = os.environ.copy()
if options["env"] != None:
for key, val in options["env"].items():
if key == u"NODE_PATH":
my_env[key] = fs.join(options["root"], val)

signal.alarm(options["timeout"])

try:
start = time.time()
process = subprocess.Popen(args=command,
cwd=path.TEST_ROOT,
env=my_env,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)

Expand Down

0 comments on commit 92c2ceb

Please sign in to comment.