Any idea what is causing this: ```'use strict' pr...
# general
s
Any idea what is causing this:
Copy code
'use strict'

process.env.REACT_APP_ENGINE_SERVICE_URL = '<http://localhost:8992>'

import path from 'path'
import { Pact } from '@pact-foundation/pact'
import { fetchACEFields } from '../api/index'

const port = 8992
const objectType = 'dummy'

const provider = new Pact({
  port: port,
  log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
  dir: path.resolve(process.cwd(), 'pacts'),
  spec: 2,
  consumer: 'webapp',
  provider: 'engine-service',
  pactfileWriteMode: 'merge',
})

describe('fetch ACE fields', () => {

  const expectedBody = { status: true, data: [{ fullName: 'dummy' }] }

  beforeAll(async () => {
    await provider.setup();
  });


  describe('request to fetch ACE fields', () => {

    beforeAll(async () => {
      await provider.addInteraction({
        state: 'fetch ace fields',
        uponReceiving: 'a request to get all ace fields',
        withRequest: {
          method: 'GET',
          path: `/ace-fields?object_type=${objectType}`,
          headers: {
            Accept: 'application/json',
          },
        },
        willRespondWith: {
          status: 200,
          headers: {
            'Content-Type': 'application/json',
          },
          body: expectedBody,
        },
      });
    });
    test('verify it returns the correct response', async () => {
      const res = await fetchACEFields(objectType)
      expect(res).toBe(expectedBody)
    })
  })
})
m
It looks like a CORS problem. I’d suggest running this in a node environment, or usinsg the
cors
flag (also this looks to be a JS question, could you please add future JS questions in #C9VBGLUM9?)
I did see a recent cors issue in the Pact JS repo, so it might be related.
s
when i run it in node env i get navigator not defined error..
t
What is your client using to send http requests?
From the error, it looks like you're using xmlhttprequest objects (which is pretty unusual these days). For the best experience with pact, you'll want to run it in a node environment. To use xmlhttprequest in node, you'll want a shim like this: https://www.npmjs.com/package/xmlhttprequest
(disclaimer: I have never used that library, I just found it now)
s
we are using axios
t
Axios will work in node, so that's not the problem. Something is using the navigator API, which doesn't exist outside the browser. It's not pact and it won't be axios
I would guess it is something in your code
m
Are you running tests in Jasmine perhaps? I think axios will attempt to use the xmlhttprequest interface if not in a node environment
t
The problem is that outside node, it's failing as expected - and inside node, it's failing with
navigator not defined