<Backend engineer & Pact noob alert> Is ...
# pact-js
p
<Backend engineer & Pact noob alert> Is it possible to run Pact within the jsdom environment? I'm trying to experiment with a contract test setup for our TS (old and janky) frontend. Specific error in this case is
FormData is not defined
when I run the test within the
node
env and
ReferenceError: setImmediate is not defined
when I run within jsdom. This later error seems to be an issue with Jest 27 and up, but I don't want to downgrade the Jest version.
I've not tested it out with the new rust core, so would appreciate a report back, and we can help look into it if it doesn't work
We also have https://github.com/pact-foundation/jest-pact which may be worth consideration as a convenience
p
So I've tried the
Copy code
/**
 * @jest-environment node
 */
which successfully switches the env to node I assume, as the reference error is gone). The problem is my test uses jsdom-specific code:
Copy code
it('returns the correct response', (done) => {

      const formData = new FormData();
      formData.append(
        'file',
        'this is the file string',
        'this is the file name',
      );
Arguably needs refactoring and/or I should just pick a different method for my first test as the main thing I want to do is generate a Pactfile and try it out!
m
I think jsdom code should work in a Pact test, so long as it runs in a node environment (because Pact needs it). Could you please share a bit more of the test? The main thing is, seeing how the request is sent to the API and how that can be redirected to Pact. Seeing
FormData
I’m assuming it’s going to be a multipart form post, which should be testable
p
yea, wrapping up for the holiday so will probably pick this up in the new year, thanks!
xmas party kirby 1