Hi guys, I know there was a similar issue but it is marked closed so I decided to start a new one.
I am very new to pact. I have a little tests to run just the consumer side test and it fails with error:
Error: connect ECONNREFUSED 127.0.0.1:8989
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
My .log file is empty and nothing is being added there when I run the tests.
The actual code looks like this:
const Pact = require("@pact-foundation/pact").Pact;
const path = require('path')
const request = require('superagent');
describe("API me", () => {
const MOCK_SERVER_PORT = 8989;
const API_HOST = `http://localhost:${MOCK_SERVER_PORT}`;
const provider = new Pact({
port: MOCK_SERVER_PORT,
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
dir: path.resolve(process.cwd(), 'pacts'),
spec: 2,
consumer: 'Members',
provider: 'API',
logLevel: 'DEBUG',
cors: true
})
beforeAll((done) => {
provider.setup().then(done);
});
afterAll((done) => {
provider.verify()
.then(provider.finalize)
.then(done);
});
describe("works", () => {
beforeEach((done) => {
provider.addInteraction({
state: 'I want to fetch my user information before login',
uponReceiving: 'a request to api/me',
withRequest: {
method: 'GET',
path: '/me',
headers: {
'Accept': 'application/json'
}
},
willRespondWith: {
status: 401,
headers: {
'Content-Type': 'application/json'
}
}
}).then(done, done);
});
// add expectations
test('returns a sucessful body', done => {
request
.get(`${API_HOST}/me`)
.set({'Accept': 'application/json'})
.then((res) => {
expect(response.status).toEqual(401)
}).then(done);
});
})
})
Do you know what might be an issue?
Are you positive the provider.setup() is being called before the test executes? This is the bit that starts a service on the given port 8989, so it's possible the server either isn't starting correctly or at all.
Can you also please check to see if there is any process running on port 8989? It should be a different error if this is the case, but good to be sure.
Also, is there more output in the terminal that you can share? It might be enlightening to see what arguments were given to the node process that starts the mock server, this should definitely be visible with DEBUG logs.
Sure! Thank you for the fast response.
When i run npm run test I see this:
[2017-12-21T22:15:24.351Z] INFO: [email protected]/45185 on Kateynas-MacBook-Pro.local:
Creating Pact Server with options:
consumer = Members,
cors = true,
dir = /Users/kateyna/web_app/jupiter/apps/test-runner/pacts,
host = 127.0.0.1,
log = /Users/kateyna/web_app/jupiter/apps/test-runner/logs/mockserver-integration.log,
pactFileWriteMode = overwrite,
port = 8989,
provider = API,
spec = 2,
ssl = false,
sslcert = ,
sslkey =
When I do 'Debug' I just see so much setting not actually related to my tests =(( But then I get this:
[2017-12-21T22:15:24.367Z] INFO: [email protected]/45185 on Kateynas-MacBook-Pro.local: Created './platforms/darwin/bin/pact-mock-service service --consumer 'Members' --cors 'true' --pact_dir '/Users/kateyna/web_app/jupiter/apps/test-runner/pacts' --host '127.0.0.1' --log '/Users/kateyna/web_app/jupiter/apps/test-runner/logs/mockserver-integration.log' --pact-file-write-mode 'overwrite' --port '8989' --provider 'API' --pact_specification_version '2'' process with PID: 45198
RUNS ../../contract_tests/members/api_me.spec.js
/Users/kateyna/web_app/jupiter/node_modules/react-scripts-ts/scripts/test.js:22
throw err;
^
Error: connect ECONNREFUSED 127.0.0.1:8989
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
error Command failed with exit code 1.
So seems like the server actually starts.. but then my .log file is empty =(
If you could, the entire terminal output would be really helpful to see the sequence of things - I'm happy to wade through it all ;)
It's surprising that there is nothing in /Users/kateyna/web_app/jupiter/apps/test-runner/logs/mockserver-integration.log, so that tells me it probably got shut down before the tests were able to do anything.
Also, if you could upload a complete example (including package.json and everything) I can download and try to reproduce.
So the full output looks like this:
[2017-12-21T22:15:24.351Z] INFO: [email protected]/45185 on Kateynas-MacBook-Pro.local:
Creating Pact Server with options:
consumer = Members,
cors = true,
dir = /Users/kateyna/web_app/jupiter/apps/test-runner/pacts,
host = 127.0.0.1,
log = /Users/kateyna/web_app/jupiter/apps/test-runner/logs/mockserver-integration.log,
pactFileWriteMode = overwrite,
port = 8989,
provider = API,
spec = 2,
ssl = false,
sslcert = ,
sslkey =
[2017-12-21T22:15:24.363Z] DEBUG: [email protected]/45185 on Kateynas-MacBook-Pro.local: Starting pact binary with '/bin/sh,[object Object],{"cwd":"/Users/kateyna/web_app/jupiter/node_modules/@pact-foundation/pact-standalone","detached":true,"env":{"npm_config_save_dev":"","npm_config_legacy_bundling":"","npm_config_dry_run":"","npm_config_viewer":"man","npm_config_only":"","npm_config_browser":"","npm_package_gitHead":"2fe3b93b1fc30106270d4b58b8ba5f80bb9f906e","npm_config_also":"","npm_package_scripts_cypress_open_members":"cypress open --project ./cypress_e2e/members_app","npm_config_rollback":"true","TERM_PROGRAM":"Apple_Terminal","rvm_bin_path":"/Users/kateyna/.rvm/bin","npm_config_usage":"","npm_package_devDependencies__pact_foundation_pact":"^5.3.0","SAUCE_USERNAME":"enaumenko","NODE":"/usr/local/Cellar/node/8.9.1/bin/node","npm_config_version_git_tag":"true","npm_package_homepage":"https://github.com/pelotoncycle/jupiter#readme","npm_package_scripts_cypress_open_members_uat":"cypress open --project ./cypress_e2e/members_app -c baseUrl=https://uat-members.onepeloton.com -e webAppUrl=https://www.onepeloton.com/login,api=https://api.onepeloton.com","GEM_HOME":"/Users/kateyna/.rvm/gems/ruby-2.4.1","npm_config_globalignorefile":"/usr/local/etc/npmignore","SHELL":"/bin/bash","TERM":"xterm-256color","npm_config_shell":"/bin/bash","npm_config_maxsockets":"50","npm_config_init_author_url":"","npm_config_shrinkwrap":"true","npm_config_parseable":"","npm_package_devDependencies_tslint_eslint_rules":"^4.1.1","npm_package_devDependencies_tslint":"^5.8.0","TMPDIR":"/var/folders/8z/l5j3q5jd3wj4x97llx2z92h80000gn/T/","IRBRC":"/Users/kateyna/.rvm/rubies/ruby-2.4.1/.irbrc","npm_package_devDependencies__types_enzyme_adapter_react_16":"^1.0.0","npm_config_init_license":"MIT","npm_package_scripts_lint":"tslint --project . --format codeFrame","Apple_PubSub_Socket_Render":"/private/tmp/com.apple.launchd.icDDW6xdUC/Render","npm_config_if_present":"","TERM_PROGRAM_VERSION":"388.1.1","npm_config_sign_git_tag":"","npm_config_init_author_email":"","npm_config_cache_max":"Infinity","npm_package_scripts_start_preorder_prod":"REACT_APP_API_ENV=prod yarn start-preorder","npm_config_long":"","npm_config_local_address":"","npm_config_git_tag_version":"true","npm_config_cert":"","npm_package_scripts_prepush":"yarn lint","TERM_SESSION_ID":"7D25AA4E-C60F-402D-B3C4-E58F958FB426","MY_RUBY_HOME":"/Users/kateyna/.rvm/rubies/ruby-2.4.1","npm_config_registry":"https://registry.yarnpkg.com","npm_config_npat":"","npm_config_fetch_retries":"2","npm_package_private":"true","npm_package_devDependencies_jest_styled_components":"^4.9.0","npm_package_repository_url":"git+ssh://[email protected]/pelotoncycle/jupiter.git","npm_config_versions":"","npm_config_message":"%s","npm_config_key":"","npm_package_readmeFilename":"README.md","npm_package_devDependencies_pact":"^4.3.1","npm_package_dependencies_react_scripts_ts":"2.8.0","npm_package_description":"Monorepo for peloton web projects.","USER":"kateyna","npm_package_devDependencies_enzyme_adapter_react_16":"^1.0.4","npm_package_config_lintFiles":"'apps/**/*.ts*' 'packages/**/*.ts*'","npm_package_devDependencies_selenium_standalone":"^6.11.0","npm_package_license":"MIT","npm_package_scripts_start_members_qa":"REACT_APP_API_ENV=qa yarn start-members","_system_type":"Darwin","npm_config_globalconfig":"/usr/local/etc/npmrc","npm_config_always_auth":"","rvm_path":"/Users/kateyna/.rvm","SSH_AUTH_SOCK":"/private/tmp/com.apple.launchd.jchABipb5a/Listeners","npm_package_devDependencies__types_jest":"^21.1.4","npm_package_devDependencies_which":"^1.3.0","__CF_USER_TEXT_ENCODING":"0x1F5:0x0:0x0","npm_execpath":"/usr/local/lib/node_modules/npm/bin/npm-cli.js","npm_config_global_style":"","npm_config_cache_lock_retries":"10","npm_package_scripts_start_preorder":"cd apps/preorder && yarn start","npm_config_cafile":"","npm_package_scripts_cypress_run_members":"cypress run --project ./cypress_e2e/members_app","npm_package_scripts_cypress_run_members_uat":"cypress run --project ./cypress_e2e/members_app -c baseUrl=https://uat-members.onepeloton.com -e webAppUrl=https://www.onepeloton.com/login,api=https://api.onepeloton.com","npm_package_author_name":"Web Team","npm_config_heading":"npm","npm_config_proprietary_attribs":"true","npm_config_fetch_retry_mintimeout":"10000","npm_package_scripts_cypress_open_preorder":"cypress open --project ./cypress_e2e/preorder_app","rvm_prefix":"/Users/kateyna","npm_config_json":"","npm_config_access":"","npm_config_argv":"{\"remain\":[],\"cooked\":[\"run\",\"test\"],\"original\":[\"run\",\"test\"]}","PATH":"/Users/kateyna/web_app/jupiter/apps/test-runner/node_modules/.bin:/Users/kateyna/.config/yarn/link/node_modules/.bin:/Users/kateyna/web_app/jupiter/apps/test-runner/node_modules/.bin:/Users/kateyna/.config/yarn/link/node_modules/.bin:/usr/local/Cellar/node/8.9.1/lib/node_modules/npm/bin/node-gyp-bin:/usr/local/Cellar/node/8.9.1/bin/node_modules/npm/bin/node-gyp-bin:/usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/kateyna/web_app/jupiter/node_modules/.bin:/usr/local/Cellar/node/8.9.1/bin:/Users/kateyna/.rvm/gems/ruby-2.4.1/bin:/Users/kateyna/.rvm/gems/ruby-2.4.1@global/bin:/Users/kateyna/.rvm/rubies/ruby-2.4.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/kateyna/.rvm/bin","npm_config_https_proxy":"","npm_config_engine_strict":"","npm_config_description":"true","_":"/usr/local/Cellar/node/8.9.1/bin/node","npm_config_userconfig":"/Users/kateyna/.npmrc","npm_config_init_module":"/Users/kateyna/.npm-init.js","npm_package_scripts_postmerge":"yarn","npm_package_devDependencies__types_enzyme":"^3.1.3","npm_package_devDependencies_cypress":"1.1.4","PWD":"/Users/kateyna/web_app/jupiter/apps/test-runner","npm_config_user":"","npm_config_node_version":"6.11.1","npm_package_bugs_url":"https://github.com/pelotoncycle/jupiter/issues","npm_lifecycle_event":"test","npm_config_save":"","npm_config_editor":"vi","npm_package_repository_type":"git","npm_package_name":"test-runner","LANG":"en_US.UTF-8","npm_config_tag":"latest","npm_config_progress":"true","npm_config_global":"","npm_package_scripts_start":"cd apps/members && yarn start","npm_package_scripts_start_members":"cd apps/members && yarn start","npm_package_devDependencies_raf":"^3.4.0","npm_config_optional":"true","XPC_FLAGS":"0x0","_system_arch":"x86_64","npm_package_devDependencies_enzyme":"^3.1.1","npm_config_force":"","npm_config_bin_links":"true","npm_config_searchopts":"","_system_version":"10.12","npm_config_depth":"Infinity","npm_package_scripts_tslint":"tslint","npm_package_scripts_start_members_prod":"yarn start-members","npm_config_searchsort":"name","npm_config_rebuild_bundle":"true","npm_package_version":"0.1.0","XPC_SERVICE_NAME":"0","npm_config_unicode":"true","rvm_version":"1.29.3 (latest)","npm_package_scripts_start_preorder_qa":"yarn start-preorder","SHLVL":"3","HOME":"/Users/kateyna","npm_config_fetch_retry_maxtimeout":"60000","npm_package_scripts_test":"node ./scripts/test --scripts-version react-scripts-ts --env=jsdom","npm_package_scripts_storybook":"cd apps/storybook && yarn storybook","npm_config_tag_version_prefix":"v","npm_config_strict_ssl":"true","npm_config_save_prefix":"^","npm_config_loglevel":"warn","npm_config_ca":"","npm_config_version_git_message":"v%s","npm_config_save_exact":"","npm_config_group":"20","npm_config_fetch_retry_factor":"10","npm_config_dev":"","npm_package_devDependencies_husky":"^0.14.3","npm_config_version":"","npm_config_cache_lock_stale":"60000","npm_config_cache_min":"10","YARN_WRAP_OUTPUT":"false","npm_config_searchexclude":"","npm_config_cache":"/Users/kateyna/.npm","LOGNAME":"kateyna","npm_lifecycle_script":"node ./scripts/test --scripts-version react-scripts-ts --env=jsdom","npm_config_color":"true","npm_package_devDependencies_tslint_react":"^3.2.0","PREFIX":"/usr/local","npm_config_proxy":"","npm_package_author_email":"[email protected]","GEM_PATH":"/Users/kateyna/.rvm/gems/ruby-2.4.1:/Users/kateyna/.rvm/gems/ruby-2.4.1@global","SAUCE_ACCESS_KEY":"66efb05b-27bc-4c2d-987f-c1d5fc707622","npm_config_save_optional":"","npm_config_version_git_sign":"","npm_config_ignore_scripts":"","npm_config_user_agent":"yarn/1.3.2 npm/? node/v6.11.1 darwin x64","npm_config_cache_lock_wait":"10000","npm_config_production":"","DISPLAY":"/private/tmp/com.apple.launchd.CWGySNQpmr/org.macosforge.xquartz:0","npm_config_save_bundle":"","npm_config_ignore_optional":"","npm_config_umask":"0022","npm_config_init_version":"1.0.0","npm_package_workspaces_2":"packages/@peloton/*","npm_config_scope":"","npm_config_init_author_name":"","npm_config_git":"git","npm_package_workspaces_3":"packages/@ecomm/*","RUBY_VERSION":"ruby-2.4.1","npm_config_unsafe_perm":"true","npm_config_tmp":"/var/folders/8z/l5j3q5jd3wj4x97llx2z92h80000gn/T","npm_config_onload_script":"","npm_package_workspaces_0":"apps/*","_system_name":"OSX","npm_config_version_tag_prefix":"v","npm_package_dependencies_react_app_rewired":"^1.3.8","npm_node_execpath":"/usr/local/Cellar/node/8.9.1/bin/node","npm_config_link":"","npm_config_prefix":"/usr/local","npm_package_workspaces_1":"packages/@members/*","NODE_ENV":"test","NODE_PATH":"","BABEL_ENV":"test","PUBLIC_URL":""}}'
[2017-12-21T22:15:24.367Z] INFO: [email protected]/45185 on Kateynas-MacBook-Pro.local: Created './platforms/darwin/bin/pact-mock-service service --consumer 'Members' --cors 'true' --pact_dir '/Users/kateyna/web_app/jupiter/apps/test-runner/pacts' --host '127.0.0.1' --log '/Users/kateyna/web_app/jupiter/apps/test-runner/logs/mockserver-integration.log' --pact-file-write-mode 'overwrite' --port '8989' --provider 'API' --pact_specification_version '2'' process with PID: 45198
RUNS ../../contract_tests/members/api_me.spec.js
/Users/kateyna/web_app/jupiter/node_modules/react-scripts-ts/scripts/test.js:22
throw err;
^
Error: connect ECONNREFUSED 127.0.0.1:8989
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
error Command failed with exit code 1.
Created repro repo here: https://github.com/mefellows/test-pact-jest-repro
Can't reproduce, are you able to make it fail for us?
FWIW working with @elliottmurray who has the same issue. The above repo works for me, fails for him. He has dockerised the project to remove OS and environmental issues.
One thing to note is that I'm running 10.11.5 (El Capitan) and not High Sierra. Possibly something to poke at.
Here is the dockerfile I used. You can build/run it with
FROM node:8 AS base
RUN mkdir -p /app && npm config set strict-ssl false
COPY ["package.json", "/app/"]
WORKDIR /app
RUN npm install
COPY . .
FROM base AS package
CMD 'npm run test'
Build and run with:
```shell
docker build -t pact-jest .
docker run -it pact-jest npm t
````
hey guys, first A HUGE thank you for looking into this.
I cloned the test-pact-jest-repo to a new directory, ran npm i and then ran tests. Their failed for me with same error
Test Suites: 1 failed, 1 total
Tests: 2 failed, 2 total
Snapshots: 0 total
Time: 5.964s
Ran all test suites.
[2017-12-22T16:27:50.766Z] INFO: [email protected]/46032 on Kateynas-MacBook-Pro.local:
Deleting Pact Server with options:
consumer = MyConsumer,
cors = false,
dir = /Users/kateyna/test_pact/test-pact-jest-repro/pacts,
host = 127.0.0.1,
log = /Users/kateyna/test_pact/test-pact-jest-repro/logs/mockserver-integration.log,
pactFileWriteMode = overwrite,
port = 8989,
provider = MyProvider,
spec = 2,
ssl = false,
sslcert = ,
sslkey =
console.error node_modules/@pact-foundation/pact/pact.js:103
console.error node_modules/@pact-foundation/pact/pact.js:104
Pact verification failed!
console.error node_modules/@pact-foundation/pact/pact.js:105
Error: connect ECONNREFUSED 127.0.0.1:8989
Now I ran the docker version that @elliottmurray sent. All tests ran for me. So seems like it's OS related
So I updated my system to macOS Sierra 10.13.2 and was able to run the test repo without any issues.. Weird. Now I am trying to run my actual tests.
No worries @katerynae, it's a weird one!
Please let us know how you get on after the upgrade.
On another note, presumably you've tried different ports just to rule out an issue with 8989?
I can confirm the OSX upgrade to Sierra 10.13.2 fixed the sample tests for me too. I'll have a crack at my tests tomorrow coz I have nothing better to do Xmas Eve....!
So weird! I've looked at the release notes and nothing jumps at me.
Hey guys,
So updating OS work for me. Though while working on tests I had another issue.
Even after all my assertions passed my tests would fail with Error: [Object object]
This issue comes from Jest and is related to this opened issue https://github.com/facebook/jest/issues/3839
I updated my "jest-cli": "21.0.0", to "jest-cli": "^20.0.4" and works fine now.
I guess it is worth mentioning and maybe you can update your docs with it.
And thank you a lot for the help! 馃
Hey,
I had the same issues with v21. We managed to get 22.0.4 working. I'm going to do a fork on the example for jest as I found a few other issues as well with multiple test files.
@elliottmurray that would be awesome! Can you send me the link when you have that fork?
I am still having some issues to make it run with jest. We using typescript so in out test runner with jest conf we need to transpile and then I get this [Object object] error again... If I run it just with jest it works fine but then I can't import Typescript libraries =(
Thanks for that PR @elliottmurray. Once it's merged, i'll close this issue off.
This is the fork/branch. Just going through review now (as there are a few funky things in there)
Those jest changes are in - closing. Thanks all!
In case anyone of you run into the same error with me, you could have a try on the timeout config, 10s maybe not enough, try:
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;