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

tools: use local or specified $NODE for test-npm #1984

Merged
merged 1 commit into from
Jul 25, 2015

Conversation

Fishrock123
Copy link
Member

See: #1955 (comment)

cc @nodejs/build

@Fishrock123 Fishrock123 added the build Issues and PRs related to build files or the CI. label Jun 15, 2015
@@ -136,7 +136,7 @@ test-debugger: all
$(PYTHON) tools/test.py debugger

test-npm: $(NODE_EXE)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are still correct, right? I'm not too sure how makefile uses this part.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, NODE_EXE is mostly used as build target.

@Fishrock123 Fishrock123 added test Issues and PRs related to the tests. npm Issues and PRs related to the npm client dependency or the npm registry. and removed build Issues and PRs related to build files or the CI. labels Jun 15, 2015
../$NODE_EXE cli.js install --ignore-scripts
../$NODE_EXE cli.js run-script test-all
../$NODE cli.js install --ignore-scripts
../$NODE cli.js run-script test-all
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we changing directory a few lines up? Thinking this should just be $NODE. Guess it depends on how you pass the binary path.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not ./node because at this point we are inside the test-npm directory. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right

@Fishrock123
Copy link
Member Author

@jbergstroem is this lgty?

@jbergstroem
Copy link
Member

I haven't tried it but the change LGTM.

@Fishrock123
Copy link
Member Author

Rebased and updated, tested, can confirm it still works.

Unfortunately npm's tests still require a global node for now. ...unless that can be passed via env variable?


../$NODE cli.js install --ignore-scripts
../$NODE cli.js run-script test-legacy
../$NODE cli.js run-script test
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually on second thought this always used the local node to run cli.js anyways because these are relative links.

Still, I think this PR is better practice given our makefile setup.

@@ -3,11 +3,11 @@
set -e

# always change the working directory to the project's root directory
cd $(dirname $0)/..
cd $(dirname ${BASH_SOURCE[0]})/..
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see: http://stackoverflow.com/a/9107028/1279026 (related comment linked below in the "get absolute path" part).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems zsh doesn't sport this variable unfortunately. There is an alternative, but I'd rather avoid using shell-specific things, if possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, Will revert to using $0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what issue were you trying to solve here exactly? Maybe there's an alternative way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing really, I just saw it was suggested in the stackoverflow, going to revert to using $0

@Fishrock123
Copy link
Member Author

Updated, PTAL.

It now creates a local node link and exports it to the used $PATH, this should run the tests using only the local node binary.

Will also test on my assigned linux machine.


## a hopefully temporary hack to use the local $NODE binary when calling node(1)
# make a link to $NODE as test-npm/node
ln -f $NODE test-npm/node
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be an issue cross-platform.

My OS X ln cannot do relative symlinks (-r), but linux does not appear to like hard links.

@silverwind
Copy link
Contributor

I wonder if we have other bash-specific things in those test-npm scripts. Could be an explanation for the weird issues I was having with test-npm on zsh.

@Fishrock123 Fishrock123 changed the title tools: use local or specified NODE for test-npm tools: use local or specified $NODE for test-npm Jun 19, 2015
@Fishrock123
Copy link
Member Author

PTAL: Updated to remove this bit, which I'll PR separately:

EDIT: on second thought it is kind of useless without the hack, so I'm re-adding it again.

@Fishrock123 Fishrock123 force-pushed the fix-test-npm branch 2 times, most recently from 05516f5 to 1959fd0 Compare June 19, 2015 18:47
popd > /dev/null
# export that link as preferred in the $PATH
export PATH=$PWD:$PATH
##
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I can confirm this works on both OS X and Linux (Ubuntu 15), it just means we have an extra thing to clean up in the project root, as seen at the bottom of this file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this fails on a more recent npm with these errors:

test/tap/lifecycle-path.js ............................ 2/4
  make sure the path is correct
  not ok exit code
    +++ found                                                          
    --- wanted                                                         
    -0                                                                 
    +1                                                                 
    compare: ===
    at:
      file: test/tap/lifecycle-path.js
      line: 55
      column: 7
    stack: |
      test/tap/lifecycle-path.js:55:7
      f (node_modules/once/once.js:17:25)
      ChildProcess.<anonymous> (test/common-tap.js:56:5)
      maybeClose (internal/child_process.js:764:16)
      Socket.<anonymous> (internal/child_process.js:319:11)
      Pipe._onclose (net.js:467:12)

  make sure the path is correct
  not ok should be equivalent
    +++ found                                                          
    --- wanted                                                         
     [                                                                 
    -  "{{ROOT}}/bin/node-gyp-bin"                                     
    -  "{{ROOT}}/test/tap/lifecycle-path/node_modules/.bin"            
    -  "/bin"                                                          
    -  "/usr/bin"                                                      
    +  "> ./node-bin/node print-path.js"                               
     ]                                                                 
    at:
      file: test/tap/lifecycle-path.js
      line: 74
      column: 7
    stack: |
      test/tap/lifecycle-path.js:74:7
      f (node_modules/once/once.js:17:25)
      ChildProcess.<anonymous> (test/common-tap.js:56:5)
      maybeClose (internal/child_process.js:764:16)
      Socket.<anonymous> (internal/child_process.js:319:11)
      Pipe._onclose (net.js:467:12)

From this test: https://github.com/npm/npm/blob/master/test/tap/lifecycle-path.js

@othiym23 is this worth the effort to hack this in before npm's tests work without a global node? It seems like this test is relying on the location of the node binary, is that something that can / should be fixed?

@Fishrock123
Copy link
Member Author

@silverwind / @jbergstroem ptal again. :)

@Fishrock123
Copy link
Member Author

Anyone able to review? :D

@evanlucas
Copy link
Contributor

Hmm, getting some failures...not sure if it is related to the most recent changes you made or not though...

https://cloudup.com/cmC7mdzkL4x

@Fishrock123
Copy link
Member Author

@evanlucas what OS? Those look like npm failures. If my script is broken on your system the tests will almost certainly fail to run. :P

@evanlucas
Copy link
Contributor

Yosemite. Haven't tried running them standalone yet though

@Fishrock123
Copy link
Member Author

Uh oh, the same two tests are failing for me now when rebased on master, but only with this patch? How is that possible... I'll have to investigate.

Edit: must have something to do with setting the $PATH.

@Fishrock123 Fishrock123 self-assigned this Jul 1, 2015
PWD=`pwd -P`
popd > /dev/null
# export that link as preferred in the $PATH
export PATH=$PWD:$PATH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original PATH should be restored after the test run? (Maybe through saving it to a temp var)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@silverwind you mean after the legacy tests? I could try that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean having PATH=$PWD:$PATH will prepend the directory on each run of test-npm.sh, resulting in PATH getting longer and longer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, nope. It appears the tests themselves depend on a global node (from the tap module, I think?)

Since running the test requires it, and causes it to fail, that's not a possibility.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure you understand what I mean. My issue is with the global shell's PATH being in an modified state after this script finishes executing (global node now pointing to the built one), and I think we should restore PATH after this script is done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just removing the export is sufficient so all child scripts get the correct binary and we avoid touching the global PATH.

@Fishrock123
Copy link
Member Author

Updated to remove the $PATH hack. I'll try working on it separately. PTAL please, would like to land this haha.

@silverwind
Copy link
Contributor

Looks pretty straightforward now. LGTM

@jbergstroem
Copy link
Member

LGTM

PR-URL: nodejs#1984
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Roman Reiss <me@silverwind.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
npm Issues and PRs related to the npm client dependency or the npm registry. test Issues and PRs related to the tests. tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants