npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

latte-mocha

v0.0.3

Published

tdd facilitator

Downloads

9

Readme

Latte Mocha

This is a helper package to write efficient functional tests.

What is this repository for?

This is a functional test helper. Unit test related features will be added.

Latte Mocha (latte for short) has 2 methods.

  • Init() is used to initialize a suite context. latte.Init() will be used to start the arrangement of the test suite (like creating an organization), and all the test cases included in the suite will have access to suite context (like data.organization.owner.id).
  • Run() is used in individual its and it initializes a test context. A test context has 3 important parts.
    • Arrange: it has access to suite context to arrange the test case.
    • Act: calls super agent for authenticated, cross and/or client endpoints.
    • Assert: the verification step. Arrange has access to req, res and the suite context to assert the test case. Custom assertion functions can be wrapped as described below.

Code Samples

Arranger functions can be wrapped using wrap() function in describe() to be executed later in its, or can be wrapped and executed right away using wrapAndRun() in describe(). Wrapping a function with a name that starts with "assert" is a special case, which allows the developer to reuse that assertion function in its. This way a developer can create a helper function to assert a flight/travel etc., wrap it in init and reuse it later in test cases. wrapAndRun allows passing parameters for immediate execution. The helper function is expected to resolve an object (organization, policy, deposit etc.) and latte will add the resolved object to the suite context (suite.data.organization, suite.data.policy etc.)

#!javascript

const assertFlight = (req, res, data)=>{
  console.log('assertion 1');
  expect(res.success,'search did not return success').to.be.equals(true);
}

describe('Search Flight Tests', () => {
  before(latte.init(suite => suite
    .wrapAndRun(helper.initializeTest)
    .wrapAndRun(helper.createPolicy, policy)
    .wrap(assertFlight)));

Developers can reuse wrapped suite functions in arrange(). In this case suite.data.policy which was created in describe() will be overridden by the new policy:

#!javascript
  it('Flight_With_Stop_At_Restricted_City_Expect_Success @RestrictedGeoPolicy', () => {
    return latte.run(it => it
      .arrange(suite => suite.createPolicy({ policyName: 'test' }))
      .act(createSearchRequest)
      .assert((req, res, data) => {
        expect(res.epower.cards.every(card => card.errorCode === '300510012'), 'policy error').to.be.equals(true);
      }));
  });

Developers can wrapAndRun() new functions in arrange():

#!javascript
  it('Flight_With_Stop_At_Restricted_City_Expect_Success @RestrictedGeoPolicy', () => {
    return latte.run(it => it
      .arrange(suite => suite.wrapAndRun(helper.createAnotherPolicy, { policyName: 'test' }))
      .act(createSearchRequest)
      .assert((req, res, data) => {
        expect(res.epower.cards.every(card => card.errorCode === '300510012'), 'policy error').to.be.equals(true);
      }));
  });

A custom assertion that was wrapped in describe() is used in the test case below. Note that no extra arrangement is done for this test case:

#!javascript
  it('Flight_To_Restricted_City_Expect_Success @RestrictedGeoPolicy', () => {
    return latte.run(it => it
      .act(createSearchRequest)
      .assertFlight());
  });

Custom assertion function allows executing generic assertions in tests (assertion 1). It will also let the developers execute specific assertions in some test cases. (assertion 2). If assertFlight() is called, both assertion 1 and assertion 2 will be on the logs. If only assert() is called, then logs will only have assertion 2, ignoring assertion 1 as it is part of assertFlight only:

#!javascript
  it('Flight_From_Restricted_City_Expect_Success @RestrictedGeoPolicy', () => {
    return latte.run(it => it
      .act(createSearchRequest)
      .assertFlight((req, res, data)=>{
        console.log('assertion 2');
        //put specific assertion code here
      }));
  });

act() expects a function to build the request and sends the suite data as its parameter. Developers can use static data and suite data to create a request object. They should set the endpoint, method and authentication methods (auth, cross, client). Latte will change the endpoint accordingly, add the extra headers and send the request via supertest agent:

#!javascript
...
      .act(createSearchRequest)
...
const createSearchRequest = (data) => ({
  method: 'post',
  endpoint: '/btm/user/:user_id/flights/search',
  params: {
    user_id: data.organization.owner.id,
  },
  isCrossAuthenticated: false,
  isClientAuthenticated: false,
  isAuthenticated: true,
  body: {
    currency: 'TRY',
    from: from || 'IST',
    fromType: 'City',
    to: 'AMS',
    toType: 'City',
    departureDate: '2018-04-15',
    departureTime: '08:00',
    returnDate: '2018-04-17',
    returnTime: '11:00',
    passengerCount: 1,
    cabin: 'Economy',
    refundableType: 'AllFlights',
    tripType: 'RoundTrip',
    directFlightsOnly: 'false',
  },
});