When running the jest example I'm getting
Unhandled promise rejection { Error: connect ECONNREFUSED 127.0.0.1:8989
at Object.exports._errnoException (util.js:1050:11)
at exports._exceptionWithHostPort (util.js:1073:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1093:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 8989,
config:
{ transformRequest: { '0': [Function: transformRequest] },
transformResponse: { '0': [Function: transformResponse] },
headers: { Accept: 'application/json', 'User-Agent': 'axios/0.14.0' },
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
method: 'GET',
baseURL: 'http://localhost:8989',
url: 'http://localhost:8989/dogs',
data: undefined },
response: undefined }
Has anyone seen anything similar?
I've cloned the repo and followed the README but am still seeing this. Non-jest examples are passing. I can see the pact server come up on that port and get torn down at the end.
Environment:
OSX
node 7.10
I haven't seen this before, no. Could you please enabling debug logging and supply any logs for us to look at?
Are you just cloning and running the examples?
Yup, just clone and then npm i, npm t
.log files didn't have anything meaningful
[2017-07-18T22:21:08.601Z] DEBUG: [email protected]/25504 on name.local:
[2017-07-18 15:21:08] INFO WEBrick 1.3.1
[2017-07-18 15:21:08] INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13]
[2017-07-18T22:21:08.603Z] DEBUG: [email protected]/25504 on
[2017-07-18 15:21:08] INFO WEBrick::HTTPServer#start: pid=25512 port=8989
[2017-07-18T22:21:18.222Z] INFO: [email protected]/25504 on name.local: Removing Pact with PID: 25512
[2017-07-18T22:21:18.224Z] DEBUG: [email protected]/25504 on name.local:
[2017-07-18 15:21:18] INFO going to shutdown ...
[2017-07-18 15:21:18] INFO WEBrick::HTTPServer#start done.
[2017-07-18T22:21:18.227Z] INFO: [email protected]/25504 on name.local:
Deleting Pact Server with options:
port = 8989,
host = localhost,
dir = /Users/name/dev/pact-js/examples/jest/pacts,
ssl = false,
sslcert = false,
sslkey = false,
cors = false,
log = /Users/name/dev/pact-js/examples/jest/logs/mockserver-integration.log,
spec = 2,
consumer = ,
provider =
FAIL __tests__/index.spec.js (16.587s)
Dog's API
works
✕ returns a sucessful body (10004ms)
✕ successfully verifies (12ms)
● Dog's API › works › returns a sucessful body
Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at ontimeout (timers.js:380:14)
at tryOnTimeout (timers.js:244:5)
at Timer.listOnTimeout (timers.js:214:5)
Nothing in this file: /Users/name/dev/pact-js/
examples/jest/logs/mockserver-integration.log?
On Wed, Jul 19, 2017 at 8:26 AM, willworden notifications@github.com
wrote:
Yup, just clone and then npm i, npm t
.log files didn't have anything meaningful
[2017-07-18T22:21:08.601Z] DEBUG: [email protected]/25504 on name.local:
[2017-07-18 15:21:08] INFO WEBrick 1.3.1
[2017-07-18 15:21:08] INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13][2017-07-18T22:21:08.603Z] DEBUG: [email protected]/25504 on .local:
[2017-07-18 15:21:08] INFO WEBrick::HTTPServer#start: pid=25512 port=8989[2017-07-18T22:21:18.222Z] INFO: [email protected]/25504 on name.local:
Removing Pact with PID: 25512
[2017-07-18T22:21:18.224Z] DEBUG: [email protected]/25504 on name.local:
[2017-07-18 15:21:18] INFO going to shutdown ...
[2017-07-18 15:21:18] INFO WEBrick::HTTPServer#start done.[2017-07-18T22:21:18.227Z] INFO: [email protected]/25504 on name.local:
Deleting Pact Server with options:
port = 8989,
host = localhost,
dir = /Users/name/dev/pact-js/examples/jest/pacts,
ssl = false,
sslcert = false,
sslkey = false,
cors = false,
log = /Users/name/dev/pact-js/examples/jest/logs/mockserver-
integration.log,
spec = 2,
consumer = ,
provider =
FAIL tests/index.spec.js (16.587s)
Dog's API
works
✕ returns a sucessful body (10004ms)
✕ successfully verifies (12ms)● Dog's API › works › returns a sucessful body
Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at ontimeout (timers.js:380:14)
at tryOnTimeout (timers.js:244:5)
at Timer.listOnTimeout (timers.js:214:5)—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/pact-foundation/pact-js/issues/67#issuecomment-316216351,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AADSjJVmVAfghlEYA9YhtwCladSWGVJIks5sPTEbgaJpZM4Ob339
.
--
Matt Fellows
I, [2017-07-18T15:21:18.210426 #25512] INFO -- : Verifying - interactions matched for example ""
I, [2017-07-18T15:21:18.215994 #25512] INFO -- : Cleared interactions before example ""
I, [2017-07-18T15:21:18.221788 #25512] INFO -- : Writing pact with details {:consumer=>{:name=>"MyConsumer"}, :provider=>{:name=>"MyProvider"}, :pactfile_write_mode=>"overwrite"}
That's the whole lot?
Interesting, that tells me that interactions were never registered in the first place with the mock server but the verification and shutdown stuff did.
I haven't got the code in front of me but feels like maybe a logic flaw or a mishandled promise.
Hi @mefellows,
I have a similar problem as well. When I run my contract tests, I get the following errors:
[2017-08-21T14:01:26.316Z] INFO: [email protected]/70733 on ip-xx-x-xxx-xxx.us-west-2.compute.internal: Creating Pact with PID: 70739
(node:70733) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): RequestError: Error: connect ECONNREFUSED 127.0.0.1:8989
(node:70733) [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.
(node:70733) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): RequestError: Error: connect ECONNREFUSED 127.0.0.1:8989
(node:70733) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: Cannot read property 'json' of undefined
(node:70733) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): RequestError: Error: connect ECONNREFUSED 127.0.0.1:8989
FAIL src/contract-tests/contract.spec.js (6.499s)
● contract tests › specDescribe › spec
Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at pTimeout (node_modules/jest-jasmine2/build/queueRunner.js:53:21)
at ontimeout (timers.js:469:11)
at tryOnTimeout (timers.js:304:5)
at Timer.listOnTimeout (timers.js:264:5)
contract tests
specDescribe
✕ firstSpec (5050ms)
✓ successfully verifies (15ms)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 passed, 2 total
Snapshots: 0 total
Time: 7.222s, estimated 11s
Ran all test suites matching /^/**/contract\-tests/contract\.spec\.js$/ with tests matching "^contract tests ".
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at pTimeout (node_modules/jest-jasmine2/build/queueRunner.js:53:21)
at ontimeout (timers.js:469:11)
at tryOnTimeout (timers.js:304:5)
at Timer.listOnTimeout (timers.js:264:5)
[2017-08-21T14:01:32.438Z] INFO: [email protected]/70733 on ip-xx-x-xxx-xxx.us-west-2.compute.internal: Removing Pact with PID: 70739
[2017-08-21T14:01:32.442Z] INFO: [email protected]/70733 on ip-xx-x-xxx-xxx.us-west-2.compute.internal:
Deleting Pact Server with options:
port = 8989,
host = localhost,
dir = /xxx/pacts,
ssl = false,
sslcert = false,
sslkey = false,
cors = false,
log = /xxx/logs/Pact.log,
spec = 2,
consumer = ,
provider =
Here's the output from the pact.log file:
I, [2017-08-21T10:01:27.384265 #70739] INFO -- : Received OPTIONS request for mock service administration endpoint POST /interactions. Returning CORS headers: {"Access-Control-Allow-Origin":"null","Access-Control-Allow-Headers":"X-Pact-Mock-Service","Access-Control-Allow-Methods":"DELETE, POST, GET, HEAD, PUT, TRACE, CONNECT, PATCH"}.
I, [2017-08-21T10:01:27.390458 #70739] INFO -- : Registered expected interaction GET /api/endpoint
D, [2017-08-21T10:01:27.390617 #70739] DEBUG -- : {
"description": "spec description",
"request": {
"method": "GET",
"path": "/api/endpoint",
"headers": {
"Accept": "application/json",
"Cookie": "username=user; role=role"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json;charset=UTF-8"
},
"body": [
{
"id": 1,
"data": "Some Data",
"submissionDate": "2016-02-11T09:46:56"
}
]
}
}
I, [2017-08-21T10:01:32.418255 #70739] INFO -- : Received OPTIONS request for mock service administration endpoint POST /interactions. Returning CORS headers: {"Access-Control-Allow-Origin":"null","Access-Control-Allow-Headers":"X-Pact-Mock-Service","Access-Control-Allow-Methods":"DELETE, POST, GET, HEAD, PUT, TRACE, CONNECT, PATCH"}.
I, [2017-08-21T10:01:32.422303 #70739] INFO -- : Registered expected interaction GET /api/endpoint
D, [2017-08-21T10:01:32.422415 #70739] DEBUG -- : {
"description": "spec description",
"request": {
"method": "GET",
"path": "/api/endpoint",
"headers": {
"Accept": "application/json",
"Cookie": "username=user; role=role"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json;charset=UTF-8"
},
"body": [
{
"id": 1,
"data": "Some Data",
"submissionDate": "2016-02-11T09:46:56"
}
]
}
}
I, [2017-08-21T10:01:32.432390 #70739] INFO -- : Received OPTIONS request for mock service administration endpoint POST /pact. Returning CORS headers: {"Access-Control-Allow-Origin":"null","Access-Control-Allow-Headers":"X-Pact-Mock-Service","Access-Control-Allow-Methods":"DELETE, POST, GET, HEAD, PUT, TRACE, CONNECT, PATCH"}.
I, [2017-08-21T10:01:32.436000 #70739] INFO -- : Writing pact with details {:consumer=>{:name=>"My App"}, :provider=>{:name=>"MyApp Service"}, :pactfile_write_mode=>"overwrite"}
and here are my specs:
import path from 'path';
import Pact from 'pact';
import {getData} from '../shared/api';
describe('contract tests', () => {
const MOCK_SERVER_PORT = 8989;
const provider = Pact({
consumer: 'My App',
provider: 'MyApp Service',
port: MOCK_SERVER_PORT,
log: path.resolve(process.cwd(), 'logs', 'Pact.log'),
dir: path.resolve(process.cwd(), 'pacts'),
logLevel: 'INFO',
spec: 2
});
const EXPECTED_BODY = [{
id: 1,
data" "Some Data",
submissionDate: "2016-02-11T09:46:56"
}];
beforeAll(() => provider.setup());
afterAll(() => provider.finalize());
describe('getData', () => {
beforeEach((done) => {
provider.addInteraction({
state: '',
uponReceiving: 'a request for Data',
withRequest: {
method: 'GET',
path: '/api/endpoint',
headers: {
'Accept': 'application/json',
'Cookie': 'username=user; role=role'
}
},
willRespondWith: {
status: 200,
headers: {'Content-Type': 'application/json;charset=UTF-8'},
body: EXPECTED_BODY
}
}).then(done, done);
});
test('failing spec', (done) => {
return getData() // <- this method would make the remote http call
.then((someData) => {
expect(Array.isArray(someData)).toBe(true);
done();
})
});
test('passing spec', () => {
provider.verify()
});
});
});
One thing that jumps straight up is that provider.setup() is a promise so in here:
beforeAll(() => provider.setup());
you're asynchronously setting up the mock server but there's no callback to hit when the promise succeeds.
Can you make sure you handle it with the done callback on beforeAll() and let us know what's the status then?
Looking at the Jest example maybe it needs a fix there too but let's start with helping you solve this first :)
Hi @lirantal
I modified the beforeAll to be:
beforeAll((done) => {
provider.setup().then(done);
});
And I still get the same error:
Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at pTimeout (node_modules/jest-jasmine2/build/queueRunner.js:53:21)
at ontimeout (timers.js:469:11)
at tryOnTimeout (timers.js:304:5)
at Timer.listOnTimeout (timers.js:264:5)
and the tests fails
can you move provider.verify() also to afterAll() and call the done callback as we did with beforeAll?
@lirantal, I tried this
afterAll((done) => {
provider.finalize();
provider.verify().then(done);
});
and got a different failure:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at pTimeout (node_modules/jest-jasmine2/build/queueRunner.js:53:21)
at ontimeout (timers.js:469:11)
at tryOnTimeout (timers.js:304:5)
at Timer.listOnTimeout (timers.js:264:5)
console.error node_modules/pact/src/pact.js:118
console.error node_modules/pact/src/pact.js:119
Pact verification failed!
console.error node_modules/pact/src/pact.js:120
Actual interactions do not match expected interactions for mock MockService.
Missing requests:
GET /api/endpoint
See /***/logs/Pact.log for details.
which I think can be resolved by fixing my implementation for the spec?
Edit
The pact.log file:
I, [2017-08-21T11:31:19.980016 #73854] INFO -- : Received OPTIONS request for mock service administration endpoint POST /interactions. Returning CORS headers: {"Access-Control-Allow-Origin":"null","Access-Control-Allow-Headers":"X-Pact-Mock-Service","Access-Control-Allow-Methods":"DELETE, POST, GET, HEAD, PUT, TRACE, CONNECT, PATCH"}.
I, [2017-08-21T11:31:19.985606 #73854] INFO -- : Registered expected interaction GET /api/requests
D, [2017-08-21T11:31:19.985853 #73854] DEBUG -- : {
"description": "a request for data",
"request": {
"method": "GET",
"path": "/api/endpoint",
"headers": {
"Accept": "application/json",
"Cookie": "username=user; role=role"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json;charset=UTF-8"
},
"body": [
{
"id": 1,
"data": "Some Data",
"submissionDate": "2016-02-11T09:46:56"
}
]
}
}
I, [2017-08-21T11:31:25.020759 #73854] INFO -- : Received OPTIONS request for mock service administration endpoint GET /interactions/verification. Returning CORS headers: {"Access-Control-Allow-Origin":"null","Access-Control-Allow-Headers":"X-Pact-Mock-Service","Access-Control-Allow-Methods":"DELETE, POST, GET, HEAD, PUT, TRACE, CONNECT, PATCH"}.
W, [2017-08-21T11:31:25.025668 #73854] WARN -- : Verifying - actual interactions do not match expected interactions for example "".
Missing requests:
GET /api/endpoint
W, [2017-08-21T11:31:25.025696 #73854] WARN -- : Missing requests:
GET /api/endpoint
Ok hold on, you've got things a bit mixed up.
Please change as follows:
afterAll((done) => {
provider.verify()
.then(provider.finalize)
.then(() => done());
});
Then show us the logs :)
Ok. I changed the code like you said and here are the logs.
From the pact.log file:
I, [2017-08-21T14:40:28.140545 #79048] INFO -- : Received OPTIONS request for mock service administration endpoint POST /interactions. Returning CORS headers: {"Access-Control-Allow-Origin":"null","Access-Control-Allow-Headers":"X-Pact-Mock-Service","Access-Control-Allow-Methods":"DELETE, POST, GET, HEAD, PUT, TRACE, CONNECT, PATCH"}.
I, [2017-08-21T14:40:28.145842 #79048] INFO -- : Registered expected interaction GET /api/requests
D, [2017-08-21T14:40:28.146010 #79048] DEBUG -- : {
"description": "a request for data",
"providerState": "There is data",
"request": {
"method": "GET",
"path": "/api/endpoint",
"headers": {
"Accept": "application/json",
"Cookie": "username=user; role=role"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json;charset=UTF-8"
},
"body": [
{
"id": 1,
"data": "Some data",
"submissionDate": "2016-02-11T09:46:56"
}
]
}
}
I, [2017-08-21T14:40:33.175969 #79048] INFO -- : Received OPTIONS request for mock service administration endpoint GET /interactions/verification. Returning CORS headers: {"Access-Control-Allow-Origin":"null","Access-Control-Allow-Headers":"X-Pact-Mock-Service","Access-Control-Allow-Methods":"DELETE, POST, GET, HEAD, PUT, TRACE, CONNECT, PATCH"}.
W, [2017-08-21T14:40:33.180009 #79048] WARN -- : Verifying - actual interactions do not match expected interactions for example "".
Missing requests:
GET /api/endpoint
W, [2017-08-21T14:40:33.180036 #79048] WARN -- : Missing requests:
GET /api/endpoint
And from the console:
/usr/local/bin/node /***/node_modules/jest/bin/jest --config "{\"rootDir\":\"/***/config/../.\",\"setupFiles\":[\"./config/testSetup.js\"],\"collectCoverageFrom\":[\"src/**/*.{js,jsx}\"],\"testMatch\":[\"<rootDir>/src/**/?(*.)(spec|test).js?(x)\"],\"testEnvironment\":\"node\",\"testURL\":\"http://localhost\",\"transform\":{\"^.+\\.(js|jsx)$\":\"<rootDir>/node_modules/babel-jest\"},\"transformIgnorePatterns\":[\"[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$\",\"^/Applications/WebStorm.app/Contents/plugins/JavaScriptLanguage/helpers\"],\"moduleFileExtensions\":[\"js\",\"jsx\"],\"moduleNameMapper\":{\"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$\":\"<rootDir>/config/testSetup.js\"},\"collectCoverage\":true,\"coverageThreshold\":{\"global\":{\"branches\":75,\"functions\":75,\"lines\":75,\"statements\":75}},\"unmockedModulePathPatterns\":[\"^/Applications/WebStorm.app/Contents/plugins/JavaScriptLanguage/helpers\"]}" --colors --setupTestFrameworkScriptFile /Applications/WebStorm.app/Contents/plugins/JavaScriptLanguage/helpers/jest-intellij/lib/jest-intellij-jasmine.js --testPathPattern ^/Users/wole/Source/Alpine/mywall/mywall\-web/src/contract\-tests/contract\.spec\.js$ --testNamePattern "^contract tests getData "
console.error node_modules/dtrace-provider/dtrace-provider.js:36
{ Error: Cannot find module './build/Release/DTraceProviderBindings' from 'dtrace-provider.js'
at Resolver.resolveModule (/***/node_modules/jest-resolve/build/index.js:179:17)
at Resolver._getVirtualMockPath (/***/node_modules/jest-resolve/build/index.js:296:23)
at Resolver._getAbsolutPath (/***/node_modules/jest-resolve/build/index.js:279:10)
at Resolver.getModuleID (/***/node_modules/jest-resolve/build/index.js:252:31)
at Runtime._shouldMock (/***/node_modules/jest-runtime/build/index.js:574:37)
at Runtime.requireModuleOrMock (/***/node_modules/jest-runtime/build/index.js:402:14)
at Object.<anonymous> (/***/node_modules/dtrace-provider/dtrace-provider.js:18:23)
at Runtime._execModule (/***/node_modules/jest-runtime/build/index.js:513:13)
at Runtime.requireModule (/***/node_modules/jest-runtime/build/index.js:329:14)
at Runtime.requireModuleOrMock (/***/node_modules/jest-runtime/build/index.js:405:19) code: 'MODULE_NOT_FOUND' }
Creating Pact with PID: 79048
(node:79041) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): RequestError: Error: connect ECONNREFUSED 127.0.0.1:8989
(node:79041) [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.
(node:79041) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): RequestError: Error: connect ECONNREFUSED 127.0.0.1:8989
[2017-08-21T18:40:27.630Z] DEBUG: [email protected]/79041 on ip-10-3-128-189.us-west-2.compute.internal:
[2017-08-21 14:40:27] INFO WEBrick 1.3.1
[2017-08-21 14:40:27] INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13]
[2017-08-21T18:40:27.631Z] DEBUG: [email protected]/79041 on ip-10-3-128-189.us-west-2.compute.internal:
[2017-08-21 14:40:27] INFO WEBrick::HTTPServer#start: pid=79048 port=8989
(node:79041) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: Cannot read property 'json' of undefined
(node:79041) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): StatusCodeError: 500 - {"type":"Buffer","data":[65,99,116,117,97,108,32,105,110,116,101,114,97,99,116,105,111,110,115,32,100,111,32,110,111,116,32,109,97,116,99,104,32,101,120,112,101,99,116,101,100,32,105,110,116,101,114,97,99,116,105,111,110,115,32,102,111,114,32,109,111,99,107,32,77,111,99,107,83,101,114,118,105,99,101,46,10,10,77,105,115,115,105,110,103,32,114,101,113,117,101,115,116,115,58,10,9,71,69,84,32,47,97,112,105,47,114,101,113,117,101,115,116,115,10,10,83,101,101,32,47,85,115,101,114,115,47,119,111,108,101,47,83,111,117,114,99,101,47,65,108,112,105,110,101,47,109,121,119,97,108,108,47,109,121,119,97,108,108,45,119,101,98,47,108,111,103,115,47,112,97,99,116,46,108,111,103,32,102,111,114,32,100,101,116,97,105,108,115,46]}
(node:79041) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 5): Error: Pact verification failed - expected interactions did not match actual.
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at pTimeout (node_modules/jest-jasmine2/build/queueRunner.js:53:21)
at ontimeout (timers.js:469:11)
at tryOnTimeout (timers.js:304:5)
at Timer.listOnTimeout (timers.js:264:5)
console.error node_modules/pact/src/pact.js:118
console.error node_modules/pact/src/pact.js:119
Pact verification failed!
console.error node_modules/pact/src/pact.js:120
Actual interactions do not match expected interactions for mock MockService.
Missing requests:
GET /api/endpoint
See /***/logs/pact.log for details.
FAIL src/contract-tests/contract.spec.js (11.634s)
● contract tests › getData › a spec
Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at pTimeout (node_modules/jest-jasmine2/build/queueRunner.js:53:21)
at ontimeout (timers.js:469:11)
at tryOnTimeout (timers.js:304:5)
at Timer.listOnTimeout (timers.js:264:5)
contract tests
getData
✕ a spec (5058ms)
Ok so I think that at least now it's setup better and seems like your code which should call the mocked service (I assume it's in the getData) isn't really doing it's thing.
Yes, that's what we are suspecting. We are using whatwg-fetch for our API calls. When we console.log to debug, we see that the fetch method gets called but we never get a response. Here's a code snippet for the getData method:
export const getData = async () => {
const response = await get(REQUESTS_URL);
return response.json();
};
and the get method is:
import "whatwg-fetch";
export const get = (url) =>
fetch(url, {method: 'GET', credentials: 'include'});
Does it matter what port we set the mock server to run on? Should we set it to the same value as our webpack.config file?
I've never used whatwg-fetch but you should make sure the pact mock server runs on the same ip/port that you're sending the request to.
Yeah, we stopped the API service ( a Java Springboot application) and ran our tests with the mock server on the same port. The error we get is:
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): StatusCodeError: 500 - {"type":"Buffer","data":[65,99,116,117,97,108,32,105,110,116,101,114,97,99,116,105,111,110,115,32,100,111,32,110,111,116,32,109,97,116,99,104,32,101,120,112,101,99,116,101,100,32,105,110,116,101,114,97,99,116,105,111,110,115,32,102,111,114,32,109,111,99,107,32,77,111,99,107,83,101,114,118,105,99,101,46,10,10,77,105,115,115,105,110,103,32,114,101,113,117,101,115,116,115,58,10,9,71,69,84,32,47,97,112,105,47,114,101,113,117,101,115,116,115,10,10,83,101,101,32,47,85,115,101,114,115,47,119,111,108,101,47,83,111,117,114,99,101,47,65,108,112,105,110,101,47,109,121,119,97,108,108,47,109,121,119,97,108,108,45,119,101,98,47,108,111,103,115,47,112,97,99,116,46,108,111,103,32,102,111,114,32,100,101,116,97,105,108,115,46]}
Could we be missing some authorization headers? Is it possible to send cookies and other authorization headers in the consumer side spec?
Edit
We also get this error:
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): RequestError: Error: connect ECONNREFUSED 127.0.0.1:5000
Also, I'm not sure if I mentioned this earlier but we are using Jest to run specs.
Thanks for all of your help @lirantal!
@wolesolana there is no authorization required for the Mock Server - unless something has gone _really_ wrong, the mock server will typically respond with a 40x error, meaning it couldn't find an interaction to send back to you.
I think there are a couple more problems, though:
beforeEach block, meaning it will expect a call to /api/endpoint in both test('failing spec', ...) and test('passing spec',...). I'm guessing it's only required for the first test.whatwg-fetch is going to be making the call from a browser environment, so you'll need to make sure all appropriate CORS headers are setup. For one, you'll want to set cors: true when you setup Pact. You may also want to capture any pre-flight OPTIONS request as expected interactions (See https://github.com/pact-foundation/pact-js/issues/58 for a discussion on the appropriateness of whether these should be in your contract or not).You can see that your library is making the pre-flight request and then immediately failing, so I suspect this might be the issue:
I, [2017-08-21T11:31:25.020759 #73854] INFO -- : Received OPTIONS request for mock service administration endpoint GET /interactions/verification. Returning CORS headers: {"Access-Control-Allow-Origin":"null","Access-Control-Allow-Headers":"X-Pact-Mock-Service","Access-Control-Allow-Methods":"DELETE, POST, GET, HEAD, PUT, TRACE, CONNECT, PATCH"}.
Happy to help!
Don't want to steer off the discussion but even if the expectation is set in beforeAll() it doesn't necessarily require every test case to actually make a call.
Good catch on the browser environment I assumed this was running on a Node.js runtime.
Thanks @lirantal and @mefellows. I have moved the specs into beforeEach methods following @lirantal's suggestions. I added the cors option like you suggested so my Pact setup is now:
const provider = Pact({
consumer: "My App",
provider: "My Service",
port: MOCK_SERVER_PORT,
log: path.resolve(process.cwd(), "logs", "pact.log"),
dir: path.resolve(process.cwd(), "pacts"),
logLevel: "INFO",
spec: 2,
cors: true
});
Are there any extra settings I will need to modify in my Jest test configs in order to get whatwg-fetch to use the headers as I am getting the same failures as before.
My apologies, I've corrected my previous comment - i meant beforeEach will add the interaction as an expectation in each of the tests (not beforeAll which as stated only fires once).
Can you please share your project either on GitHub or as a gist, so that we can download and reproduce locally? It's much harder to diagnose and correct this way.
@mefellows, unfortunately I can't share the project due to confidentiality issues. I'll discuss with other members of my team with more ReactJS and Jest experience to try the suggestions you made. I might just be setting things up the wrong way.
I read the issue #58 that you shared and am still figuring out how to get the CORS settings right.
I seem to be experiencing this issue - tried copying the jest example verbatim but I receive the following:
Error: connect ECONNREFUSED 127.0.0.1:7979
Additionally, this is what I see in my pact log:
I, [2017-08-24T17:09:22.191269 #6917] INFO -- : Verifying - interactions matched for example ""
I, [2017-08-24T17:09:22.196971 #6917] INFO -- : Cleared interactions before example ""
I, [2017-08-24T17:09:22.201440 #6917] INFO -- : Writing pact with details {:consumer=>{:name=>"product-search-importer"}, :provider=>{:name=>"product"}, :pactfile_write_mode=>"overwrite"}
Thanks!
@mouserd are you able to share your entire pact.log file?
Closing due to inactivity. Please re-open if/when you're ready to progress the diagnosis - thanks!
The issue here is related to jasmine.DEFAULT_TIMEOUT_INTERVAL setting. The machine is too slow to spin up the pact mock server. Please change the default timeout interval to something bigger, like put this line on top of your specs:
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
I'm stuck in this error for over 2 days, and finally found 10s is not enough for my poor Mac. If any of you tried a lot of different ways, but still got the connect refuse error, maybe you can try:
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;
My case: MacOs 10.13.4 + docker + Typescript + Jest + Axios
A minimum working version could be:
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;
const port = 9999;
const axiosClient = axios.create({
baseURL: `http://127.0.0.1:${port}/api`,
});
describe('models of make api', () => {
const provider = new Pact({
port,
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
dir: path.resolve(process.cwd(), 'pacts'),
spec: 2,
consumer: 'myConsumer',
provider: 'myProvider',
});
const expectedResult = [{
id: 1,
value: '1 value',
}, {
id: 9,
value: '9 value',
}];
beforeAll(() => provider.setup())
afterAll(() => provider.finalize())
describe('get fake results', () => {
beforeAll(() => {
const interaction = new Interaction()
.given('I have a list of fake results')
.uponReceiving('id = 9')
.withRequest({
method: 'GET',
path: '/api/fake-results/9',
})
.willRespondWith({
status: 200,
body: expectedResult,
});
return provider.addInteraction(interaction);
});
afterEach(() => provider.verify())
it('returns a successful body', (done: any) => {
return axiosClient.request({
url: '/fake-results/9',
method: 'GET',
}).then((response: AxiosResponse) => {
expect(response.data).not.toBeNull();
done();
})
});
});
});
Hope this can save some time for you.
Most helpful comment
I'm stuck in this error for over 2 days, and finally found 10s is not enough for my poor Mac. If any of you tried a lot of different ways, but still got the connect refuse error, maybe you can try:
My case: MacOs 10.13.4 + docker + Typescript + Jest + Axios
A minimum working version could be:
Hope this can save some time for you.