Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

use node-gyp correctly in the tests#898

Merged
darangi merged 6 commits intoatom:masterfrom
atom-community:test-node-gyp-4upstream
Oct 15, 2020
Merged

use node-gyp correctly in the tests#898
darangi merged 6 commits intoatom:masterfrom
atom-community:test-node-gyp-4upstream

Conversation

@aminya
Copy link
Copy Markdown
Contributor

@aminya aminya commented Aug 23, 2020

Description of the change

This uses npm's built-in node-gyp which is used in the tests. The tests assume that node-gyp should exist in node_modules, but this is an assumption about the test environment which may not be true. npm does not hoist node-gyp which is a dependency of the npm to the top-level node-modules in the newer versions. It adds node-gyp to devDependencies just for install-spec test.

nodeModules = fs.realpathSync(path.join(__dirname, '..', 'node_modules'))
beforeEach ->
# Normally npm_config_node_gyp would be ignored, but it works here because we're calling apm
# directly and not through the scripts in bin/
fs.copySync path.join(nodeModules, 'node-gyp'), path.join(nodeModules, 'with a space')

Verification

The tests now pass correctly. This is tested on Atom too: atom-community/atom#103

Drawbacks

none

Release Notes

N/A

Closes #10

@aminya aminya changed the title test: use npm's built-in node-gyp in the tests use node-gyp correctly in the tests Aug 23, 2020
@aminya aminya mentioned this pull request Aug 23, 2020
@DeeDeeG

This comment has been minimized.

@aminya
Copy link
Copy Markdown
Contributor Author

aminya commented Sep 4, 2020

For what it's worth, the require.resolve('node-gyp') workaround is all that should be needed here, IMO.

That's not correct. Using a newer npm (#900) changes the location of node-gyp which results in the test failure.

@DeeDeeG

This comment has been minimized.

@aminya
Copy link
Copy Markdown
Contributor Author

aminya commented Sep 4, 2020

also passes CI. 6226314

This is with the old npm.

I have already tested this: atom-community#10 (comment)

We need to install node-gyp for testing apm on the newer npm versions. There is no way around this, and we should not rely on the hoisting algorithm.

@DeeDeeG
Copy link
Copy Markdown
Contributor

DeeDeeG commented Sep 4, 2020

I see you are right. Sorry for the misunderstanding.

@DeeDeeG

This comment has been minimized.

@aminya
Copy link
Copy Markdown
Contributor Author

aminya commented Sep 5, 2020

I don't understand what you are trying to achieve. I just added a devDependency which is only used in the tests. This does not affect Atom or anything. This machine-generated package-lock.json does not change by running npm install.

@DeeDeeG

This comment has been minimized.

@aminya
Copy link
Copy Markdown
Contributor Author

aminya commented Sep 5, 2020

The point of this PR is to not rely on npm's hoisting algorithm and package-lock.json which are susceptible to change. Updating package-lock.json with a different command is not sustainable and is a very fragile approach.

If a certain version of node-gyp needs to be a devDependency it should be declared in package.json. I added version 5 just in case Atom's build scripts rely on this fragile behavior.

@DeeDeeG
Copy link
Copy Markdown
Contributor

DeeDeeG commented Sep 5, 2020

That works. Thanks for addressing it. This look good to me now.

@darangi
Copy link
Copy Markdown
Contributor

darangi commented Oct 15, 2020

Thanks 🙇🏾‍♂️ @aminya

@darangi darangi merged commit d06e047 into atom:master Oct 15, 2020
@aminya
Copy link
Copy Markdown
Contributor Author

aminya commented Oct 15, 2020

You're welcome!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants