Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: missing expected exception in parallel/test-require-deps-deprecation.js #17148

Closed
Tiriel opened this issue Nov 20, 2017 · 16 comments
Closed
Labels
module Issues and PRs related to the module subsystem. test Issues and PRs related to the tests.

Comments

@Tiriel
Copy link
Contributor

Tiriel commented Nov 20, 2017

  • Version: nodejs/node:master
  • Platform: Linux 4.10.0-38-generic rename node.js -> io.js #42~16.04.1-Ubuntu SMP Tue Oct 10 16:32:20 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: test

Hey there!

Got this error when running tests on master:

$make test-parallel
[...]
/usr/bin/python2.7 tools/test.py --mode=release parallel -J
=== release test-require-deps-deprecation ===                                  
Path: parallel/test-require-deps-deprecation
assert.js:42
  throw new errors.AssertionError({
  ^

AssertionError [ERR_ASSERTION]: Missing expected exception.
    at innerThrows (assert.js:186:7)
    at Function.throws (assert.js:205:3)
    at Object.<anonymous> (/home/benjamin/Dev/javascript/NodeFoundation/node/test/parallel/test-require-deps-deprecation.js:43:10)
    at Module._compile (module.js:644:30)
    at Object.Module._extensions..js (module.js:655:10)
    at Module.load (module.js:563:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:685:10)
    at startup (bootstrap_node.js:192:16)
Command: out/Release/node /home/benjamin/Dev/javascript/NodeFoundation/node/test/parallel/test-require-deps-deprecation.js
[00:51|% 100|+ 1719|-   1]: Done                                               
Makefile:242 : la recette pour la cible « test-parallel » a échouée
make: *** [test-parallel] Erreur 1

If I'm corect this was added some three days ago in this commit 7ce6d23 but I have no idea why that doesn't throws, when the patch was specifically designed to make this kind of require throw.

Is it only me?

For the record, I thought I had done some breaking changes without wanting it, so I erase my copy and re cloned it, fetched the last updates and then ran ./configure and make. Build is as fresh as it can get.

@mscdex mscdex added module Issues and PRs related to the module subsystem. test Issues and PRs related to the tests. labels Nov 20, 2017
@Trott
Copy link
Member

Trott commented Nov 21, 2017

@Tiriel What's the output if you run this?:

./node test/parallel/test-require-deps-deprecation.js

@Trott
Copy link
Member

Trott commented Nov 21, 2017

@Tiriel Also, what's the output of each of these two commands?:

./node -e "require('acorn/dist/acorn')"
./node -e "require('acorn/dist/walk')"

@Tiriel
Copy link
Contributor Author

Tiriel commented Nov 21, 2017

Hey @Trott , Thanks!

  • test only :
$ ./node test/parallel/test-require-deps-deprecation.js
assert.js:42
  throw new errors.AssertionError({
  ^

AssertionError [ERR_ASSERTION]: Missing expected exception.
    at innerThrows (assert.js:186:7)
    at Function.throws (assert.js:205:3)
    at Object.<anonymous> (/home/benjamin/Dev/javascript/NodeFoundation/node/test/parallel/test-require-deps-deprecation.js:43:10)
    at Module._compile (module.js:644:30)
    at Object.Module._extensions..js (module.js:655:10)
    at Module.load (module.js:563:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:685:10)
    at startup (bootstrap_node.js:192:16)
  • require('acorn/dist/acorn') :
    no output
  • require('acorn/dist/walk') :
    no output
  • Just to be sure, require('acorn/dist/foo') :
module.js:547
    throw err;
    ^

Error: Cannot find module 'acorn/dist/foo'
    at Function.Module._resolveFilename (module.js:545:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:588:17)
    at require (internal/module.js:11:18)
    at [eval]:1:1
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at Object.runInThisContext (vm.js:152:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:644:30)
    at evalScript (bootstrap_node.js:471:27)

@Trott
Copy link
Member

Trott commented Nov 21, 2017

require('acorn/dist/acorn) and require('acorn/dist/walk') should throw like require('acorn/dist/foo') does. Maybe you have acorn tucked away somewhere that require() is finding it? You don't have NODE_PATH environment variable set by any chance, do you?

@Tiriel
Copy link
Contributor Author

Tiriel commented Nov 21, 2017

Damn, you got it. Sorry I missed this.
NODE_PATH is indeed defined, though I don't know how to solve this simply. Anyway, not a global issue then, I'll close this.

Thanks!

@Tiriel Tiriel closed this as completed Nov 21, 2017
@Trott
Copy link
Member

Trott commented Nov 21, 2017

@Tiriel It's conceivable that a sensible solution is to PR in a change to Makefile/vcbuild.bat or test.py that unsets NODE_PATH. I'm not 100% sure about that--perhaps there's something in CI that needs NODE_PATH but I don't think so.

@Tiriel
Copy link
Contributor Author

Tiriel commented Nov 21, 2017

@Trott But it would then need to be re set afterwards right? I'm not really good at sysadmin, but can it be unset temporarily?

@Trott
Copy link
Member

Trott commented Nov 21, 2017

@Trott But it would then need to be re set afterwards right? I'm not really good at sysadmin, but can it be unset temporarily?

You can unset it for the subprocess only. It won't affect the invoking shell.

$ NODE_PATH='foo' ./node -e 'console.log(process.env.NODE_PATH)'
foo
$ echo $NODE_PATH

$

@Tiriel
Copy link
Contributor Author

Tiriel commented Nov 21, 2017

@Trott Awesome, thanks! And sorry for being such a weight ^^'

@Tiriel
Copy link
Contributor Author

Tiriel commented Nov 22, 2017

I'll just reopen this since it seems there may be a solution and a fix that would solve the problem for people potentially having it like me.

Right now I'm investigatin the problem, but prefixing the commands in the Makefile hasn't improved the situation yet. I think because the Python is launching the tests by executing commands, and so the temporary assignment is lost. 4ill try and dig inside test.py just to be sure. Also tried adding process.env.NODE_PATH = ''; at the top of the js test, but no joy.

If anyone as another idea, they're deeply welcome to share!

@Tiriel Tiriel reopened this Nov 22, 2017
@Trott
Copy link
Member

Trott commented Nov 23, 2017

@Tiriel There's already code in test.py to remove NODE_PATH from the environment before exectuing tests:

  # Remove NODE_PATH
  if "NODE_PATH" in env_copy:
    del env_copy["NODE_PATH"]

Perhaps the root cause of the problem is something else. Maybe check for the other things listed in https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders that confound module loading:

1: $HOME/.node_modules
2: $HOME/.node_libraries
3: $PREFIX/lib/node

(I think $PREFIX will be the value of prefix_node in config.gypi.)

@richardlau
Copy link
Member

You can also set NODE_DEBUG=module environment variable to see where Node.js is looking to load modules from.

@Tiriel
Copy link
Contributor Author

Tiriel commented Nov 23, 2017

Awesome thanks both of you! I'll check into it ASAP

@Tiriel
Copy link
Contributor Author

Tiriel commented Dec 22, 2017

Okay, this was a long time ago, but I finally had the time to put some more tests to it.

Simply checked require.resolve('acorn/dist/acorn')) in test-require-deps-deprecation.js. It appears it's loaded from $HOME/node_modules (without the dot).
To be a bit more specific, require.resolve.paths('/acorn/dist/acorn') indicates that it finds acorn simply by iterating up through my folder structure, searching for a node_module folder at every depth until it finds one. Which is precisely it's usual workflow if I'm not mistaken.

But I must admit I'm note sure which path to follow from now on. I'm searching for a way to limit the upward iterating to a certain number of levels, at least locally in this test file, but it seems weird.

Any intake, or should I just drop it and ignore this test failing when building Node?

@Trott
Copy link
Member

Trott commented Dec 22, 2017

@Tiriel I propose this: Change the require() in the test to be require.resolve(). If it throws, the test passes. If it returns a string other than acorn/dist/acorn, then it passes. If it returns exactly acorn/dist/acorn, then it fails.

I'm happy to put that together as a PR, but would be even happier to see you do it. Let me know. :-D

@Tiriel
Copy link
Contributor Author

Tiriel commented Dec 23, 2017

@Trott awesome thanks !

I’ll open a PR later today !

Tiriel added a commit to Tiriel/node that referenced this issue Dec 25, 2017
Test test-require-deps-deprecation.js was failing when user already had node
installed with acorn in require.resolve range.
Modified test to acknowledge the possibility and throw only if acorn is
found in the deps directory.

Fixes: nodejs#17148
Refs: nodejs#17148 (comment)
Tiriel added a commit to Tiriel/node that referenced this issue Dec 27, 2017
Fix following review.
Reinstated assertion on error message, and corrected comment.
Leaving continu to break loop and avoid unneeded assertions.

Fixes: nodejs#17148
Refs: nodejs#17148 (comment)
Tiriel added a commit to Tiriel/node that referenced this issue Jan 10, 2018
Test test-require-deps-deprecation.js was failing when user already had
node installed with acorn in require.resolve range.

Modified test to acknowledge the possibility and throw only if acorn is
found in the deps directory.

Also changed the deprecation test for v9.x: common.expectWarning was failing
because the required deps now throw ReferenceErrors when not properly called
internally in the right order.

PR-URL: nodejs#17848
Fixes: nodejs#17148
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Tiriel added a commit to Tiriel/node that referenced this issue Jan 11, 2018
MylesBorins pushed a commit that referenced this issue Feb 20, 2018
Test test-require-deps-deprecation.js was failing when user already had
node installed with acorn in require.resolve range.

Modified test to acknowledge the possibility and throw only if acorn is
found in the deps directory.

Also changed the deprecation test for v9.x: common.expectWarning was failing
because the required deps now throw ReferenceErrors when not properly called
internally in the right order.

Bacport-PR-URL: #18077
PR-URL: #17848
Fixes: #17148
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module Issues and PRs related to the module subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants