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-xhr-mod

v0.2.2

Published

An XHR "Listener" with response passing for Nightwatch.js based off of the original nightwatch-xhr by [email protected]

Downloads

9

Readme

Nightwatch XHR

We've encountered some issues with our e2e tests. We tried checking if clicks on specific links behave as they should (which also meant, send a POST XHR request to a tracking server).

Since we couldn't find any package for that, we wrote one.

So - this package waits for XHR to complete and enables a callback with its values for assertion.

Have fun!

Install

npm install nightwatch-xhr

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/lib",
...

Usage Example

The function expects these parameters:

  • requestUrl - a regex match for url pattern, will only listen to urls matching this, use '' for all urls.
  • Timeout - well, timeout
  • callback - use this to assert the request after it completes
  • trigger - activate a trigger in the browser after initiating the listener

Without Trigger:

module.exports = {
    'Catch all XHRs': function (browser) {
        browser
            .url('some/path')
            .waitForXHR('', 1000, function assertValues(status, method, url, http_response_code, request_data) {
                browser.assert.equal(status, "success");
                browser.assert.equal(method, "POST");
                browser.assert.equal(http_response_code, "200");
            })
    }
 }

With Click Trigger:

module.exports = {
    'Catch all XHRs, trigger click': function (browser) {
        browser
            .url('some/path')
            .waitForXHR('', 1000, function assertValues(status, method, url, http_response_code, request_data) {
                browser.assert.equal(status, "success");
                browser.assert.equal(method, "POST");
                browser.assert.equal(http_response_code, "200");
            }, function browserTrigger() {
                 browser.click('.tracking-link-1');
            });
    }
}

"Listening" to a specific URL or Regex

module.exports = {
    'Catch user update request': function() {
        browser
            .waitForXHR('user\/([0-9]*)\/details', 1000, function assertValues(status) {
                browser.assert.equal(status, "success");
                browser.assert.equal(method, "PUT");
            }, function browserTrigger() {
                browser.click('.update');
            });
    }
}

The callback function returns the following arguments:

  • status (success/error/timeout)
  • method (GET/POST)
  • url (url of request)
  • http_response_code (HTTP status response code, eg: 200)
  • request_data (JSON of request parameters)

When the anticipated XHR request has not occurred, the above arguments will be undefined. So, please handle them appropriately.

Contribute

Feel free to correct/improve the code and send in a pull request!