minkphp / MinkZombieDriver

Zombie.js driver for Mink framework
41 stars 49 forks source link

Using a local Zombie installation #178

Closed rask closed 2 years ago

rask commented 7 years ago

All docs and tutorials tell to install Zombie as such:

$ npm install -g zombie

and then setting $NODE_PATH to /usr/lib/node_modules or similar.

Would it be possible to use a local installation of Zombie without $NODE_PATH? E.g. parse the directory structure to find the nearest node_modules directory and fallback to $NODE_PATH if not Zombie lib is found locally?

I would like to use a local Zombie installation as we're trying to run Zombie+Behat tests in a shared CI environment that is a bit restricted.

stof commented 7 years ago

actually, it is totally possible.

And when using recent versions of the driver, you indeed can omit NODE_PATH when node_modules is a sibling of composer's vendor folder (or of one of its ancestors), as we know have the JS script in the project instead of generating it in the temp folder. Btw, this is exactly what we are doing on Travis.

We should probably update the doc as it is a simpler setup now (but the doc was written at a time where the JS script was still generated in a temp file, making the usage of NODE_PATH required)

aik099 commented 7 years ago

@stof , are you sure, that we have removed temporary server generation code? I saw https://github.com/minkphp/MinkZombieDriver/blob/614cfc8793bd4661b816be0666db7a2a83636ea9/src/NodeJS/Server.php#L467 and it's still doing some str_replace of host port in temporary file.

stof commented 7 years ago

@aik099 see https://github.com/minkphp/MinkZombieDriver/blob/614cfc8793bd4661b816be0666db7a2a83636ea9/src/NodeJS/Server/ZombieServer.php#L54 We still use the generation code when Mink is bundled in a phar (as node cannot access the source file in this case). And the str_replace call is deprecated. It is here for BC with people providing custom script file relying on it (see the deprecation warning).

aik099 commented 7 years ago

Nice.

rask commented 7 years ago

I see, will need to try it out. Thanks. :)

rask commented 7 years ago
  1. Create Behat test When I go to "/"
  2. Install local Zombie using npm install --save-dev zombie@"^4.0" (tried ^5.0 too)
  3. Attempt to run behat
  4. Error:

    Error: Cannot find module 'zombie/node_modules/tough-cookie'

How did you manage to get Zombie running as a local package as this is a reported issue with it? https://github.com/assaf/zombie/issues/955

stof commented 7 years ago

@rask are you using npm 2 or npm 3 ? We might have an issue when using npm 3 which will flatten the node_modules.

rask commented 7 years ago

Yes, npm3 and Yarn on some systems. It seems like a script to run npm install inside the zombie dir is needed or something to make this work.

stof commented 7 years ago

No, we simply made a hacky code which relied on the way npm 2 was working (as npm 3 was not even starting to be developed at this time). We need to fix our code (the workaround in the meantime is to use npm 2)

aik099 commented 7 years ago

We haven't really tried to use local zombie installation. @stof just said, that it might work theoretically.

According to https://github.com/assaf/zombie/issues/955 (link @rask mentioned above) the problem is with tough-cookie package and in it's next release will be fixed.

aik099 commented 7 years ago

No, we simply made a hacky code which relied on the way npm 2 was working (as npm 3 was not even starting to be developed at this time). We need to fix our code (the workaround in the meantime is to use npm 2)

Didn't knew that.

So the npm 3 uses different directory structure for dependencies compared to npm 2? I wonder how it will work if I have packages installed using npm 2 and then upgraded npm to 3?

rask commented 7 years ago

If I remember correctly npm3 just flattens the node_modules directory (instead of nesting multiple node_modules dirs). It may break or not. But if code depends on the npm2 dir structure then the code will break.

stof commented 7 years ago

@aik099 both structures are compatible with the node.js package resolution. Npm 3 changed the way it installed packages to dedupe as much as it can by default (npm 2 had a way to dedupe things too, with a dedicated command). If you upgrade to npm 3 and want to benefit from the deduped structure, the easiest way is to delete your node_modules folder and reinstall everything (and maybe npm3 is smart enough to upgrade the folder, but not sure).

stof commented 7 years ago

@rask better fix: use the dev version of MinkZombieDriver, as we already fixed the issue (but not yet released)

aik099 commented 7 years ago

If I'm not mistaken this is the fix: https://github.com/minkphp/MinkZombieDriver/commit/1153919e853cf5ebd828dae5d4d5b765a94820cd

stof commented 7 years ago

@aik099 exactly

rask commented 7 years ago

@stof using the dev stream worked! Any ideas when the change lands on a release version? :)

stof commented 7 years ago

I will try to make a release this weekend, but I make no promise about it (I don't know how much time I can devote to Mink this weekend)

rask commented 7 years ago

Great, no worries. :+1:

chrisdudley commented 7 years ago

Any chance of a release with this fix in please?

TerjeBr commented 6 years ago

@stof Still no release with this fix?

rbrisita commented 4 years ago

Anyone working on a legacy project will be interested in installing an older version of Zombie.js with:

npm install --save-dev npm-2
node_modules/.bin/npm-2 install --save-dev zombie@4
stof commented 2 years ago

Closing this as 1.5.0 has been released in the meantime