-
-
Notifications
You must be signed in to change notification settings - Fork 349
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
mockServer does not start()
#10
Comments
This seem to be related with pact-foundation/pact-js-core#20 |
Will have a look at this today. Did you try installing a previous version of the library? The latest one went through a refactor last week and I wonder if it caused a side effect somewhere - or maybe it is really the pact-node issue you refer to. Would you be able to tell 1) what environment are you on and 2) if you can try 1.0.0-rc.4 instead of the latest and how you go with it? Thanks |
The environment this is running is:
And I just tried the rc.4 release, but that did not work. If I move the initialization of the variable
|
Moving the variable outside you can't be sure if the server really started. I just noticed this line: And also paying to attention to Jest, the async behaviour is different from Jasmine based on what I seen on the documentation and it doesn't look like it contains Maybe you have to adapt your code? |
Yes, that is what I am assuming. The undefined is because of that. provider is undefined until the server starts. It never starts it timeout and then run those lines for the afterEach and afterAll. Sure I will try that! thanks and I will update |
No worries @dolfo-pivotal - BTW first time I've seen someone using Jest with Pact. Would be great to have your contribution on a test case / doco 👍 |
How did you go @dolfo-pivotal ? |
@tarciosaraiva this is my personal account. XD I could not allocated more work on the client, but I created a example using jest. https://github.com/rodolfo2488/pact-test-example/blob/master/client/__tests__/mainTest.js that works, but: I have to tell jest to use the "node" testEnvironmentI get weird errors/warnings on the
Note: this is because something is rejecting the request when it is by a script. I could not use the
|
hi @rodolfo2488 I think I identified the issue. Jest loads up JSDOM by default, even though the Jest configuration states that a browser environment is off by default. This is causing Pact to instantiate a XMLHttpRequest {
onabort: null,
onerror: null,
onload: null,
onloadend: null,
onloadstart: null,
onprogress: null,
ontimeout: null,
upload:
XMLHttpRequestUpload {
onabort: null,
onerror: null,
onload: null,
onloadend: null,
onloadstart: null,
onprogress: null,
ontimeout: null,
_ownerDocument: Document { location: [Getter/Setter] } },
onreadystatechange: null } I'm digging further to see how we can fix this. Will keep you posted. |
OK @rodolfo2488 @dolfo-pivotal I understand what's going on now. TL;DR: Jest uses JSDOM by default and brings along A LOT of polyfills to mimic a real browser environment (RBE) which passes the supporting libraries checks for RBE's thus using polyfills of questionable implementation. JSDOM, as you know, is highly used by Facebook, Airbnb, etc to simulate a RBE in Node especially for React testing. Most libraries that deal with HTTP/S requests that try to be universal usually check fora RBE like this:
The code above is actually from
Pact JS does a similar check. I don't think JSDOM was meant to be used so heavily like this with real XHR objects being instantiated and requests making their way through - which actually work as you seen the log being populated - but the response somehow is not mapped correctly on the polyfill causing the request to fail and always be rejected by the Promise. The guys from Jest thought about that and provided a configuration option named testEnvironment. If you set it to I will be pushing an Hope that helps and thanks for the issue. At least now I know that JSDOM might be something to look out for and potentially bring more support for React testing with Pact. |
hi @rodolfo2488 here's the example code based on your sample: https://github.com/pact-foundation/pact-js/tree/master/examples/jest |
Nice work @tarciosaraiva, is it worth noting this in the README more explicitly for future reference? |
you're right @mefellows might update that now |
I've updated the README with a reference to the details of this issue, closing. |
chore(request): make Request class work across both Node and Browser using Popsicle Includes a number of changes and tidying ups: * Add 'exit' flag to mocha to exit properly after tests are done * Update superagent dependency * Update dependencies for karma-pact to fix issue with peer dependencies * Update standard version, make sure the ignore glob is correct * Fix Mocha registering ts-node twice * Update nock to 9.1.x and fix tests * Update lock file for e2e tests * Adding union type for http methods to gradually change to the enum See #134 and #10 for background.
…using Popsicle Includes a number of changes and tidying ups: * Add 'exit' flag to mocha to exit properly after tests are done * Update superagent dependency * Update dependencies for karma-pact to fix issue with peer dependencies * Update standard version, make sure the ignore glob is correct * Fix Mocha registering ts-node twice * Update nock to 9.1.x and fix tests * Update lock file for e2e tests * Adding union type for http methods to gradually change to the enum See #134 and #10 for background.
…using Popsicle Includes a number of changes and tidying ups: * Add 'exit' flag to mocha to exit properly after tests are done * Update superagent dependency * Update dependencies for karma-pact to fix issue with peer dependencies * Update standard version, make sure the ignore glob is correct * Fix Mocha registering ts-node twice * Update nock to 9.1.x and fix tests * Update lock file for e2e tests * Adding union type for http methods to gradually change to the enum See pact-foundation#134 and pact-foundation#10 for background.
Hi,
I am trying to start doing CDD on my JS application. I am trying to create the most simple consumer pact, but when I call
It never gets inside the
then
, so I am assuming the promise never gets resolved. I am using Jest that uses Jasmine behind the scene. I wonder if you have any clue of how could I debug this network issue ( if it is that ).this is my test file
and when I run test I get
There is a jasmine TIMEOUT.
The text was updated successfully, but these errors were encountered: