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

@wildpeaks/electron-test-utils

v1.0.1

Published

Electron Test Utilities

Downloads

2

Readme

Electron Test Utilities

Build Status

Collection of helpers for DOM tests running in Electron.

Install:

npm install @wildpeaks/electron-test-utils --save-dev

Function "getBounds"

Calculates the bounding box of an HTMLElement in the page.

This is useful to check how CSS styles or text contents affect the size of known elements, or test things like whether important elements are above the fold or not.

Usage:

getBounds(HTMLElement element)

Example:

const {getBounds} = require('@wildpeaks/electron-test-utils');

const container = document.getElementById('application');
const bbox = getBounds(container);

Function "hasFocus"

Checks if an HTMLElement has focus.

Usage:

hasFocus(HTMLElement element)

Example:

const assert = require('assert');
const {hasFocus} = require('@wildpeaks/electron-test-utils');

const textfield = document.getElementById('username');
assert.ok(hasFocus(textfield), 'The text input does not have focus initially');
someFunctionBeingTested();
assert.ok(hasFocus(textfield), 'The text input has focus afterwards');

Function "simulateClick"

Simulates an arbitrary mouse click in the page.

This (along with screenshot) is also useful for running scenarios against Canvas-based (2D Canvas or WebGL) user interfaces.

Usage:

simulateClick(Object options)

Options:

  • x / y: (Integer) Coordinates in the page where the mouse is clicked

  • button: (String) Mouse button: left, middle or right

  • modifiers: (Array of String) Active special keys such as shift or ctrl. See the Electron API for the list of available modifiers.

Example:

const {spy} = require('sinon');
const {simulateClick} = require('@wildpeaks/electron-test-utils');

const onclick = spy();
const button = document.getElementById('mybutton');
button.addEventListener('click', onclick);

assert.strictEqual(onclick.called, false, 'The button has not been clicked yet');

simulateClick({
	x: 10,
	y: 20,
	button: 'left',
	modifiers: []
});

setTimeout(() => {
	assert.strictEqual(onclick.called, true, 'The button has been clicked');
});

Function "simulateKey"

Simulate an arbitrary keyboard key.

Usage:

simulateKey(Object options)

Options:

  • keyCode: (String) Key being sent, such as a, enter or tab. See the Electron API for the list of available key codes.

  • modifiers: (Array of String) Active special keys such as shift or ctrl. See the Electron API for the list of available modifiers.

Example:

const assert = require('assert');
const {simulateKey} = require('@wildpeaks/electron-test-utils');

const textfield = document.getElementById('username');
textfield.focus();

assert.strictEqual(textfield.value, '', 'Value before');

simulateKey({keyCode: 'H', modifiers: ['shift']});
simulateKey({keyCode: 'e'});
simulateKey({keyCode: 'l'});
simulateKey({keyCode: 'l'});
simulateKey({keyCode: 'o'});

setTimeout(() => {
	assert.strictEqual(textfield.value, 'Hello', 'Value after');
});

Function "screenshot"

Takes a screenshot of an HTMLElement.

Useful to compare against a reference screenshot (for visual regression tests) or simply save to file (to have an overview of key parts of an application).

However, remember that antialiasing and font rendering can differ depending on the operating system, e.g. the resulting image might look slightly different on Travis CI than on your development machine.

Usage:

screenshot(HTMLElement element, Function callback)

Callback parameters:

Example:

const fs = require('fs');
const {screenshot} = require('@wildpeaks/electron-test-utils');

screenshot(
	document.getElementById('application'),
	image => {
		fs.writeFile('screenshot.png', image.toPNG(), () => {
			console.log('Saved the screenshot');
		});
	}
);