pact-foundation / pact-js

JS version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
https://pact.io
Other
1.63k stars 347 forks source link

example karma-pact not working with new versions of pact modules #196

Closed kaparna91 closed 6 years ago

kaparna91 commented 6 years ago

Software versions

Expected behaviour

I am working on a exemplar project that uses karma ,grunt . When I try updating it with new versions of pact the test cases are failing . It used to work with old pact modules and I have changed the client-spec.js file to support new pact modules. old pact moduels : "pact": "4.3.2", "@pact-foundation/pact-node": "6.7.4", "@pact-foundation/karma-pact": "2.1.3", new pact modules: "@pact-foundation/karma-pact": "^2.1.5", "@pact-foundation/pact": "^5.9.1", "@pact-foundation/pact-node": "^6.13.0",

Steps to reproduce

I am using below project as my reference https://github.com/pact-foundation/pact-js/tree/master/karma/jasmine

mefellows commented 6 years ago

So what's not working exactly? The example code you provided is tested with every build so we know that works.

Please provide a reproducible project for us.

kaparna91 commented 6 years ago

Test cases are failing after updating project with new pact modules.

mefellows commented 6 years ago

That's not very helpful for us. Please read https://coderanch.com/wiki/659862/Show-Effort so you can help us help you.

mefellows commented 6 years ago

FYI we run the jasmine and mocha karma examples as part of every commit - the tests are currently green (e.g. https://travis-ci.org/pact-foundation/pact-js/jobs/392460714#L3909-L3964)

I'm going to close this issue until evidence of an issue is demonstrated. Will happily investigate then.

kaparna91 commented 6 years ago

I have uploaded a repro code for you to play with and to replicate the issue that I am having while using new pact modules. Here is the repo code for the same https://github.com/kaparna91/pact-js.git

mefellows commented 6 years ago

Thanks @kaparna91, can you please provide instructions for running the examples? I've tried running karma start test/karma.config.js but it fails with a bunch of errors (doesn't match files, for example).

Also, if you could please provide logs/evidence of the problem that would certainly assist.

kaparna91 commented 6 years ago

Hi @mefellows Once the grunt tasks are loaded if we run test- pact it should able to run the test cases. But In my project pact exits with code 1 ,this behavior is seen after I updated the project with new pact node modules. Below are the attached error logs

13 08 2018 12:09:02.891:ERROR [plugin]: Error during loading "C:\devl\demo-dojo.webapp\node_modules/karma-phantomjs-launcher" plugin:
  Path must be a string. Received null
13 08 2018 12:09:05.933:INFO [framework.browserify]: registering rebuild (autoWatch=true)
[2018-08-13T16:09:05.950Z]  INFO: pact-node@6.13.0/368540 on MYWINDOWS: 
    Creating Pact Server with options: 
    port = 1234,
    consumer = KarmaJasmineConsumer,
    provider = KarmaJasmineProvider,
    logLevel = DEBUG,
    log = C:\devl\demo-dojo.webapp\logs\pact.log,
    dir = C:\devl\demo-dojo.webapp\pacts,
    pactFileWriteMode = overwrite,
    ssl = false,
    cors = false,
    host = localhost
[2018-08-13T16:09:05.980Z]  INFO: pact-node@6.13.0/368540 on MYWINDOWS:Created 'standalone\win32-1.33.1\bin\pact-mock-service.bat service --port '1234' --consumer 'KarmaJasmineConsumer' --provider 'KarmaJasmineProvider' --log 'C:\devl\demo-dojo.webapp\logs\pact.log' --pact_dir 'C:\devl\demo-dojo.webapp\pacts' --pact-file-write-mode 'overwrite' --host 'localhost'' process with PID: 365796
(node:368540) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[2018-08-13T16:09:06.262Z]  WARN: pact-node@6.13.0/368540 on MYWINDOWS: Pact exited with code 1.
mefellows commented 6 years ago

I'm not getting that error, this is what I get:

➜  pact-js git:(master) ✗ ./node_modules/.bin/grunt test-pact
(node:22285) ExperimentalWarning: The http2 module is an experimental API.
Running "karma:pacts" (karma) task
16 08 2018 09:36:53.644:INFO [framework.browserify]: registering rebuild (autoWatch=true)
[2018-08-15T23:36:53.648Z]  INFO: pact-node@6.19.10/22285 on macfellows.mel.dius.local:
    Creating Pact Server with options:
    port = 1234,
    consumer = KarmaJasmineConsumer,
    provider = KarmaJasmineProvider,
    logLevel = DEBUG,
    log = /private/tmp/pact-js/logs/pact.log,
    dir = /private/tmp/pact-js/pacts,
    pactFileWriteMode = overwrite,
    ssl = false,
    cors = false,
    host = localhost
[2018-08-15T23:36:53.654Z]  INFO: pact-node@6.19.10/22285 on macfellows.mel.dius.local: Created './standalone/darwin-1.54.3/bin/pact-mock-service service --port '1234' --consumer 'KarmaJasmineConsumer' --provider 'KarmaJasmineProvider' --log-level 'DEBUG' --log '/private/tmp/pact-js/logs/pact.log' --pact_dir '/private/tmp/pact-js/pacts' --pact-file-write-mode 'overwrite' --host 'localhost'' process with PID: 22286
(node:22285) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
16 08 2018 09:36:54.687:INFO [pact]: Pact Mock Server running on port: 1234
16 08 2018 09:36:54.717:WARN [watcher]: Pattern "/private/tmp/pact-js/test/test/**/*.pact.spec.js" does not match any file.
16 08 2018 09:36:54.718:WARN [watcher]: Pattern "/private/tmp/pact-js/test/test/spec/pact/client.js" does not match any file.
16 08 2018 09:36:54.718:WARN [watcher]: Pattern "/private/tmp/pact-js/test/node_modules/@pact-foundation/pact/pact-web.js" does not match any file.
16 08 2018 09:36:55.432:INFO [framework.browserify]: 471 bytes written (0.00 seconds)
16 08 2018 09:36:55.433:INFO [framework.browserify]: bundle built
16 08 2018 09:36:55.434:WARN [karma]: No captured browser, open http://localhost:9876/
16 08 2018 09:36:55.442:INFO [karma]: Karma v1.7.0 server started at http://0.0.0.0:9876/
16 08 2018 09:36:55.442:INFO [launcher]: Launching browser PhantomJS_without_security with unlimited concurrency
16 08 2018 09:36:55.449:INFO [launcher]: Starting browser PhantomJS
16 08 2018 09:36:56.520:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket iiwQRvYz6d3nldUdAAAA with id 52985846
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 0 of 0 ERROR (0.001 secs / 0 secs)
mefellows commented 6 years ago

Looking at your logs, this appears to be the issue:

13 08 2018 12:09:02.891:ERROR [plugin]: Error during loading "C:\devl\demo-dojo.webapp\node_modules/karma-phantomjs-launcher" plugin:
  Path must be a string. Received null

I also don't have grunt installed on my machine, and don't know which versions you have either.

Please provide more detail so that I can help you.

kaparna91 commented 6 years ago

This is the version of "grunt": "^0.4.5". I observed that you are using pact-node@6.19.0 and I am using pact-node@6.13.0 could that be an issue.

mefellows commented 6 years ago

We recently released a version of karma-pact that fixes an issue with the latest deasync package, maybe give that a go first.

Also, until I can download your package and actually run it with clear step-by-step instructions, I can't help you. The package you've provided simply doesn't run.

kaparna91 commented 6 years ago

The step by step instructions to run the project

  1. Do "npm install " after you clone the project.
  2. After all the node modules loaded , check for grunt tasks.
  3. After grunt tasks loads run "test pact " task.

For previous versions of pact the logs used to look like this

[2018-08-22T15:23:12.470Z] INFO: pact-node@6.7.4/92724 on MYWINDOWS: Creating Pact Server with options: port = 1234, consumer = KarmaJasmineConsumer, provider = KarmaJasmineProvider, logLevel = DEBUG, log = C:devl\UI\dojo.webapp\logs\pact.log, dir = C:devl\UI\dojo.webapp\pacts, pactFileWriteMode = overwrite, ssl = false, cors = false, host = localhost [2018-08-22T15:23:12.544Z] INFO: pact-node@6.7.4/92724 on MYWINDOWS: Created 'platforms\win32\bin\pact-mock-service.bat service --port '1234' --consumer 'KarmaJasmineConsumer' --provider 'KarmaJasmineProvider' --log 'C:\Desktop\UI\dojo.webapp\logs\pact.log' --pact_dir 'C:\Desktop\UI\dojo.webapp\pacts' --pact-file-write-mode 'overwrite' --host 'localhost'' process with PID: 94096 22 08 2018 11:23:19.748:INFO [pact]: Pact Mock Server running on port: 1234

After updating my project with new pact modules pact exits with code 1

[2018-08-27T13:52:48.457Z] INFO: pact-node@6.19.10/437664 on MYWINDOWS: Creating Pact Server with options: port = 1234, consumer = KarmaJasmineConsumer, provider = KarmaJasmineProvider, logLevel = DEBUG, log = C:\devl\demo-dojo.webapp\logs\pact.log, dir = C:\devl\demo-dojo.webapp\pacts, pactFileWriteMode = overwrite, ssl = false, cors = false, host = localhost [2018-08-27T13:52:48.510Z] INFO: pact-node@6.19.10/437664 on MYWINDOWS: Created 'standalone\win32-1.54.3\bin\pact-mock-service.bat service --port '1234' --consumer 'KarmaJasmineConsumer' --provider 'KarmaJasmineProvider' --log-level 'DEBUG' --log 'C:\devl\demo-dojo.webapp\logs\pact.log' --pact_dir 'C:\devl\demo-dojo.webapp\pacts' --pact-file-write-mode 'overwrite' --host 'localhost'' process with PID: 438240 (node:437664) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead. [2018-08-27T13:52:48.745Z] ERROR: pact-node@6.19.10/437664 on MYWINDOWS: Pact Binary Error: The system cannot find the path specified.

[2018-08-27T13:52:48.751Z] WARN: pact-node@6.19.10/437664 on MYWINDOWS: Pact exited with code 1.

mefellows commented 6 years ago

OK, for starters that doesn't work - I don't have grunt installed locally, so you need to either a) add it to your package.json or specify it. Which version of node? which directory to run it from (it fails for me).

I should literally be able to checkout the project locally, and blindly run your instructions.

kaparna91 commented 6 years ago

I have added every dependency in package.json that is needed to run the project. I used grunt version "grunt": "^0.4.5"
node version : node 8.9.4.