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

livetest-program

v0.0.20

Published

livetest program scripting

Downloads

9

Readme

programmable livetest workflows when running mocha tests in nwjs window

Install

npm i livetest-program --save-dev

Usage

$ node node_modules/.bin/livetest
$ node livetest --config=./test/config.json

Press F5 in dev tools window to repeat all tests.

If you want to run multiple instances, add the --user-data-dir option to start nw with different profiles:

$ node livetest --user-data-dir=first-profile &
$ node livetest --user-data-dir=second-profile

Test

$ npm test

Mocha spec file usage

;(function () {

  const program = require('livetest-program');

  describe('...', function () {
    ...

    it('...', (done) => {

      assert.strictEqual($('#result').text(), '', 'result text should be empty');

      program(this, 5000)
        .await('#btn-clickme')
        .click('#btn-clickme')
        .wait(500)
        .capture('livetest-program.clicktest.png')
        .run(function () {
          assert.strictEqual($('#result').text(), 'yay!', 'result text should have value');
          done();
        });
    });
  });
}());

see test/*Spec.js files for working examples

Config file

{
  "files": [
    "test/test1Spec.js",
    "./test/**/*Spec.js"
  ]
}

API

program(mochaTest[, timeout])

start program description

describe('suite', function () {

  it('test', (done) => {

    program(this, 5000)
      ...
      .run(done)
  });
});

also works in before():

describe('suite', function () {

  before((done) => {

    program(this)
      ...
      .run(done)
  });
});

getTestFilename ()

returns the current test filename;

  program(mochaTest)
    .do(function (next) {
      this.log(this.getTestFilename());
      ..

getTestWindow ()

returns the test window object

  program(mochaTest)
    .do(function (next) {
      var testWindow = this.getTestWindow();
      testWindow.$('body').empty();
      ..

getMainWindow ()

returns the main window object

  program(mochaTest)
    .do(function (next) {
      this.getMainWindow().console.log(42);
      ..

getNwWindow ()

returns the NW-Window Object

see nw docs

getConsole ()

get the main window console

  program(mochaTest).getConsole().log(42);

  program(mochaTest)
    .do(function (next) {
      this.getConsole().warn(43);
      ..  

getJQuery ()

get the test window $

  const $ = program(mochaTest).getJQuery();

wait (duration ms)

  program(mochaTest)
    .wait(500)
    .log('delayed')
    .run();

await (predicate)

await (selector)

  program(mochaTest)
    .await(function () {
      // if returns truthy, wait ends
      return $('.msgbox').length;
    })
    .log('message box element available now')
    .run();

with argument as a selector string

  program(mochaTest)
    .await('.controls .desired-classname')
    .log('desired element in controls is available now')
    .run();

log ()

warn ()

error ()

  var n = 0;
  program(mochaTest)
    .log('message %d', ++n)
    .do(function (next) {
      this.log('message  %d', ++n);
      next();
    })
    .run();

  // => message 1
  // => message 2

moveTo (x, y)

resizeTo (width, height) {

position/resize main window

  program(mochaTest)
    .moveTo(0, 0)
    .resizeTo(50, 50)
    .wait(1000)
    .do(function (next) {
      this.moveTo(100, 100);
      this.resizeTo(420, 700);
      this.wait(100, next);
    })
    .run();

capture (filename)

captures the page to png file

  program(mochaTest)
    .resizeTo(320, 240)
    .capture('/tmp/livetest-programm-xs.png')
    .wait(1000)
    .do(function (next) {
      this.resizeTo(1600, 800)
        .capture('/tmp/livetest-programm-xl.png')
        .wait(100, next);
    })
    .run();

on (eventName, selector, fn)

one (eventName, selector, fn)

attach a handler to an event for the selector elements

  program(mochaTest)
    .on('click', '#btn-continue', function (ev) {
      triggered = true;
    })

Use one() to execute the handler at most once.

trigger (selector, event)

trigger an event

  program(mochaTest)
    .trigger('#btn-continue', 'click')

type (selector, text)

simulate typing a text

  program(mochaTest)
    .type('.email', '[email protected]')
    .do(function (next) {
      this.type('.password', 'secret', next);
    })
    .run();

when finished, this also triggers the 'change' event

click (target)

simulate click

  program(mochaTest)
    .click('.reset')  // selector string
    .do(function (next) {
      this.click($('.send')); // jquery
      next();
    })
    .run();

run ([callback])

run the program

exit ([callback])

early exit program execution

  program(mochaTest)
    .do(function (next) {
      this.exit(() => {
        this.log('bye');
      });
    })
    .run();

License

MIT © kruemelo