frisby icon indicating copy to clipboard operation
frisby copied to clipboard

Documentation

Open xorbis opened this issue 7 years ago • 21 comments

Documentation is lacking for FrisbyJS v2. The README quickly shows howto get(), I managed to post by guessing the second parameter is the post body. Now I am struggling to find howto add headers.

ie: Expected 'TypeError: frisby.get(...).addHeader is not a function I could spend some time getting familiar with the code but I'm lazy :-)

xorbis avatar Aug 28 '17 15:08 xorbis

Would be nice to have a globalSetup() documentation for v2.

This made it work:

            this.frisby.globalSetup({
                request: {
                    headers: {
                        "Authorization": "JWT " + json._body.jwt
                    }
                }
            });

xorbis avatar Aug 28 '17 17:08 xorbis

Re-opening because I do think good docs is still an issue.

vlucas avatar Aug 29 '17 20:08 vlucas

@vlucas what approach are you taking on docs?

marcin-wosinek avatar Sep 05 '17 17:09 marcin-wosinek

I am currently trying to use GitBook: https://vlucas.gitbooks.io/frisby/

I planned on pointing the main frisbyjs.com domain there when finished. It's free for open source projects.

vlucas avatar Sep 05 '17 19:09 vlucas

It's using a separate repo, right? I find the documentation generate from code way easier to keep in synch with code - like in jsdoc. I guess that for approaching it this way, we would need some CI (travis?) and a place to dump the built doc.

marcin-wosinek avatar Sep 06 '17 06:09 marcin-wosinek

I agree in principle, but I have never seen a pure generated doc file that I have actually really liked and found helpful, with useful examples of usage.

vlucas avatar Sep 06 '17 15:09 vlucas

The documentation at http://frisbyjs.com/docs/api/ is using obsolete methods (.create, .expectStatus etc) which cause errors when you are getting started with frisby and pull in the latest stuff (v2). Feels unnecessary. Thanks for a nice tool.

Elephant-Vessel avatar Sep 18 '17 14:09 Elephant-Vessel

I just pointed the main frisbyjs.com domain to gitbook, so it will point there when it is fully resolved.

vlucas avatar Sep 20 '17 20:09 vlucas

The lack of documentation is a real issue here. I have used v1 before and I liked it. Now we're trying out the v2 version but it's a real struggle with the current docs. Is this being worked on or should we try an another alternative?

LaszloQ avatar Oct 26 '17 14:10 LaszloQ

The docs are actively being worked on. What specifically is lacking that is blocking you?

vlucas avatar Oct 26 '17 14:10 vlucas

Please add examples on how to reuse cookies for authenticated sessions. Few APIs will lack authentication.

E.g.:

const apiBase = "some-url";
const user = {
   username: "my-name",
   password: "*****"
};
const sessionCookieName = "session-cookie-name=";
let sessionId = null;

it("Login and save session successfully", doneCb => {

    const frb = frisby.post(`${apiBase}/login`, user);
    frb.expect("status", 200);
    // validate content of user model
   frb.then(resp => {
      const cookie = resp.headers.get("set-cookie");
      const sidStart = cookie.indexOf(sessionCookieName) + sessionCookieName.length;
      const sessionId = cookie.substring(sidStart, cookie.indexOf(";", sidStart));
      console.log("SID", sessionId);  // FIXME: don't print!
      frb.done(done);
   });
}

vzelenko avatar Dec 26 '17 17:12 vzelenko

hello, does frisby support async/await?

describe('Posts', function () {
  it('should return all posts and first post should have comments', async (done) => {
    await frisby.get('http://jsonplaceholder.typicode.com/posts');
    frisby.get('http://jsonplaceholder.typicode.com/posts')
      .done(done);
  });
});

koooge avatar Feb 19 '18 08:02 koooge

@koooge

Yes.

here is sample code.

const frisby = require('frisby');

describe('should be a teapot', function() {
  it('should be a teapot', async () => {
    await frisby.get('http://httpbin.org/status/418').expect('status', 418);
    return frisby.get('http://httpbin.org/status/200').expect('status', 200);
  });
});

H1Gdev avatar Feb 27 '18 15:02 H1Gdev

Any update on docs? V2 docs are awfully incomplete ... we are probably going to switch to a combo of Mocha/Chai/Supertest because of this

Archanian avatar May 01 '18 23:05 Archanian

@Archanian Understood. Is there anything specific that you were looking for that you feel is missing?

vlucas avatar May 02 '18 02:05 vlucas

Something as comprehensive as the docs that used to exist for the previous version would be a start, they were excellent. I can't give you specific examples because I myself know how to use the library pretty well, and have been using it for years. But for new developers on our team it is quite challenging, trying to learn and pick it up is very difficult when the current docs are so minimal.

Archanian avatar May 02 '18 02:05 Archanian

I just updated the website to list all the assertions and the nested HTTP spec example from the README.md in the root of this repo. I will continue improving the docs over the next few days.

vlucas avatar May 02 '18 04:05 vlucas

Awesome, thanks for the rapid response!

Archanian avatar May 02 '18 20:05 Archanian

@vlucas could you add a note in the docs about accessing the raw response, please? It took quite a bit of digging to work out that to get the raw response (in my case a binary buffer) I needed to call Buffer.concat(res._response._raw)

dparkerfmts avatar Jul 25 '18 01:07 dparkerfmts

@dparkerfmts

On next release, client will get raw response.

Sample code

const frisby = require('frisby');
const fs = require('fs');

it('save binary response', () => {
  return frisby.setup({ request: { rawBody: true } })
    .get('https://camo.githubusercontent.com/3f129b5ddde3ab0026f2d4c5460c4f15a8788bb8/68747470733a2f2f7777772e6672697362796a732e636f6d2f6173736574732f6672697362796a732e706e67')
    .expect('status', 200)
    .expect('header', 'Content-Type', 'image/png')
    .then(res => {
      let buf = Buffer.from(res.body);
      return new Promise((resolve, reject) => {
        fs.writeFile('res.body.png', buf, err => {
          if (err) reject();
          resolve();
        });
      });
    });
});

Please wait a moment.

H1Gdev avatar Jul 25 '18 05:07 H1Gdev

Accessing the raw body is now available in the latest version v2.1.0.

vlucas avatar Jul 25 '18 17:07 vlucas