Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation #388

Open
xorbis opened this issue Aug 28, 2017 · 21 comments
Open

Documentation #388

xorbis opened this issue Aug 28, 2017 · 21 comments

Comments

@xorbis
Copy link

xorbis commented Aug 28, 2017

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
Copy link
Author

xorbis commented Aug 28, 2017

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 xorbis closed this as completed Aug 28, 2017
@vlucas
Copy link
Owner

vlucas commented Aug 29, 2017

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

@vlucas vlucas reopened this Aug 29, 2017
@marcin-wosinek
Copy link
Collaborator

@vlucas what approach are you taking on docs?

@vlucas
Copy link
Owner

vlucas commented Sep 5, 2017

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.

@marcin-wosinek
Copy link
Collaborator

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.

@vlucas
Copy link
Owner

vlucas commented Sep 6, 2017

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.

@Elephant-Vessel
Copy link

Elephant-Vessel commented Sep 18, 2017

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.

@vlucas
Copy link
Owner

vlucas commented Sep 20, 2017

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

@LaszloQ
Copy link

LaszloQ commented Oct 26, 2017

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?

@vlucas
Copy link
Owner

vlucas commented Oct 26, 2017

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

@vzelenko
Copy link

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);
   });
}

@koooge
Copy link
Collaborator

koooge commented Feb 19, 2018

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);
  });
});

@H1Gdev
Copy link
Collaborator

H1Gdev commented Feb 27, 2018

@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);
  });
});

@Archanian
Copy link

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

@vlucas
Copy link
Owner

vlucas commented May 2, 2018

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

@Archanian
Copy link

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.

@vlucas
Copy link
Owner

vlucas commented May 2, 2018

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.

@Archanian
Copy link

Awesome, thanks for the rapid response!

@dparkerfmts
Copy link

@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)

@H1Gdev
Copy link
Collaborator

H1Gdev commented Jul 25, 2018

@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.

@vlucas
Copy link
Owner

vlucas commented Jul 25, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants