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

noisette

v0.1.1

Published

A phantomjs shim for functional testing

Downloads

2

Readme

noisette.js

A promise based interface to phantom.js, named after a coffee drink, because it seemed like a good idea at the time.

Getting Started

Firstly, make sure phantomjs is installed on your machine:

npm install -g phantomjs

Then start using it in your project

var Noisette = require('noisette');

new Noisette({
	site: 'http://127.0.0.1',
	width: 1366,
	height: 768
}).then(function(browser){
	browser.visit('/buttons').then(function(){
		return browser.dom()
				.find('button')
				.get(0)
				.click()
				.wait(200)
			.exec().then(function(){
				browser.capture('screenshot-1.png');
			});
	}).finally(function(){
		browser.close();
	});
});

The Browser

noisette.visit(page)

Points the browser to a url. If the site option is used when creating the object instance, this url is constructed as site+page, with site defaulting to an empty string.

noisette.resize(width,height)

Resizes the browser window on the fly, for testing them media queries and such.

noisette.capture(path)

Sometimes headless testing can be frustrating. You can use this to take a peek under the hood and see how your page is doing. Set path to the file path of the png file you'd like created, relative to the running script. If you want to create screenshot-1.png in folder ./captures, call it like this:

browser.capture('captures/screenshot-1.png');

noisette.close()

This function shuts down the whole operation. If the memory on your machine starts running low, it's because you forgot to call this function after you were done.

Talking to the Browser

noisette.eval(function)

Injects a javascript function within the page scope and calls it. Whatever it returns comes back as the first parameter in your next .then statement. You can only pass data that can be serialized into a JSON object.

noisette.dom()

Basic DOM manipulation and navigation can be done by creating a DOM Stack. Stacks are preceded with noisette.dom() and concluded with .exec(), returning a promise that can be chained. Check the Getting Started section for an example. There's a full dom manipulation library injected inside the browser, but I've only exposed the ones I've tested thus far.

  • find(selector) returns all the nodes found on the page matching the css selector
  • get(index) usually used with find, grabs the node at index of those matching the find
  • fill(text) puts text into input and textarea fields
  • click() throws a click event
  • wait(duration) pauses the stack for a certain duration in ms

Talking to Noisette

This is currently a half baked idea to call out from inside the browser instance. I needed it to tell the noisette instance when async javascript functions completed in the browser and for when the DOM Stack was initialized. There could be something cool in developing this, but I can't see it yet. You can take a picture from within your page by calling:

window.callPhantom({
	system: 'take_a_picture',
	data: 'captures/screenshot-1.png'
});

3 MeowMeowBeenz for the first to develop a dynamically injectable module system on top of this.

Contributing

I got a real job, so don't expect instant response times, but feel free to submit pull requests, issues, etc to this project. I kind of follow the AirBnB style guide, but if it lints and doesn't look like your cat typed it, consider it accepted.