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

Consumer tests failing on MAC OS Catalina #383

Closed
igor-pol opened this issue Oct 22, 2019 · 19 comments
Closed

Consumer tests failing on MAC OS Catalina #383

igor-pol opened this issue Oct 22, 2019 · 19 comments

Comments

@igor-pol
Copy link

Software versions

  • OS: Mac OSX 10.15
  • Consumer Pact library: @pact-foundation/pact v9.0.1 and v9.2.1
  • Node Version: 10.16.3

Actual behaviour

Consumer tests were working fine on MAC OSX 10.14.5, but since we updated to 10.15 the tests are failing now.

Steps to reproduce

Run any consumer test on MAC OSX Catalina..

Relevant log files

 ● Test suite failed to run
   TypeError: Cannot read property ‘writePact’ of undefined
     12 | afterAll((done) => {
     13 |     Promise.all([
   > 14 |         newsProvider.finalize(),
        |                ^
     15 |         documentProvider.finalize(),
     16 |         legalProvider.finalize(),
     17 |         feedbackProvider.finalize(),
     at Pact.Object.<anonymous>.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8)
     at Object.<anonymous> (contract/pactTestWrapper.js:14:16)```
@TimothyJones
Copy link
Contributor

It looks like that error would happen if the mock service didn’t initialise. Is there anything in the pact log file (or test output) about errors during initialisation?

Also, have your network settings changed after upgrading the OS?

@igor-pol
Copy link
Author

It looks like that error would happen if the mock service didn’t initialise. Is there anything in the pact log file (or test output) about errors during initialisation?

Unfortunately I don't get any logs anymore since this issue. Only during the very first run I got logs in the console, where it said that the init of the pact server failed, due to a "no such file or directory" error. I haven't been able to reproduce it, so I don't have the exact logs anymore...

Also, have your network settings changed after upgrading the OS?

No.

@mefellows
Copy link
Member

Thanks @aTastyT0ast. Can you please share the output of our debugging tips?

@igor-pol
Copy link
Author

igor-pol commented Oct 24, 2019

@mefellows Here you go. For better reproducibility, we used the jest example from this repo and set the same dependencies we use in our project, which have the same errors:

[2019-10-24T12:17:04.453Z]  INFO: pact-node@9.0.7/605 on Commander-Keen.local: 
    Creating Pact Server with options: 
    {"consumer":"MyConsumer","cors":false,"dir":"/Users/MAPP/Downloads/pact-js-master/examples/jest/pacts","host":"127.0.0.1","log":"/Users/MAPP/Downloads/pact-js-master/examples/jest/logs/mockserver-integration.log","pactFileWriteMode":"update","port":8991,"provider":"MyProvider","spec":2,"ssl":false}
 FAIL  __tests__/catAPI.spec.js
  ● Test suite failed to run

    TypeError: Cannot read property 'writePact' of undefined

      4 | 
      5 | afterAll(done => {
    > 6 |   provider.finalize().then(() => done())
        |            ^
      7 | })
      8 | 

      at Pact.Object.<anonymous>.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8)
      at Object.finalize (pactTestWrapper.js:6:12)

[2019-10-24T12:17:09.959Z]  INFO: pact-node@9.0.7/605 on Commander-Keen.local: 
    Creating Pact Server with options: 
    {"consumer":"MyConsumer","cors":false,"dir":"/Users/MAPP/Downloads/pact-js-master/examples/jest/pacts","host":"127.0.0.1","log":"/Users/MAPP/Downloads/pact-js-master/examples/jest/logs/mockserver-integration.log","pactFileWriteMode":"update","port":8991,"provider":"MyProvider","spec":2,"ssl":false}
 FAIL  __tests__/index.spec.js
  ● Test suite failed to run

    TypeError: Cannot read property 'writePact' of undefined

      4 | 
      5 | afterAll(done => {
    > 6 |   provider.finalize().then(() => done())
        |            ^
      7 | })
      8 | 

      at Pact.Object.<anonymous>.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8)
      at Object.finalize (pactTestWrapper.js:6:12)

[2019-10-24T12:17:15.092Z]  INFO: pact-node@9.0.7/605 on Commander-Keen.local: 
    Creating Pact Server with options: 
    {"consumer":"MyConsumer","cors":false,"dir":"/Users/MAPP/Downloads/pact-js-master/examples/jest/pacts","host":"127.0.0.1","log":"/Users/MAPP/Downloads/pact-js-master/examples/jest/logs/mockserver-integration.log","pactFileWriteMode":"update","port":8991,"provider":"MyProvider","spec":2,"ssl":false}
 FAIL  __tests__/multipleSpecs.spec.js
  ● Test suite failed to run

    TypeError: Cannot read property 'writePact' of undefined

      4 | 
      5 | afterAll(done => {
    > 6 |   provider.finalize().then(() => done())
        |            ^
      7 | })
      8 | 

      at Pact.Object.<anonymous>.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8)
      at Object.finalize (pactTestWrapper.js:6:12)

Test Suites: 3 failed, 3 total
Tests:       0 total
Snapshots:   0 total
Time:        16.609s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
➜  jest yarn pact
yarn run v1.19.1
$ jest --runInBand --setupFiles ./pactSetup.js --setupFilesAfterEnv ./pactTestWrapper.js --testMatch "**/*.spec.js"
[2019-10-24T12:17:41.772Z]  INFO: pact-node@9.0.7/818 on Commander-Keen.local: 
    Creating Pact Server with options: 
    {"consumer":"MyConsumer","cors":false,"dir":"/Users/MAPP/Downloads/pact-js-master/examples/jest/pacts","host":"127.0.0.1","log":"/Users/MAPP/Downloads/pact-js-master/examples/jest/logs/mockserver-integration.log","pactFileWriteMode":"update","port":8991,"provider":"MyProvider","spec":2,"ssl":false}
 FAIL  __tests__/catAPI.spec.js
  ● Test suite failed to run

    TypeError: Cannot read property 'writePact' of undefined

      4 | 
      5 | afterAll(done => {
    > 6 |   provider.finalize().then(() => done())
        |            ^
      7 | })
      8 | 

      at Pact.Object.<anonymous>.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8)
      at Object.finalize (pactTestWrapper.js:6:12)

[2019-10-24T12:17:47.296Z]  INFO: pact-node@9.0.7/818 on Commander-Keen.local: 
    Creating Pact Server with options: 
    {"consumer":"MyConsumer","cors":false,"dir":"/Users/MAPP/Downloads/pact-js-master/examples/jest/pacts","host":"127.0.0.1","log":"/Users/MAPP/Downloads/pact-js-master/examples/jest/logs/mockserver-integration.log","pactFileWriteMode":"update","port":8991,"provider":"MyProvider","spec":2,"ssl":false}
 FAIL  __tests__/index.spec.js
  ● Test suite failed to run

    TypeError: Cannot read property 'writePact' of undefined

      4 | 
      5 | afterAll(done => {
    > 6 |   provider.finalize().then(() => done())
        |            ^
      7 | })
      8 | 

      at Pact.Object.<anonymous>.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8)
      at Object.finalize (pactTestWrapper.js:6:12)

[2019-10-24T12:17:52.440Z]  INFO: pact-node@9.0.7/818 on Commander-Keen.local: 
    Creating Pact Server with options: 
    {"consumer":"MyConsumer","cors":false,"dir":"/Users/MAPP/Downloads/pact-js-master/examples/jest/pacts","host":"127.0.0.1","log":"/Users/MAPP/Downloads/pact-js-master/examples/jest/logs/mockserver-integration.log","pactFileWriteMode":"update","port":8991,"provider":"MyProvider","spec":2,"ssl":false}
 FAIL  __tests__/multipleSpecs.spec.js
  ● Test suite failed to run

    TypeError: Cannot read property 'writePact' of undefined

      4 | 
      5 | afterAll(done => {
    > 6 |   provider.finalize().then(() => done())
        |            ^
      7 | })
      8 | 

      at Pact.Object.<anonymous>.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8)
      at Object.finalize (pactTestWrapper.js:6:12)

Test Suites: 3 failed, 3 total
Tests:       0 total
Snapshots:   0 total
Time:        16.775s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
➜  jest ./node_modules/.bin/pact-mock-service
INFO  WEBrick 1.3.1
INFO  ruby 2.2.2 (2015-04-13) [x86_64-darwin13]
INFO  WEBrick::HTTPServer#start: pid=1060 port=51169
^CINFO  going to shutdown ...
INFO  WEBrick::HTTPServer#start done.

➜  jest ./node_modules/.bin/pact-provider-verifier
No value provided for required options '--provider-base-url'

And the only thing we changed from the jest example were the logLevel to DEBUG (which apparently didn't provide any more logs as you can see in the logs above) and the package.json:

{
  "name": "jest",
  "version": "1.0.0",
  "description": "Jest Pact example",
  "main": "index.js",
  "scripts": {
    "pact": "jest --runInBand --setupFiles ./pactSetup.js --setupFilesAfterEnv ./pactTestWrapper.js --testMatch \"**/*.spec.js\"",
    "publish:pact": "node ./publish.js"
  },
  "license": "MIT",
  "jest": {
    "testEnvironment": "node"
  },
  "devDependencies": {
    "@pact-foundation/pact": "9.2.1",
    "axios": "0.14.0",
    "jest": "24.0.0"
  }
}

Also after testing it out on another machine and in docker containers, we noticed that it's not related to the OS at all. So now we are not sure what exactly causes the tests to fail.

@mefellows
Copy link
Member

Thanks @aTastyT0ast (also love your computer name!).

Mmm I can't see why that would be. The fact that the binaries are executing, and that our CI builds for linux/MacOSX aren't failing is a positive, and leads me to think that something is going on in your environment.

Can you literally clone this repository and run the examples as we do in our CI build?

@igor-pol
Copy link
Author

igor-pol commented Oct 28, 2019

@mefellows Thanks, here you go:

➜  jest git:(master) ✗ docker run -it --rm -v /Users/MAPP/Desktop/pact-js/examples/jest/:/code node:12 bash 
root@323e3859ddc0:/# cd code
root@323e3859ddc0:/code# rm -rf node_modules/
root@323e3859ddc0:/code# npm install

> dtrace-provider@0.8.7 install /code/node_modules/dtrace-provider
> node-gyp rebuild || node suppress-error.js

make: Entering directory '/code/node_modules/dtrace-provider/build'
  TOUCH Release/obj.target/DTraceProviderStub.stamp
make: Leaving directory '/code/node_modules/dtrace-provider/build'

> spawn-sync@1.0.15 postinstall /code/node_modules/spawn-sync
> node postinstall


> caporal@1.2.0 postinstall /code/node_modules/caporal
> (test -f ./node_modules/husky/bin/install.js && node ./node_modules/husky/bin/install.js) || exit 0


> @pact-foundation/pact-node@8.6.0 postinstall /code/node_modules/@pact-foundation/pact-node
> node postinstall.js

Installing Pact Standalone Binary for linux.
Downloading Pact Standalone Binary v1.68.0 for platform linux from https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.68.0/pact-1.68.0-linux-x86_64.tar.gz
Please note: we are tracking this download anonymously to gather important usage statistics. To disable tracking, set 'pact_do_not_track: true' in your package.json 'config' section.
npm Downloaded 0.91%...
Downloaded 58.10%...
testFinished downloading binary to /code/node_modules/@pact-foundation/pact-node/standalone/pact-1.68.0-linux-x86_64.tar.gz
Extracting binary from /code/node_modules/@pact-foundation/pact-node/standalone/pact-1.68.0-linux-x86_64.tar.gz.
Checksum passed for 'pact-1.68.0-linux-x86_64.tar.gz'.
Extraction done.


### If you ❤ Pact and want to support us, please donate here: http://donate.pact.io/node


Pact Standalone Binary is ready.
npm WARN jest@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 769 packages from 518 contributors and audited 9090 packages in 51.256s
found 234 vulnerabilities (104 low, 74 moderate, 56 high)
  run `npm audit fix` to fix them, or `npm audit` for details
root@323e3859ddc0:/code# npm test

> jest@1.0.0 test /code
> jest __tests__/ --runInBand --setupFiles ./pactSetup.js --setupTestFrameworkScriptFile ./pactTestWrapper.js 

[2019-10-28T12:21:50.716Z]  INFO: pact-node@8.6.0/76 on 323e3859ddc0: 
    Creating Pact Server with options: 
    consumer = MyConsumer,
    cors = false,
    dir = /code/pacts,
    host = 127.0.0.1,
    log = /code/logs/mockserver-integration.log,
    pactFileWriteMode = update,
    port = 8991,
    provider = MyProvider,
    spec = 2,
    ssl = false,
    sslcert = ,
    sslkey = 
[2019-10-28T12:21:51.650Z] DEBUG: pact-node@8.6.0/76 on 323e3859ddc0: Starting pact binary with '/bin/sh,[object Object],{"cwd":"/code/node_modules/@pact-foundation/pact-node","detached":true,"env":{"npm_config_cache_lock_stale":"60000","npm_config_ham_it_up":"","npm_config_legacy_bundling":"","npm_config_sign_git_tag":"","npm_config_user_agent":"npm/6.12.0 node/v12.13.0 linux x64","npm_config_always_auth":"","NODE_VERSION":"12.13.0","npm_package_jest_testEnvironment":"node","npm_config_bin_links":"true","npm_config_key":"","YARN_VERSION":"1.19.1","HOSTNAME":"323e3859ddc0","npm_config_allow_same_version":"","npm_config_description":"true","npm_config_fetch_retries":"2","npm_config_heading":"npm","npm_config_if_present":"","npm_config_init_version":"1.0.0","npm_config_user":"","npm_node_execpath":"/usr/local/bin/node","SHLVL":"1","npm_config_prefer_online":"","npm_config_noproxy":"","HOME":"/root","OLDPWD":"/","npm_config_force":"","npm_config_only":"","npm_config_read_only":"","npm_config_cache_min":"10","npm_config_init_license":"ISC","npm_config_editor":"vi","npm_config_rollback":"true","npm_config_tag_version_prefix":"v","npm_config_cache_max":"Infinity","npm_config_timing":"","npm_config_userconfig":"/root/.npmrc","npm_config_engine_strict":"","npm_config_init_author_name":"","npm_config_init_author_url":"","npm_config_preid":"","npm_config_tmp":"/tmp","npm_package_description":"Jest Pact example","npm_config_depth":"Infinity","npm_config_package_lock_only":"","npm_config_save_dev":"","npm_config_usage":"","npm_package_readmeFilename":"README.md","npm_config_metrics_registry":"https://registry.npmjs.org/","npm_config_cafile":"","npm_config_otp":"","npm_config_package_lock":"true","npm_config_progress":"true","npm_config_https_proxy":"","npm_config_save_prod":"","npm_config_audit":"true","npm_config_cidr":"","npm_config_onload_script":"","npm_config_sso_type":"oauth","npm_config_rebuild_bundle":"true","npm_config_save_bundle":"","npm_config_shell":"bash","_":"/usr/local/bin/npm","npm_config_dry_run":"","npm_config_format_package_lock":"true","npm_config_prefix":"/usr/local","npm_config_scope":"","npm_config_browser":"","npm_config_cache_lock_wait":"10000","npm_config_ignore_prepublish":"","npm_config_registry":"https://registry.npmjs.org/","npm_config_save_optional":"","npm_config_searchopts":"","npm_config_versions":"","TERM":"xterm","npm_config_cache":"/root/.npm","npm_config_proxy":"","npm_config_send_metrics":"","npm_package_devDependencies_jest_cli":"^21.0.0","npm_config_global_style":"","npm_config_ignore_scripts":"","npm_config_version":"","npm_config_local_address":"","npm_config_viewer":"man","npm_config_node_gyp":"/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js","PATH":"/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/code/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","npm_package_name":"jest","npm_package_devDependencies__pact_foundation_pact":"^8.2.6","npm_config_audit_level":"low","npm_config_prefer_offline":"","NODE":"/usr/local/bin/node","npm_config_color":"true","npm_config_sign_git_commit":"","npm_config_fetch_retry_mintimeout":"10000","npm_config_maxsockets":"50","npm_config_offline":"","npm_config_sso_poll_frequency":"500","npm_config_umask":"0022","npm_package_main":"index.js","npm_config_fetch_retry_maxtimeout":"60000","npm_config_loglevel":"notice","npm_config_logs_max":"10","npm_config_message":"%s","npm_lifecycle_script":"jest __tests__/ --runInBand --setupFiles ./pactSetup.js --setupTestFrameworkScriptFile ./pactTestWrapper.js ","npm_package_scripts_test":"jest __tests__/ --runInBand --setupFiles ./pactSetup.js --setupTestFrameworkScriptFile ./pactTestWrapper.js ","npm_config_ca":"","npm_config_cert":"","npm_config_global":"","npm_config_link":"","npm_package_version":"1.0.0","npm_config_access":"","npm_config_also":"","npm_config_save":"true","npm_config_unicode":"","npm_lifecycle_event":"test","npm_config_argv":"{\"remain\":[],\"cooked\":[\"test\"],\"original\":[\"test\"]}","npm_config_before":"","npm_config_long":"","npm_config_production":"","npm_config_searchlimit":"20","npm_config_unsafe_perm":"","npm_config_update_notifier":"true","npm_config_auth_type":"legacy","npm_config_node_version":"12.13.0","npm_config_tag":"latest","npm_config_git_tag_version":"true","npm_config_commit_hooks":"true","npm_config_script_shell":"","npm_config_shrinkwrap":"true","npm_package_license":"MIT","npm_config_fetch_retry_factor":"10","npm_config_save_exact":"","npm_config_strict_ssl":"true","npm_config_dev":"","npm_config_globalconfig":"/usr/local/etc/npmrc","npm_config_init_module":"/root/.npm-init.js","npm_config_parseable":"","PWD":"/code","npm_config_globalignorefile":"/usr/local/etc/npmignore","npm_execpath":"/usr/local/lib/node_modules/npm/bin/npm-cli.js","npm_package_devDependencies_axios":"^0.14.0","npm_config_cache_lock_retries":"10","npm_config_searchstaleness":"900","npm_config_node_options":"","npm_config_save_prefix":"^","npm_config_scripts_prepend_node_path":"warn-only","npm_config_group":"","npm_config_init_author_email":"","npm_config_searchexclude":"","npm_package_scripts_publish_pact":"node ./publish.js","npm_config_git":"git","npm_config_optional":"true","npm_config_json":"","INIT_CWD":"/code","NODE_ENV":"test"}}'
[2019-10-28T12:21:51.655Z]  INFO: pact-node@8.6.0/76 on 323e3859ddc0: Created './standalone/linux-x64-1.68.0/bin/pact-mock-service service --consumer 'MyConsumer' --pact_dir '/code/pacts' --host '127.0.0.1' --log '/code/logs/mockserver-integration.log' --pact-file-write-mode 'update' --port '8991' --provider 'MyProvider' --pact_specification_version '2'' process with PID: 89
 FAIL  __tests__/multipleSpecs.spec.js (5.971s)
  ● Dog's API › works › returns a sucessful body

    Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
      
      at node_modules/jest-cli/node_modules/jest-jasmine2/build/queue_runner.js:64:21
      at listOnTimeout (internal/timers.js:531:17)
      at processTimers (internal/timers.js:475:7)

  ● Dog's API › works › returns a sucessful body

    TypeError: Cannot read property 'addInteraction' of undefined
      
      at Pact.Object.<anonymous>.Pact.addInteraction (node_modules/@pact-foundation/pact/httpPact.js:81:33)
      at Object.<anonymous> (__tests__/multipleSpecs.spec.js:38:23)
          at new Promise (<anonymous>)

  ● Dog's API › works › returns a sucessful body

    connect ECONNREFUSED 127.0.0.1:8991
      
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1128:14)

  ● Dog's API › works › returns a sucessful body

    TypeError: Cannot read property 'verify' of undefined
      
      at Pact.Object.<anonymous>.Pact.verify (node_modules/@pact-foundation/pact/httpPact.js:92:14)
      at Object.<anonymous> (__tests__/multipleSpecs.spec.js:15:21)
          at new Promise (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)

  ● Dog's API › works again › returns a sucessful body

    Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
      
      at node_modules/jest-cli/node_modules/jest-jasmine2/build/queue_runner.js:64:21
      at listOnTimeout (internal/timers.js:531:17)
      at processTimers (internal/timers.js:475:7)

  ● Dog's API › works again › returns a sucessful body

    TypeError: Cannot read property 'addInteraction' of undefined
      
      at Pact.Object.<anonymous>.Pact.addInteraction (node_modules/@pact-foundation/pact/httpPact.js:81:33)
      at Object.<anonymous> (__tests__/multipleSpecs.spec.js:75:23)
          at new Promise (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)

  ● Dog's API › works again › returns a sucessful body

    connect ECONNREFUSED 127.0.0.1:8991
      
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1128:14)

  ● Dog's API › works again › returns a sucessful body

    TypeError: Cannot read property 'verify' of undefined
      
      at Pact.Object.<anonymous>.Pact.verify (node_modules/@pact-foundation/pact/httpPact.js:92:14)
      at Object.<anonymous> (__tests__/multipleSpecs.spec.js:15:21)
          at new Promise (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)

[2019-10-28T12:21:57.474Z]  INFO: pact-node@8.6.0/76 on 323e3859ddc0: 
    Creating Pact Server with options: 
    consumer = MyConsumer,
    cors = false,
    dir = /code/pacts,
    host = 127.0.0.1,
    log = /code/logs/mockserver-integration.log,
    pactFileWriteMode = update,
    port = 8991,
    provider = MyProvider,
    spec = 2,
    ssl = false,
    sslcert = ,
    sslkey = 
[2019-10-28T12:21:57.677Z] DEBUG: pact-node@8.6.0/76 on 323e3859ddc0: Starting pact binary with '/bin/sh,[object Object],{"cwd":"/code/node_modules/@pact-foundation/pact-node","detached":true,"env":{"npm_config_cache_lock_stale":"60000","npm_config_ham_it_up":"","npm_config_legacy_bundling":"","npm_config_sign_git_tag":"","npm_config_user_agent":"npm/6.12.0 node/v12.13.0 linux x64","npm_config_always_auth":"","NODE_VERSION":"12.13.0","npm_package_jest_testEnvironment":"node","npm_config_bin_links":"true","npm_config_key":"","YARN_VERSION":"1.19.1","HOSTNAME":"323e3859ddc0","npm_config_allow_same_version":"","npm_config_description":"true","npm_config_fetch_retries":"2","npm_config_heading":"npm","npm_config_if_present":"","npm_config_init_version":"1.0.0","npm_config_user":"","npm_node_execpath":"/usr/local/bin/node","SHLVL":"1","npm_config_prefer_online":"","npm_config_noproxy":"","HOME":"/root","OLDPWD":"/","npm_config_force":"","npm_config_only":"","npm_config_read_only":"","npm_config_cache_min":"10","npm_config_init_license":"ISC","npm_config_editor":"vi","npm_config_rollback":"true","npm_config_tag_version_prefix":"v","npm_config_cache_max":"Infinity","npm_config_timing":"","npm_config_userconfig":"/root/.npmrc","npm_config_engine_strict":"","npm_config_init_author_name":"","npm_config_init_author_url":"","npm_config_preid":"","npm_config_tmp":"/tmp","npm_package_description":"Jest Pact example","npm_config_depth":"Infinity","npm_config_package_lock_only":"","npm_config_save_dev":"","npm_config_usage":"","npm_package_readmeFilename":"README.md","npm_config_metrics_registry":"https://registry.npmjs.org/","npm_config_cafile":"","npm_config_otp":"","npm_config_package_lock":"true","npm_config_progress":"true","npm_config_https_proxy":"","npm_config_save_prod":"","npm_config_audit":"true","npm_config_cidr":"","npm_config_onload_script":"","npm_config_sso_type":"oauth","npm_config_rebuild_bundle":"true","npm_config_save_bundle":"","npm_config_shell":"bash","_":"/usr/local/bin/npm","npm_config_dry_run":"","npm_config_format_package_lock":"true","npm_config_prefix":"/usr/local","npm_config_scope":"","npm_config_browser":"","npm_config_cache_lock_wait":"10000","npm_config_ignore_prepublish":"","npm_config_registry":"https://registry.npmjs.org/","npm_config_save_optional":"","npm_config_searchopts":"","npm_config_versions":"","TERM":"xterm","npm_config_cache":"/root/.npm","npm_config_proxy":"","npm_config_send_metrics":"","npm_package_devDependencies_jest_cli":"^21.0.0","npm_config_global_style":"","npm_config_ignore_scripts":"","npm_config_version":"","npm_config_local_address":"","npm_config_viewer":"man","npm_config_node_gyp":"/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js","PATH":"/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/code/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","npm_package_name":"jest","npm_package_devDependencies__pact_foundation_pact":"^8.2.6","npm_config_audit_level":"low","npm_config_prefer_offline":"","NODE":"/usr/local/bin/node","npm_config_color":"true","npm_config_sign_git_commit":"","npm_config_fetch_retry_mintimeout":"10000","npm_config_maxsockets":"50","npm_config_offline":"","npm_config_sso_poll_frequency":"500","npm_config_umask":"0022","npm_package_main":"index.js","npm_config_fetch_retry_maxtimeout":"60000","npm_config_loglevel":"notice","npm_config_logs_max":"10","npm_config_message":"%s","npm_lifecycle_script":"jest __tests__/ --runInBand --setupFiles ./pactSetup.js --setupTestFrameworkScriptFile ./pactTestWrapper.js ","npm_package_scripts_test":"jest __tests__/ --runInBand --setupFiles ./pactSetup.js --setupTestFrameworkScriptFile ./pactTestWrapper.js ","npm_config_ca":"","npm_config_cert":"","npm_config_global":"","npm_config_link":"","npm_package_version":"1.0.0","npm_config_access":"","npm_config_also":"","npm_config_save":"true","npm_config_unicode":"","npm_lifecycle_event":"test","npm_config_argv":"{\"remain\":[],\"cooked\":[\"test\"],\"original\":[\"test\"]}","npm_config_before":"","npm_config_long":"","npm_config_production":"","npm_config_searchlimit":"20","npm_config_unsafe_perm":"","npm_config_update_notifier":"true","npm_config_auth_type":"legacy","npm_config_node_version":"12.13.0","npm_config_tag":"latest","npm_config_git_tag_version":"true","npm_config_commit_hooks":"true","npm_config_script_shell":"","npm_config_shrinkwrap":"true","npm_package_license":"MIT","npm_config_fetch_retry_factor":"10","npm_config_save_exact":"","npm_config_strict_ssl":"true","npm_config_dev":"","npm_config_globalconfig":"/usr/local/etc/npmrc","npm_config_init_module":"/root/.npm-init.js","npm_config_parseable":"","PWD":"/code","npm_config_globalignorefile":"/usr/local/etc/npmignore","npm_execpath":"/usr/local/lib/node_modules/npm/bin/npm-cli.js","npm_package_devDependencies_axios":"^0.14.0","npm_config_cache_lock_retries":"10","npm_config_searchstaleness":"900","npm_config_node_options":"","npm_config_save_prefix":"^","npm_config_scripts_prepend_node_path":"warn-only","npm_config_group":"","npm_config_init_author_email":"","npm_config_searchexclude":"","npm_package_scripts_publish_pact":"node ./publish.js","npm_config_git":"git","npm_config_optional":"true","npm_config_json":"","INIT_CWD":"/code","NODE_ENV":"test"}}'
[2019-10-28T12:21:57.683Z]  INFO: pact-node@8.6.0/76 on 323e3859ddc0: Created './standalone/linux-x64-1.68.0/bin/pact-mock-service service --consumer 'MyConsumer' --pact_dir '/code/pacts' --host '127.0.0.1' --log '/code/logs/mockserver-integration.log' --pact-file-write-mode 'update' --port '8991' --provider 'MyProvider' --pact_specification_version '2'' process with PID: 101
[2019-10-28T12:22:01.842Z] DEBUG: pact-node@8.6.0/76 on 323e3859ddc0: 
    INFO  WEBrick 1.3.1
    INFO  ruby 2.2.2 (2015-04-13) [x86_64-linux]
    
[2019-10-28T12:22:01.842Z] DEBUG: pact-node@8.6.0/76 on 323e3859ddc0: 
    INFO  WEBrick::HTTPServer#start: pid=90 port=8991
    
[2019-10-28T12:22:02.213Z]  INFO: pact@8.2.6/76 on 323e3859ddc0: 
    Setting up Pact with Consumer "MyConsumer" and Provider "MyProvider"
        using mock service on Port: "8991"
[2019-10-28T12:22:02.215Z]  INFO: pact@8.2.6/76 on 323e3859ddc0: 
    Setting up Pact with Consumer "MyConsumer" and Provider "MyProvider"
        using mock service on Port: "8991"
[2019-10-28T12:22:02.282Z] DEBUG: pact-node@8.6.0/76 on 323e3859ddc0: 
    WARN: Ignoring unsupported matching rules {"min"=>1} for path $['query']['catId'][]
    WARN: Ignoring unsupported matching rules {"match"=>"type"} for path $['query']['catId'][][*]*
    
[2019-10-28T12:22:02.282Z] ERROR: pact-node@8.6.0/76 on 323e3859ddc0: 
    Pact Binary Error: WARN: Ignoring unsupported matching rules {"min"=>1} for path $['query']['catId'][]
    WARN: Ignoring unsupported matching rules {"match"=>"type"} for path $['query']['catId'][][*]*
    
[2019-10-28T12:22:02.282Z] DEBUG: pact-node@8.6.0/76 on 323e3859ddc0: 
    *****************************************************************************
    Updating existing file ./code/pacts/myconsumer-myprovider.json as pactfile_write_mode is :update
    Only interactions defined in this test run will be updated.
    
[2019-10-28T12:22:02.283Z] DEBUG: pact-node@8.6.0/76 on 323e3859ddc0: 
    As interactions are identified by description and provider state, pleased note that if either of these have changed, the old interactions won't be removed from the pact file until the specs are next run with :pactfile_write_mode => :overwrite.
    
[2019-10-28T12:22:02.283Z] DEBUG: pact-node@8.6.0/76 on 323e3859ddc0: 
    *****************************************************************************
    
[2019-10-28T12:22:02.291Z]  INFO: pact@8.2.6/76 on 323e3859ddc0: Pact File Written
[2019-10-28T12:22:02.291Z]  INFO: pact-node@8.6.0/76 on 323e3859ddc0: Removing Pact with PID: 101
[2019-10-28T12:22:02.311Z] DEBUG: pact-node@8.6.0/76 on 323e3859ddc0: 
    /code/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.68.0/lib/vendor/ruby/2.2.0/gems/thor-0.20.3/lib/thor.rb:55:in `desc': Interrupt
        from /code/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.68.0/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/cli.rb:16:in `<class:CLI>'
        from /code/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.68.0/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/cli.rb:11:in `<module:MockService>'
        from /code/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.68.0/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/cli.rb:10:in `<module:Pact>'
        from /code/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.68.0/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/cli.rb:9:in `<top (required)>'
        from /code/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.68.0/lib/app/pact-mock-service.rb:1:in `require'
        from /code/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.68.0/lib/app/pact-mock-service.rb:1:in `<main>'
    
[2019-10-28T12:22:02.311Z] ERROR: pact-node@8.6.0/76 on 323e3859ddc0: 
    Pact Binary Error: /code/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.68.0/lib/vendor/ruby/2.2.0/gems/thor-0.20.3/lib/thor.rb:55:in `desc': Interrupt
        from /code/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.68.0/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/cli.rb:16:in `<class:CLI>'
        from /code/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.68.0/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/cli.rb:11:in `<module:MockService>'
        from /code/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.68.0/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/cli.rb:10:in `<module:Pact>'
        from /code/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.68.0/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/cli.rb:9:in `<top (required)>'
        from /code/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.68.0/lib/app/pact-mock-service.rb:1:in `require'
        from /code/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.68.0/lib/app/pact-mock-service.rb:1:in `<main>'
    
 PASS  __tests__/catAPI.spec.js (9.796s)
[2019-10-28T12:22:07.776Z]  INFO: pact-node@8.6.0/76 on 323e3859ddc0: 
    Creating Pact Server with options: 
    consumer = MyConsumer,
    cors = false,
    dir = /code/pacts,
    host = 127.0.0.1,
    log = /code/logs/mockserver-integration.log,
    pactFileWriteMode = update,
    port = 8991,
    provider = MyProvider,
    spec = 2,
    ssl = false,
    sslcert = ,
    sslkey = 
 FAIL  __tests__/index.spec.js (5.143s)
  ● Console

    console.error node_modules/jest-cli/node_modules/jest-jasmine2/build/jasmine/Env.js:194
      Unhandled error
    console.error node_modules/jest-cli/node_modules/jest-jasmine2/build/jasmine/Env.js:195
      Error: Port 8991 is unavailable on address 127.0.0.1
          at Server.<anonymous> (/code/node_modules/@pact-foundation/pact/common/net.js:26:24)
          at Server.emit (events.js:210:5)
          at emitErrorNT (net.js:1327:8)
          at processTicksAndRejections (internal/process/task_queues.js:80:21)
          at runNextTicks (internal/process/task_queues.js:62:3)
          at processImmediate (internal/timers.js:412:9)

  ● Dog's API › works › returns a sucessful body

    Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
      
      at node_modules/jest-cli/node_modules/jest-jasmine2/build/queue_runner.js:64:21
      at listOnTimeout (internal/timers.js:531:17)
      at processTimers (internal/timers.js:475:7)

  ● Dog's API › works › returns a sucessful body

    TypeError: Cannot read property 'addInteraction' of undefined
      
      at Pact.Object.<anonymous>.Pact.addInteraction (node_modules/@pact-foundation/pact/httpPact.js:81:33)
      at Object.<anonymous> (__tests__/index.spec.js:34:23)
          at new Promise (<anonymous>)

  ● Dog's API › works › returns a sucessful body

    Request failed with status code 500
      
      at createError (node_modules/axios/lib/core/createError.js:15:15)
      at settle (node_modules/axios/lib/core/settle.js:18:12)
      at IncomingMessage.handleStreamEnd (node_modules/axios/lib/adapters/http.js:168:11)
      at IncomingMessage.emit (events.js:215:7)
      at endReadableNT (_stream_readable.js:1183:12)
      at processTicksAndRejections (internal/process/task_queues.js:80:21)

Test Suites: 2 failed, 1 passed, 3 total
Tests:       3 failed, 1 passed, 4 total
Snapshots:   0 total
Time:        25.88s
Ran all test suites matching /__tests__\//i.
[2019-10-28T12:22:32.270Z]  INFO: pact-node@8.6.0/76 on 323e3859ddc0: Removing Pact with PID: 101
(node:76) UnhandledPromiseRejectionWarning: Error: Couldn't stop Pact with PID '101'
(node:76) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 9)
(node:76) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
^C[2019-10-28T12:24:46.731Z]  INFO: pact-node@8.6.0/76 on 323e3859ddc0: Removing all Pact servers.
[2019-10-28T12:24:46.731Z]  INFO: pact-node@8.6.0/76 on 323e3859ddc0: Removing Pact with PID: 89
[2019-10-28T12:24:46.732Z]  INFO: pact-node@8.6.0/76 on 323e3859ddc0: Removing all Pact servers.
[2019-10-28T12:24:46.732Z]  INFO: pact-node@8.6.0/76 on 323e3859ddc0: Removing Pact with PID: 101
[2019-10-28T12:24:46.732Z]  INFO: pact-node@8.6.0/76 on 323e3859ddc0: Removing all Pact servers.

We made sure, that there was no pact-mock-service running beforehand, so I don't really understand the error message "connect ECONNREFUSED 127.0.0.1:8991".

@TimothyJones
Copy link
Contributor

TimothyJones commented Oct 28, 2019

Thanks for the detailed repro. I can reproduce this with docker (and MacOS Mojave), so I suspect it is something to do with the container. I'll do a bit of investigating.

@TimothyJones
Copy link
Contributor

Aha! This is happening because Jasmine (which is used by Jest) isn't waiting long enough for the pact server to start up, and for some reason Jasmine doesn't report the timeout failure in beforeAll. Adding:

jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000

To pactTestWrapper.js results in a successful test run.

There are a few places where we could improve this example (eg #385), too. You might also be interested in https://github.com/YOU54F/jest-pact , which aims to make using Jest and Pact together less fiddly.

I'll update the example to set the timeout.

@TimothyJones
Copy link
Contributor

I've committed a change to the examples that I think fixes this. Let me know how you go, and please re-open if I am mistaken.

@jameshd
Copy link

jameshd commented Nov 1, 2019

FWIW - I'm seeing exactly the same issue. Only happened recently too. Windows dev box is fine, only occurs on CI.

$ cross-env && jest --testRegex "./tests/pact/.*/*(.test.pact.js)" --runInBand
[�[37m2019-11-01T16:30:40.361Z�[39m] �[36m INFO�[39m: pact-node@10.0.1/594 on ip-10-64-22-233.eu-west-1.compute.internal: 
�[90m    �[36mCreating Pact Server with options: 
    {"consumer":"fe-fragment-user-insight","cors":false,"dir":"/home/jenkins/workspace/0-add-pact-tests-to-user-insight/pacts","host":"127.0.0.1","log":"/home/jenkins/workspace/0-add-pact-tests-to-user-insight/logs/mockserver-integration.log","pactFileWriteMode":"update","port":8991,"provider":"user-insight","spec":2,"ssl":false}�[39m
�[39mFAIL tests/pact/user-insights/mandatory-fields.test.pact.js
  ● Test suite failed to run

    TypeError: Cannot read property 'writePact' of undefined

       9 | 
      10 | afterAll(done => {
    > 11 |   return provider.finalize().then(() => done())
         |                   ^
      12 | })
      13 | 

      at Pact.Object.<anonymous>.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8)
      at Object.finalize (tests/pact/pactTestWrapper.js:11:19)

[�[37m2019-11-01T16:31:41.022Z�[39m] �[36m INFO�[39m: pact-node@10.0.1/594 on ip-10-64-22-233.eu-west-1.compute.internal: 
�[90m    �[36mCreating Pact Server with options: 
    {"consumer":"fe-fragment-user-insight","cors":false,"dir":"/home/jenkins/workspace/0-add-pact-tests-to-user-insight/pacts","host":"127.0.0.1","log":"/home/jenkins/workspace/0-add-pact-tests-to-user-insight/logs/mockserver-integration.log","pactFileWriteMode":"update","port":8991,"provider":"user-insight","spec":2,"ssl":false}�[39m
�[39mFAIL tests/pact/user-insights/jsonapi-confirmity.test.pact.js
  ● Test suite failed to run

    TypeError: Cannot read property 'writePact' of undefined

       9 | 
      10 | afterAll(done => {
    > 11 |   return provider.finalize().then(() => done())
         |                   ^
      12 | })
      13 | 

      at Pact.Object.<anonymous>.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8)
      at Object.finalize (tests/pact/pactTestWrapper.js:11:19)

Test Suites: 2 failed, 2 total
Tests:       0 total
Snapshots:   0 total
Time:        92.25s
Ran all test suites.
error Command failed with exit code 1.

This includes the timeout option set as per the example jest repo.

@sunshy360
Copy link

sunshy360 commented Dec 31, 2019

@jameshd
I have the same problem, and no matter how big the jest.setTimeout() set, the pact tests are always failed with the same error log.

Then I checked the proxy environment variables passed into the container, and I found that the mock server started on localhost was proxy to another URL. That's why pact tests can't connect to localhost mock server and make tests timeout.

So pls check the proxy of the container, and make the mock server start in the container.

@mefellows
Copy link
Member

Thanks @sunshy360.

Are you asking us to change Pact or are these intended for James? If it's for us, could you please create a separate issue explaining the problem and expected behaviour?

By the way, the host/address the server starts on is configurable, it need not be localhost. I believe any proxy environment vars should be respected but may be mistaken there.

@asishsahoo
Copy link

I too had the same problem while running in my machine. I took me a while to realise that the process is not exiting because of which when we run it next time, it's not getting the server instance and hence failing.
Try to find if any process running with the same port, if so kill that and try again:
Find:
sudo lsof -i :3000
Kill:
kill -9

Ideally there should be a clean way to kill the process once the tests are run.

@TimothyJones
Copy link
Contributor

The consumer tests should be closing the process down when finalise is called- can you share a bit more about your test setup?

@mefellows
Copy link
Member

Please make sure you call finalize which is responsible for shutting the service down.

@asishsahoo
Copy link

asishsahoo commented Jun 22, 2021

The consumer tests should be closing the process down when finalise is called- can you share a bit more about your test setup?

Thanks for the quick response.
I have the setup.js file where am setting up the mock provider for the consumer as below:

global.port = 8001;
global.provider = new Pact({
	cors: true,
	port: global.port,
	log: path.resolve(process.cwd(), 'test/pact/logs', 'pactserver-integration.log'),
	loglevel: 'debug',
	dir: path.resolve(process.cwd(), 'test/pact/pacts'),
	pactfileWriteMode: 'update',
	consumer: 'clinician-graphql-consumer',
	provider: 'clinician-client-provider',
	host: 'localhost',
	timeout: 5000,
	spec: 2,
});

and I have another file called jest-wrapper.js where I have defined the beforeAll and afterAll as below:

beforeAll((done) => {
	global.provider.setup().then(() => done());
});

afterAll((done) => {
	global.provider.finalize().then(
		() => done(),
		(err) => done.fail(err)
	);
});

and i have defined a script in package.json file to run the tests as below:

"pact:test:consumer": "rimraf /test/pact/pacts && jest --setupFiles=./test/pact/setup.js --setupTestFrameworkScriptFile=./test/pact/jest-wrapper.js --testMatch \"**/*.pacttest.ts\" --detectOpenHandles \"^.+pacttest\\.ts$\"",
I see when I run the above tests in my local, it works fine. But my project pipeline works over a docker where it tries to run all these test on the container and that's causing issues as below:

TypeError: Cannot read property 'writePact' of undefined

       5 | 
       6 | afterAll((done) => {
    >  7 |      global.provider.finalize().then(
         |                      ^
       8 |              () => done(),
       9 |              (err) => done.fail(err)
      10 |      );

Looks like there is some conflict with the port or the mock service instance is not getting started/closed. Any idea?

@asishsahoo
Copy link

Can some one plz help on my above request. My pacts are failing in docker while they work fine in local.
I have no idea what's going wrong. Any sort of help will be heartily appreciated.

@mefellows
Copy link
Member

If you could please raise a separate issue using the issue template, providing log files, reproducable examples etc., rather than piling onto an existing issue that would help.

@asishsahoo
Copy link

I think I found the root cause. so all good now. Thanks.
It was because of the slow response that I was getting while running over a docker because of which it was not getting the mock service and hence failing.

I added a timeout to my script and that made it work.
--testTimeout=30000
https://stackoverflow.com/questions/49603939/message-async-callback-was-not-invoked-within-the-5000-ms-timeout-specified-by

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

6 participants