Code Monkey home page Code Monkey logo

Comments (4)

irvile avatar irvile commented on June 3, 2024 1

I started the worker and tracker, but I still encountered a 'ConnectionRefused' error. Afterward, I will create a repository to reproduce this issue.

from zimic.

diego-aquino avatar diego-aquino commented on June 3, 2024

Hi, @irvile! Thanks for the detailed description.

To confirm, did you start your worker? If you're using zimic in tests, you could add the following code to your test setup file:

beforeAll(async () => {
  await worker.start()
})

afterAll(async () => {
  await worker.stop()
})

Also, did you apply any mock responses to /auth/v1/admin/users? Creating the interceptor only declares the schema, so mocking endpoints is another step, using interceptor.post in your scenario:

const loginTracker = supabaseInterceptor
  .post('/auth/v1/admin/users')
  .respond({
    status: 200,
    body: { user: { id: '123' } },
  })

// Now, POST requests to /auth/v1/admin/users will be mocked!

Finally (more of a tip), the interceptor schema declares the types of the requests and responses the endpoint accepts. In your case, I believe the following format would be more general:

const supabaseInterceptor = createHttpInterceptor<{
  '/auth/v1/admin/users': {
    POST: {
      request: {
        body: { email: string; password: string }
      }
      response: {
        200: { body: { user: { id: string } } }
      }
    }
  }
}>({
  worker,
  baseURL: process.env.SUPABASE_URL,
})

from zimic.

diego-aquino avatar diego-aquino commented on June 3, 2024

@irvile, as part of #34, I'm creating example projects with popular setups. As of now, I've created Node.js, JSDOM, and browser using Jest and Vitest. The examples are on canary if you'd like to take a look and compare to your project.

Investigating more about connection refused errors, one possible cause is that MSW (and Zimic by consequence) only applies mocks to the current process, which makes it hard to use in multi-process projects (e.g. a frontend test trying to apply mocks to a backend reaching an external service). I started planning a new feature and API primitives on #75, which I'm calling "remote HTTP interceptors". I believe they could extend Zimic to multi-process cases, if yours is one of them. Let me know if you have any ideias about it!

from zimic.

diego-aquino avatar diego-aquino commented on June 3, 2024

Hi, @irvile!

Among other thins, v0.4 introduced remote interceptors and v0.5 improved the logs about unhandled requests. Take a look at the documentation to check if remote interceptors solve the problem you're facing.

I'll close this issue for now. Feel free to re-open it if the problem persists!

from zimic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.