Coder Social home page Coder Social logo

Comments (3)

vincentbel avatar vincentbel commented on May 22, 2024

Before diving into the implementation detail, I'd like to point out the main use cases of this library we can see now, which I think will help to polish our public API.

As far as I can see, there exists two main purposes of mock server:

1. Daily development

Mostly, frontend programmers would use a test backend in daily development. But sometimes when backend is not ready, frontend programmers would likely write some mock API response.

Besides, the mock API responses even can be reused to do testing(the following second purpose).

2. Testing

This is big one. With service-mocker, we can nearly test our app with least mock. But there exist some limitations:

  • tests must be run on browser(like karma, but not jest)
  • browser supports are poor now
  • we can't test compatibility of our app now

There must exists more use cases I haven't covered above. As for the main two use cases, I think service-mocker need:

  1. client side code is simple (even no client side code)
  2. easy to write mock server code.
    • I think it is meaningless for developers to set up a full-featured mock server. Developers should write mock server code easily like nock, but rather than a full-featured express app.
    • As a lib, maybe we can provide the power to write a full-featured server app. But I think the easy way should implemented first.

@idiotWu these are some of my thoughts about service-mocker, what's your opinions?

from service-mocker.

idiotWu avatar idiotWu commented on May 22, 2024

@vincentbel yeah I agree.

Actually, I have been thinking about the second point - testing - these days and all the conclusions lead to one thing: patch up XMLHttpRequest. As long as we patched xhr, we can:

  1. Full compatibility.
  2. Be able to run tests with something like jsdom (or any environment that includes XMLHttpRequest constructor).

And as for the daily devs, I think it would be much simpler to run a script in browsers than set up a server - for which you'll have to write some manuals for newcomers in your team 😢

In my thoughts, this lib should be a minimalist one. There's no need to create an express in browsers, the client-side API includes a register method and a storage service only, and a get/post/any router plus storage service for server-side API.

What confusing me now is the request/response interfaces. I have no idea how far we should go.


PS: we can even remove storage service from client's API if you want ;)

from service-mocker.

idiotWu avatar idiotWu commented on May 22, 2024

v1.0.0 is out 👏

from service-mocker.

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.