NickTomlin / protractor-flake

Rerun potentially flakey protractor tests before failing.
MIT License
80 stars 51 forks source link

Easier way to specify path of custom parser #85

Closed epgremill3 closed 6 years ago

epgremill3 commented 6 years ago

Hello, I just started using protractor-flake today and I'm really liking it so far - thanks!

There's one thing I've run into that I had to work around - the custom parser path seems to use require.resolve which seems to use __dirname or equivalent to look for the file. However, I've installed protractor and protractor-flake globally, so I'm running my tests from a different directory than where protractor-flake is installed.

I did some quick tests tweaking the source and in parsers/index.js handlePath function if I do something like:

var path = require('path');
var calledFrom = path.resolve('./');
var myCustomParserPath = calledFrom + parserPath;
return require(myCustomParserPath);

Then it works for me. Maybe you could nest that (or some nicer equivalent) in the catch block to support relative paths from the calling directory?

Alternatively, maybe there's a better way for me to achieve this? For now I'm specifying my custom parser path on the command line with %CD%\subdirectory\parser.js which works due to expansion before being passed in...

Thanks for considering and keep up the good work.

C:\nvm\v8.9.4\node_modules\protractor-flake\dist\parsers\index.js:38
    throw new Error('Invalid Custom Parser Path Specified: ' + parserPath);
    ^

Error: Invalid Custom Parser Path Specified: helpers\parser.js
    at handlePath (C:\nvm\v8.9.4\node_modules\protractor-flake\dist\parsers\index.js:38:11)
    at getParser (C:\nvm\v8.9.4\node_modules\protractor-flake\dist\parsers\index.js:58:12)
    at exports.default (C:\nvm\v8.9.4\node_modules\protractor-flake\dist\index.js:42:39)
    at Object.<anonymous> (C:\nvm\v8.9.4\node_modules\protractor-flake\bin\protractor-flake:17:1)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
NickTomlin commented 6 years ago

Ah yep this looks like a bug. Thanks for reporting! I'm not on windows but I can replicate on OSX with a relative path.

I'll try to get a fix out tomorrow but it may take until next week. Feel free to submit a PR if you have a fix of your own!

NickTomlin commented 6 years ago

I have a potential fix for this in https://github.com/NickTomlin/protractor-flake/commit/874a08eb2f10aeb24ccf94495e97f67f88ae58ea would you mind trying that out? I don't have a windows machine so there could be something that doesn't work there.

Thanks!

epgremill3 commented 6 years ago

Gladly! I'll try to get to it this weekend. If not, then on Monday for sure. I'll report back as soon as I've tried it. Thanks!

epgremill3 commented 6 years ago

All right - I tested and can confirm that all of the following work:

I think it looks good - thanks!

NickTomlin commented 6 years ago

This has been published to NPM as 3.0.2. Thanks for reporting the issue!