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 🙏

© 2024 – Pkg Stats / Ryan Hefner

nightwatch-mixpanel

v0.4.0

Published

Mixpanel tracking end-to-end testing assertions for nightwatch and nightwatch-xhr

Downloads

12

Readme

nightwatch-mixpanel

All Contributors

Mixpanel Custom command and assertions for Nightwatch.

This package use nightwatch-xhr, which must be installed. And of course, you must use Nightwatch.js.

Setup

    npm install -D nightwatch-xhr nightwatch-mixpanel

or

    yarn add -D nightwatch-xhr nightwatch-mixpanel

Then, in order for your project to be able to access these commands and assertions you need to include them in your projects Nightwatch config :

...
"custom_commands_path": ["./node_modules/nightwatch-xhr/src/commands", "./node_modules/nightwatch-mixpanel/src/commands"],
"custom_assertions_path: ["./node_modules/nightwatch-xhr/src/assertions", "./node_modules/nightwatch-mixpanel/src/assertions"],
...

or, for legacy javascript, use

...
"custom_commands_path": ["./node_modules/nightwatch-xhr/es5/commands", "./node_modules/nightwatch-mixpanel/es5/commands"],
"custom_assertions_path: ["./node_modules/nightwatch-xhr/es5/assertions", "./node_modules/nightwatch-mixpanel/es5/assertions"],
...

Usage

Custom Command : waitForMixpanel

API

The function expects these parameters:

  • delay - how much time should we listen for Mixpanel requests
  • trigger - activate a trigger in the browser after initiating the listener
  • expectedMixpanel - an array of event names and event properties we expect
  • callback(optional) - use this to assert the request after it completes

Example

Without callback

module.exports = {
    'Login Event': function (browser) {
        browser
            .waitForMixpanel(
                1000,
                browser.login(),
                [['Login', { from: 'Homepage' }]],
            )
    }
};

With callback:

module.exports = {
    'Login Event': function (browser) {
        browser
            .waitForMixpanel(
                1000,
                browser.login(),
                [['Login', { from: 'Homepage' }]],
                xhrs => {
                    browser.assert.equal(xhr[0].httpResponseCode, 200);
                }
            )
    }
};

The callback function returns an array of object containing the following properties :

  • status (success/error/timeout)
  • method (GET/POST)
  • url (url of request)
  • requestData (raw POSTed data)
  • httpResponseCode (HTTP status response code in string, eg: "200", )
  • responseData (raw response data)

When the anticipated XHR request has not occurred, it fails an assertion. Callback is not called.

Custom Assertion : mixpanelTracked

You can use directly the custom mixpanelTracked assertion on xhr objects returns by nightwatch-xhr's waitForXHR custom command.

API

The assertion expect :

  • mpEvent - name of the expected Mixpanel event
  • mpProps - expected properties of the Mixpanel event options (optional, default to {}) - An option object with these properties avalaible :
    • getMixpanelEventFromUrl - A function which take a tracking URL as parameter and should return the data at the included in (example: 'https://api.mixpanel.com/track/?data=myData' => 'myData'). This is usefull if you specified api_host option to mixpanel-browser.
  • listenedXhrs - Either a single nightwatch-xhr's xhr object, or an array of such objects.

Example

Without callback, without options

module.exports = {
    'Some Test': function (browser) {
        browser.waitForXHR(
            'mixpanel',
            1000,
            () => browser.url('some/page'),
            xhrs => {
                browser.assert.mixpanelTracked('View Page', { aProp: 'prop' }, {}, xhrs);
                browser.assert.mixpanelTracked('Other Event', { someProp: 42 }, {}, xhrs);
            }
        );
    }
};

Contributors

| jalil💻 📖 💡 ⚠️ 🔧 👀 | rdbmax💻 ⚠️ | | :---: | :---: |

Contribute

This project follows the all-contributors specification. Contributions of any kind are welcome!