Be able to merge interactions into one pact file.
Only one interaction (the last ran test) get written out. The existing pact file is overwritten when the "pactfileWriteMode: 'merge'" option is specified. The log from the mock integration server has the following line:
I, [2018-02-15T16:34:37.887577 #37412] INFO -- : Merging interactions into pact for MyProvider at C:\nav\pus\pact-js\examples\mocha\pacts/myconsumer-myprovider.json
W, [2018-02-15T16:34:37.887577 #37412] WARN -- : Could not load existing consumer contract from C:\nav\pus\pact-js\examples\mocha\pacts/myconsumer-myprovider.json due to bad URI(is not URI?): C:\nav\pus\pact-js\examples\mocha\pacts/myconsumer-myprovider.json. Creating a new file.
Notice the forward slash: _\mocha\pacts/myconsumer-myprovider.json_
This error message is thrown in consumer_contract_writer.rb in Ruby-gem pact-mock_service-2.6.3, on line 92. The pactfile_path variable seems to be set wrong somewhere. Trying to manually replace the illegal back slashes didnt work either: dir: path.resolve(process.cwd(), 'pacts').replace(/\\/g, "/"). I find uses of path.normalize in pact-node/src/server.js which could be the reason why pact-mock_service get a filepath with Windows-style back slashes.
Path to gem:
node_modules/@pact-foundation/pact-standalone/platforms/win32/lib/vendor/ruby/2.2.0/gems/pact-mock_service-2.6.3/lib/pact/consumer_contract
It's important to note that everything works fine on Mac OS and Linux. This problem occurs only on Windows.
Run the mocha example on Windows. I have upgraded the example to PactJS version 5.3.0. Unzip and run the example to reproduce. The same log statement should then be in the mockserver-integration.log. I have ran and attached the same file here.
The reproduced mockserver log:
mockserver-integration.log
What happens when you specify the path to the pact dir with forward slashes?
I tried "/pacts" which resulted in a correctly merged file, but the file get created in C:\pacts instead of the current working directory. Every other type of path fails, even when I replace \ with / using regex. path.normalize is the only call I find in Pact.js that is converting the string to a Windows-style absolute path. Without being able to confirm this theory, it looks like my file path is first converted to an absolute Windows-style path and then in the RubyGem "/myconsumer-myprovider.json" is added to complete the path. That all together fails in Ruby when trying to create an URI.
What if the path is "./pacts"?
There may be some JavaScript logic in there modifying the path before it is passed to ruby.
As you rightly theorised...
I will try "./pacts" as soon as I get to back to the Windows terminal in my office in the morning. Everything works fine on my Mac though.
I've put out a new version of the standalone, with code to replace backslashes with forward slashes when constructing the pact path. @mefellows can you update to 1.29.1 of the standalone when you have a moment?
@bethesque Thank you very much for your quick response! Btw: running the code with "./pacts" did'nt work.
@dervism v5.5.1 is out the door with this fix, can you please let us know how you go?
@mefellows I am retesting again. Will let you know.
Bugger. If you were interested, there is a branch set aside to create an appveyor build for Pact.
It needs some work but would very much appreciate any Windows testing.
@mefellows I get permission denied (might be something on my side):
I, [2018-02-20T12:44:21.613472 #10952] INFO -- : Verifying - interactions matched
I, [2018-02-20T12:44:21.629097 #10952] INFO -- : Cleared interactions
I, [2018-02-20T12:44:21.643740 #10952] INFO -- : Merging interactions into pact for MyProI, [2018-02-20T12:44:21.643740 #10132] INFO -- : Merging interactions into pW, [2018-02-20T12:44:21.652529 #10952] WARN -- : Could not load existing consumer contract from C:/nav/pus/pact-js/examples/mocha/pacts/myconsumer-myprovider.json due to Permission denied @ io_fread - c:/nav/pus/pact-js/examples/mocha/pacts/myconsumer-myprovider.json. Creating a new file.
E, [2018-02-20T12:44:21.653506 #10952] ERROR -- : Permission denied @ io_fread - c:/nav/pus/pact-js/examples/mocha/pacts/myconsumer-myprovider.json (Errno::EACCES)
Thanks @dervism. Does c:/nav/pus/pact-js/examples/mocha/pacts/ exist? Perhaps it hasn't/can't create the directory so that it can create the pact file.
@mefellows Yes the directory exist and the initial file is being created. Problem seems to happen every time the RubyGem tries to do a File.read - when that fails it overwrites the existing file with the last pact test that was ran.
There is already an appveyor build to test the standalone package. We
shouldn't really need the js to reproduce this (unless it is an artifact
of something in the js). I'll modify the test to exercise the merge
feature.
The good news is, I've reproduced it! https://ci.appveyor.com/project/MichelBoudreau/pact-ruby-standalone-windows-test/build/1.0.95#L85
Now to see if we can fix it.
I wish there was some way to _not_ automatically close an issue when you referenced it with the "fix:" notation!
Ok, I have a passing windows build with v 1.29.2 of the ruby standalone. Update at will.
On a side note Matt, I worked out how to lock and write to the same file on Windows, so there's no OS specific code. For great victory!
Amazing work Beth. I'll see to upgrading shortly... time to get on the module release merry-go-round :)
Ok have released the latest, let us know how you go @dervism
It works :-) Thank you so much for the great work! 馃憤
馃帀
Beth 1, Windows... um... I've lost count.