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

mocha-electron

v1.0.6

Published

mocha testing in electron

Downloads

4

Readme

mocha-electron

Introduction

mocha-electron makes integration testing with mocha and electron easy.

Features:

  • Run tests in electron (fast & modern!) rather than phantomJS (old & buggy).
  • Ability to see test output in node AND the electron window console.
  • Option to silently fail on errors so that tests can be run in development with file watching and not stop on an error.
  • Option to show the electron window for easier debugging or hide it and run mocha tests headlessly.

Install

Install it with npm

npm install --save-dev mocha-electron

Usage

Use the script from the command line or node.

Note: by default the electron window isn't shown so that the test runs 'headless', but for debugging it can be helpful to see the window so in the config set 'window' to true or pass the '-w' argument.

node .\node_modules\mocha-electron -w http://localhost/
var mochaElectron = require('mocha-electron');

mochaElectron({
  url: 'http://localhost/',
  silent: false,
  window: false
});

I haven't gotten around to making plugins for gulp or grunt yet (Contributions is this area would be welcome) but in the meantime here is an example of how the script can be used from a gulp task.

var gulp = require('gulp');
var mochaElectron = require('mocha-electron');

gulp.task('test', function() {
  mochaElectron({
    url: 'http://localhost/',
    silent: false,
    window: false
  });
});

You also need to make sure you are including the mocha scripts on the page. If you have already been using mocha for browser testing then this step might already be done for you, but if you haven't, an example of the HTML code required to include mocha might look like this.

<div id="mocha"></div>
<link rel="stylesheet" href="/node_modules/mocha/mocha.css">
<script src="/node_modules/mocha/mocha.js"></script>
<script src="/node_modules/chai/chai.js"></script>

<script src="/test/test.js"></script>

<script>
  if (window.mochaElectron) {
    mochaElectron.run();
  } else {
    mocha.run();
  }
</script>

Note the call to mochaElectron AFTER mocha / chai and your test.js file.

API

Here's an example of how to call mochaElectron with all of its default options and comments about them.

mochaElectron({
  // Url to test.
  url: 'http://localhost/',
  // Silently swallow errors.
  silent: false,
  // Show window.
  window: false,
});

For command line usage this should give you an idea of what arguments can be passed.

var program = require('commander');

// Handle command line usage.
program
  .version('1.0.2')
  .usage('[options] <url>')
  .option('-w, --window', 'Show window', false)
  .option('-s, --silent', 'Silently swallow errors', false)
  .parse(process.argv);
node .\node_modules\mocha-electron -w -s http://localhost/

Roadmap

  • Tests

Changelog

v1.0

  • Publicly launched

Contributing

Contributions and suggestions are welcome! Please feel free to open an issue if you run into a problem or have a feature request. I'll do my best to respond in a timely fashion.

If you want to open a pull request just fork the repo but please make sure all tests and lint pass first.

License

MIT