Comments (14)
you're right @mefellows might update that now
from pact-js.
This seem to be related with pact-foundation/pact-js-core#20
from pact-js.
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
from pact-js.
The environment this is running is:
npm: 3.10.3
node: 6.4.0
And I just tried the rc.4 release, but that did not work.
If I move the initialization of the variable provider
outside the callback from the server start()
. The pact interaction gets registered on the pact file. The test fails at the end, and during the execution I see this too:
[SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random()
Unhandled promise rejection ProgressEvent { isTrusted: [Getter] } ( 6x)
from pact-js.
Moving the variable outside you can't be sure if the server really started.
I just noticed this line: Cannot read property 'finalize' of undefined
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 beforeAll
and afterAll
hooks like the latest versions of Jasmine do based on this part of the docs.
Maybe you have to adapt your code?
from pact-js.
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
from pact-js.
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 👍
from pact-js.
How did you go @dolfo-pivotal ?
from pact-js.
@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" testEnvironment
I get weird errors/warnings on the jsdom
mode with jest like
crypto not usable, falling back to insecure Math.random()
ProgressEvent is untrusted
Note: this is because something is rejecting the request when it is by a script.
I could not use the pact.verify
call
I need to read more the implementation of that method to see where I can fit that in the test. So far I am not using it.
I had to use cors
true or it won't work
I have no clue why is this.
But I will continue working on that when I have time. A friend of mine started a project for spring boot verifier on the provider side that as well I am using it on the server side of that example. check that out.
Feel free to corrent my mainTest.js or suggest changes on it.
from pact-js.
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
object that is basically invalid:
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.
from pact-js.
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:
typeof window !== 'undefined' &&
typeof document !== 'undefined' &&
typeof document.createElement === 'function'
The code above is actually from axios
and the full method is like this
function isStandardBrowserEnv() {
return (
typeof window !== 'undefined' &&
typeof document !== 'undefined' &&
typeof document.createElement === 'function'
);
}
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 node
then everything works.
I will be pushing an examples
folder that contain a sample with Jest for Node. For the browser though, I strongly recommend you use something like Karma if you can.
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.
from pact-js.
hi @rodolfo2488 here's the example code based on your sample: https://github.com/pact-foundation/pact-js/tree/master/examples/jest
from pact-js.
Nice work @tarciosaraiva, is it worth noting this in the README more explicitly for future reference?
from pact-js.
I've updated the README with a reference to the details of this issue, closing.
from pact-js.
Related Issues (20)
- RFC: Remove CLI & Standalone API (Pact Standalone Tools - Ruby), and migrate into sister package pact-js-cli enhancement
- RFC: Support Alpine
- RFC: Pact JS V9.x - Update to latest V2 standalone / Include ARM64 Platforms HOT 1
- Because Maths: invalid pact specification version supplied: 5 HOT 8
- V4 Asynchronous Messages
- Bug: Corporate Proxy not supported during verification
- TypeError: ffi.pactffiMessageGivenWithParams is not a function HOT 2
- Support combining matching rules HOT 3
- `eachLike` behaves like `atLeastOneLike` when min is not explicitly set - contrary to documentation HOT 5
- payload changed by pact between consumer test and provider test HOT 6
- Message provider verification error: "Caught panic with error: failed printing to stdout" HOT 8
- CVE check denying [email protected] which is dependent on by pact-foundation/pact HOT 3
- V3 Matchers package missing matchers from V2
- BadSignature error when approaching broker on HTTPS HOT 5
- Vitest - Pact Verifier fails with 3 or more interactions HOT 8
- V4InteractionWithCompleteRequest is unimplemented HOT 9
- Allow using `new ArrayBuffer(0)` in withRequest.body to be honest in the contract tests HOT 1
- MatchersV3.reify doesn't extract payload from MatchersV3.nullValue() HOT 4
- Consumer test using application/x-www-form-urlencoded content type is being serialised as JSON
- Verify Pact-JS against pact-compatibility-suite
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pact-js.