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

grunt-mocha-phantomjs

v4.0.0

Published

Run client-side mocha tests using phantomjs

Downloads

5,577

Readme

grunt-mocha-phantomjs

A simple wrapper to run client-side mocha tests using mocha-phantomjs core library

Build Status Downloads

Getting Started

This plugin requires Grunt ~0.4.0

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-mocha-phantomjs --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-mocha-phantomjs');

The "mocha_phantomjs" task

Run this task with the grunt mocha_phantomjs command.

Task targets, files and options may be specified according to the grunt Configuring tasks guide.

PhantomJS is installed when installing using NPM.

Options

reporter

Type: String
Default: spec

The reporter that should be used. See the supported reporters for more information.

output

Type: String

The file that the task should output the results to. If output is specified, the task will always complete and not throw an error code if errors are found. The CI will determine if the build failed or not.

failWithOutput

Type: Boolean

Setting failWithOutput to true when used with the output option will fail a build along with creating a test artifact. This is useful for CIs (CircleCI) that don't fail a build based on the test artifact.

silent

Type: Boolean

Setting silent to true will prevent the results from being printed using stdout.

urls

Type: Array
Default: []

Absolute http:// or https:// urls to be passed to PhantomJS. Specified URLs will be merged with any specified src files first. Note that urls must be served by a web server, and since this task doesn't contain a web server, one will need to be configured separately. The grunt-contrib-connect plugin provides a basic web server.

Additional arguments may be passed. See mocha-phantomjs's usage.

phantomConfig

Type: Object Default: {}

Options to be passed directly to phantomjs. Eg:

{
    "--local-storage-path": "my/temp-phantom-files",
    "--local-storage-quota": "20480"
}

See phantomjs -h for more full options list.

config

Type: Object
Default: { useColors: true }

Options to be passed to mocha-phantomjs. See mocha-phantomjs-core's usage.

Usage examples

Basic usage (CI checks for error code)

// Project configuration.
grunt.initConfig({
  mocha_phantomjs: {
    all: ['test/**/*.html']
  }
});

File output for CI

// Project configuration.
grunt.initConfig({
  mocha_phantomjs: {
    options: {
      reporter: 'xunit',
      output: 'tests/results/result.xml'
    },
    all: ['test/**/*.html']
  }
});

Passing options to mocha-phantomjs

// Project configuration.
grunt.initConfig({
  mocha_phantomjs: {
    options: {
      reporter: 'xunit',
      output: 'tests/results/result.xml',
      config: {
        useColors: false,
        viewportSize: {
            width: 1024,
            height: 768
        },
        grep: 'pattern'
      }
    },
    all: ['test/**/*.html']
  }
});

Local server

Include the [grunt-contrib-connect plugin][] to run a local server [grunt-contrib-connect plugin]: https://github.com/gruntjs/grunt-contrib-connect

// Project configuration.
grunt.initConfig({
  mocha_phantomjs: {
    all: {
      options: {
        urls: [
          'http://localhost:8000/test/foo.html',
          'http://localhost:8000/test/bar.html'
        ]
      }
    }
  },
  connect: {
      server: {
        options: {
          port: 8000,
          base: '.',
        }
      }
    }
});

grunt.registerTask('test', ['connect', 'mocha_phantomjs']);

Notes

This is a very basic implementation of mocha-phantomjs. Failed tests and errors do not bubble up for custom reporting. The idea of this is to be mainly used by a CI and let the CI manage the error reporting.