kobenguyent / codeceptjs-rphelper

4 stars 23 forks source link

CodeceptJS should be a peer dependency #13

Closed LittleColin closed 4 years ago

LittleColin commented 4 years ago

Symptom: no results are uploaded and the log for "The launchId is started." is never shown because this event.all.before is never raised.

Cause summary: codeceptjs-rshelper gets its own separate copy of codeceptjs in some (TBD) circumstances. Check for folder: ./node_modules/codeceptjs-rphelper/node_modules/codeceptjs

Solution: In package.json, codeceptjs should be a peer dependency as per: https://nodejs.org/ru/blog/npm/peer-dependencies/#using-peer-dependencies

Workaround If you are getting the symptom and want to verify the solution, simply remove ./node_modules/codeceptjs-rphelper/node_modules/codeceptjs

More detail The reason for this is that unless the test project uses exactly the same pattern to match codeceptjs, npm will install a copy of codeceptjs under codeceptjs-rphelper/node_modules. Also (and I haven't figured out why) but it seems to depend on OS (guess) as npm is same version on two separate docker containers but even if the version matches - npm may still install a separate copy of codeceptjs.

Why does this matter? CodeceptJS maintains its own dispatcher/EventEmitter instance for events like global.before (event.all.before): https://github.com/Codeception/CodeceptJS/blob/master/lib/event.js#L3

Having two separate copies of CodeceptJS means two separate dispatchers and this means the event event.all.before that codeceptjs-rshelper subscribes to is never fired.

kobenguyent commented 4 years ago

@LittleColin thanks for your time to investigate the issue. Initially, I just want to install codeceptjs lib to run unit tests and never image that issue may happen :D. I fixed this in latest version https://github.com/PeterNgTr/codeceptjs-rphelper/blob/master/package.json#L44. Hope it solve issue.

LittleColin commented 4 years ago

Thanks for jumping on this so quickly (and for developing the library in the first place!). Unfortunately the fix wasn't quite enough. I just tried it, version 2.0.3 was downloaded but so was conceptjs again because it's still listed under "dependencies". https://github.com/PeterNgTr/codeceptjs-rphelper/blob/master/package.json#L24

kobenguyent commented 4 years ago

@LittleColin sorry, that's my bad in package.json, to run my tests, I execute the npm i which I defined in that package.json to install codeceptjs and it added that again in dependencies eventhought it had been removed. Pushed a fix on that. :)

LittleColin commented 4 years ago

No problem - 2.0.4 fixed it - thanks very much