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

node-qunit-puppeteer

v2.1.2

Published

A simple node module for running qunit tests with headless Chromium

Downloads

11,950

Readme

Node QUnit Puppeteer Plugin

NPM

A simple node module for running qunit tests with headless Chromium.

There is a common issue with PhantomJS failing with ES6 code, and the logical solution is to use Chrome Puppeteer instead.

Usage

Command-line utility

npm install -g node-qunit-puppeteer
node-qunit-puppeteer <URL> [<timeout>] [<puppeteerArgs>]
  • <URL> - the address (or filepath) of the qunit HTML test page.
  • <timeout> - (optional) test run timeout in milliseconds. Default is 30000.
  • <puppeteerArgs> - (optional) Chrome command-line arguments. Default is "--allow-file-access-from-files".

Examples

node-qunit-puppeteer https://example.org/ 10000 "--allow-file-access-from-files --no-sandbox" node-qunit-puppeteer ./test/test-runner.html 10000 "--allow-file-access-from-files --no-sandbox"

Node module

  • npm: npm install node-qunit-puppeteer --save-dev
  • yarn: yarn add node-qunit-puppeteer --dev

Exported functions

  • async function runQunitPuppeteer(qunitPuppeteerArgs) -- Opens the specified HTML page in a Chromium puppeteer and captures results of a test run. Returns an object with information on every module/test run.
  • function printOutput(qunitResult, console) -- Takes the output of runQunitPuppeteer and prints it to console with identation and colors.
  • function printResultSummary(qunitResult, console) -- Takes the output of runQunitPuppeteer and prints a summary to console with identation and colors.
  • function printFailedTests(qunitResult, console) -- Takes the output of runQunitPuppeteer and prints failed test(s) information to console with identation and colors.
  • async function runQunitWithBrowser(browser, qunitPuppeteerArgs) -- Runs the specified HTML page in the puppeteer.Browser instance. You might want to use this if you need to use a different puppeteer version or if you need to apply some additional logic on top of it.
  • async function runQunitWithPage(page, qunitPuppeteerArgs) -- Runs the specified HTML page in the puppeteer.Page instance. Just like the previous function, you may want to use it if you need to use a different puppeteer version.

Examples

const path = require("path");
const { runQunitPuppeteer, printOutput } = require("node-qunit-puppeteer");

const qunitArgs = {
  // Path to qunit tests suite
  targetUrl: `file://${path.join(__dirname, "tests.html")}`,
  // (optional, 30000 by default) global timeout for the tests suite
  timeout: 10000,
  // (optional, false by default) should the browser console be redirected or not
  redirectConsole: true,
  // (optional, ['--allow-file-access-from-files'] by default) Chrome command-line arguments
  puppeteerArgs: ["--allow-file-access-from-files"]
};

runQunitPuppeteer(qunitArgs)
  .then(result => {
    // Print the test result to the output
    printOutput(result, console);
    if (result.stats.failed > 0) {
      // Handle the failed test run
    }
  })
  .catch(ex => {
    console.error(ex);
  });
const path = require("path");
const {
  runQunitPuppeteer,
  printResultSummary,
  printFailedTests
} = require("node-qunit-puppeteer");

const qunitArgs = {
  // Path to qunit tests suite
  targetUrl: `file://${path.join(__dirname, "tests.html")}`,
  // (optional, 30000 by default) global timeout for the tests suite
  timeout: 10000,
  // (optional, false by default) should the browser console be redirected or not
  redirectConsole: true
};

runQunitPuppeteer(qunitArgs)
  .then(result => {
    printResultSummary(result, console);

    if (result.stats.failed > 0) {
      printFailedTests(result, console);
      // other action(s) on failed tests
    }
  })
  .catch(ex => {
    console.error(ex);
  });

Output

result object

{
  "modules": {
    "module 1": {
      "name": "module 1",
      "tests": [
        {
          "name": "module 1 simple test 1",
          "testId": "49b931ed",
          "skip": false,
          "module": "module 1",
          "previousFailure": false,
          "log": [
            {
              "module": "module 1",
              "name": "module 1 simple test 1",
              "result": true,
              "message": "Passed 1!",
              "actual": true,
              "testId": "49b931ed",
              "negative": false,
              "runtime": 1,
              "todo": false,
              "expected": true
            },
            {
              "module": "module 1",
              "name": "module 1 simple test 1",
              "result": true,
              "message": "Passed 2!",
              "actual": true,
              "testId": "49b931ed",
              "negative": false,
              "runtime": 2,
              "todo": false,
              "expected": true
            }
          ],
          "skipped": false,
          "todo": false,
          "failed": 0,
          "passed": 2,
          "total": 2,
          "runtime": 3,
          "assertions": [
            {
              "result": true,
              "message": "Passed 1!"
            },
            {
              "result": true,
              "message": "Passed 2!"
            }
          ],
          "source": "    at file:///Users/..../test-runner.html:17:11"
        }
      ],
      "failed": 0,
      "passed": 2,
      "runtime": 3,
      "total": 2
    },
    "module 2": {
      "name": "module 2",
      "tests": [
        {
          "name": "module 2 simple test 2",
          "testId": "9f962b0e",
          "skip": false,
          "module": "module 2",
          "previousFailure": false,
          "log": [
            {
              "module": "module 2",
              "name": "module 2 simple test 2",
              "result": true,
              "message": "Passed 1!",
              "actual": true,
              "testId": "9f962b0e",
              "negative": false,
              "runtime": 0,
              "todo": false,
              "expected": true
            }
          ],
          "skipped": false,
          "todo": false,
          "failed": 0,
          "passed": 1,
          "total": 1,
          "runtime": 0,
          "assertions": [
            {
              "result": true,
              "message": "Passed 1!"
            }
          ],
          "source": "    at file:///Users/..../test-runner.html:23:11"
        },
        {
          "name": "module 2 failed test 1",
          "testId": "aae8e622",
          "skip": false,
          "module": "module 2",
          "previousFailure": false,
          "log": [
            {
              "module": "module 2",
              "name": "module 2 failed test 1",
              "result": false,
              "message": "Passed 1!",
              "actual": false,
              "testId": "aae8e622",
              "negative": false,
              "runtime": 0,
              "todo": false,
              "expected": true,
              "source": "    at Object.<anonymous> (file:///Users/..../test-runner.html:28:14)"
            }
          ],
          "skipped": false,
          "todo": false,
          "failed": 1,
          "passed": 0,
          "total": 1,
          "runtime": 1,
          "assertions": [
            {
              "result": false,
              "message": "Passed 1!"
            }
          ],
          "source": "    at file:///Users/..../test-runner.html:27:11"
        }
      ],
      "failed": 1,
      "passed": 1,
      "runtime": 2,
      "total": 2
    }
  },
  "totalTests": 3,
  "stats": {
    "passed": 3,
    "failed": 1,
    "total": 4,
    "runtime": 35
  }
}