Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pact.js fails to merge interactions to one file #150

Closed
dervism opened this issue Feb 15, 2018 · 22 comments
Closed

Pact.js fails to merge interactions to one file #150

dervism opened this issue Feb 15, 2018 · 22 comments

Comments

@dervism
Copy link

dervism commented Feb 15, 2018

Software versions

  • OS: Windows 10
  • Consumer Pact library: Pact JS v5.3.0 and v5.5.0
  • Provider Pact library: Not relevant
  • Node Version: Node 8.9.3

Expected behaviour

Be able to merge interactions into one pact file.

Actual behaviour

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.

Steps to reproduce

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.

  1. Unzip mocha.zip (contains the upgraded example)
  2. npm install
  3. npm run test

Relevant log files

The reproduced mockserver log:
mockserver-integration.log

@dervism dervism changed the title Pact.js fails to merge interaction to one file Pact.js fails to merge interactions to one file Feb 15, 2018
@bethesque
Copy link
Member

What happens when you specify the path to the pact dir with forward slashes?

@dervism
Copy link
Author

dervism commented Feb 15, 2018

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.

@bethesque
Copy link
Member

What if the path is "./pacts"?

@bethesque
Copy link
Member

There may be some JavaScript logic in there modifying the path before it is passed to ruby.

@bethesque
Copy link
Member

As you rightly theorised...

@dervism
Copy link
Author

dervism commented Feb 15, 2018

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.

@bethesque
Copy link
Member

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 bethesque reopened this Feb 16, 2018
bethesque added a commit to pact-foundation/pact-ruby-standalone-windows-test that referenced this issue Feb 16, 2018
@dervism
Copy link
Author

dervism commented Feb 16, 2018

@bethesque Thank you very much for your quick response! Btw: running the code with "./pacts" did'nt work.

@mefellows
Copy link
Member

@dervism v5.5.1 is out the door with this fix, can you please let us know how you go?

@dervism
Copy link
Author

dervism commented Feb 20, 2018

@mefellows I am retesting again. Will let you know.

@mefellows
Copy link
Member

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.

@dervism
Copy link
Author

dervism commented Feb 20, 2018

@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)

mockserver-integration.log

@mefellows
Copy link
Member

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.

@dervism
Copy link
Author

dervism commented Feb 21, 2018

@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.

@bethesque
Copy link
Member

bethesque commented Feb 21, 2018 via email

@bethesque
Copy link
Member

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.

@bethesque
Copy link
Member

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!

@mefellows
Copy link
Member

Amazing work Beth. I'll see to upgrading shortly... time to get on the module release merry-go-round :)

@mefellows
Copy link
Member

Ok have released the latest, let us know how you go @dervism

@dervism
Copy link
Author

dervism commented Feb 22, 2018

It works :-) Thank you so much for the great work! 👍

@mefellows
Copy link
Member

mefellows commented Feb 22, 2018 via email

@bethesque
Copy link
Member

Beth 1, Windows... um... I've lost count.

blackbaud-joshlandi pushed a commit to blackbaud-joshlandi/pact-js that referenced this issue Mar 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants