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

@camperaid/watest

v2.4.7

Published

Web Application Testsuite

Downloads

49

Readme

watest

WATest stands for Web Application Testsuite. It is a lightweight, minimal dependency testsuite designed for webdriver-based testing. It also can great be for unit and integration testing.

Install

Invoke

npm install @camperaid/watest --save

in the project root.

Use watest command to run tests located in tests/ folder. For example, add

scripts: {
  test: 'watest'
}

in package.json and then run the tests by

npm test

Structure

Tests has to be located in tests/ folder. Each test folder can contain meta.js file describing the test flow.

init function used to initialize tests in a folder uninit function used to initialize tests in a folder folders is a list of nested folders containing tests services is a list of services to run

Configuration

.watestrc.js is used to define configuration.

Pre-defined webdrivers:

  • chrome to run tests in Chrome
  • chrome-mobile to run tests in Chrome on iPhone
  • firefox to run tests in Firefox
  • safari to run tests in Safari

You can create .env file in the root directory to define enviropment variables used for configuration. Here's an example of .env file:

WATEST_DEBUNK_LIMIT=5
WATEST_LOG_DIR=/tmp
WATEST_TIMEOUT=3000
WATEST_WEBDRIVERS=["chrome", "firefox"]
WATEST_WEBDRIVER_HEADLESS=true
WATEST_WEBDRIVER_LOGLEVEL=info

Unit testing

The testsuite has basic functions:

  • fail(msg) to record test failure
  • success(msg) to record test success
  • ok(cond, msg) to test a boolean value
  • is(got, expected, msg) to compare two values

Other functions:

  • info(msg)to print an info message
  • assert(expression, msg) to print an assert message if an expression fails
  • not_reached(msg) to fail with stack trace printed
  • group(msg) prints a grouping message, useful to logically group a test checks
  • intermittent(msg) to print an intermittent message
  • todo(msg) to print a todo message
  • warn(msg) to print a warning message

Integration testing

Make sure to add servicer into watestrc.js configuration, which refers to an object managing the services. See interfaces/servicer.js for the API, which should be implemented by a servicer.

Each time when the testsuite encounters services directive in meta.js file, it pokes into servicer object to start the referred services, and then to stop them, when leaving the folder.

E2E testing

The testuiste provides two helper classes to simplify webdriver testing.

Driver

Driver is a chainable wrapper around selenium webdriver. It provides a set of handy functions used to implement high level application drivers.

AppDriver

This is a base class for all application testing blocks. A typical scenario of application block would look the following way. Let's you have a chat webapp, so you might want to have Chat appdriver like this:

class Chat extends AppDriver {
  sendMessage({ from, to, message }) {
    return this.chain(() => this.action(`Send a message from ${from} to ${to})).
      sendKeys(this.MainInput, message, `send keys to main input field`).
      hitEnter());
  }

  checkMessages({ messages }) {
    return this.chain(() => this.action(`Check messages`).
      getTextAll(this.Messages, messages, `check message boxes`));
  }

  getSelectors() {
    return {
      Self: '#chat',
      MainInput: '#main-input',
      Messages: '.messages',
    };
  }
}
module.exports = Chat;

and the test will be like

module.exports.test = scope(url, async session => {
  await session.Chat.get().
    sendMessage({ from: 'me', to: 'you', 'hi' }).
    checkMessages({ messages: ['hi']});
})

Intermittent and perma failures

meta.js supports expected_failures instruction to handle intermittent and perma failures:

module.exports.expected_failures = [
  [
    test_file,
    [
      [platform, failure_type, test_group, ...failures],
    ],
  ],
];

where

  • platform is a value of process.platform or in case of webdriver tests it is a dash separated process.platform and webdriver name, for example, darwin-chrome, can be all to indicate that failure can happen on any platform
  • failure_type is either 'perma' or 'intermittent'
  • test_group is a test group name, can be *
  • ...failures is a list of expected failures

For example:

module.exports.expected_failures = [
  [
    '*',
    [
      ['all', 'intermittent', '*', [`socket hang up`], `Socket hang up`],
      [
        'all',
        'intermittent',
        '*',
        [`[map:bounds] map retrieveBounds timeout`, `*`],
        `GoogleMaps is not loaded`,
      ],
      [
        'darwin-safari',
        'intermittent',
        '*',
        [`Wait for LocSearch focus`, `Waiting until element is focused`],
        `LocSearch is not focused`,
      ],
    ],
  ],
];

Mocking

ES6 modules mocking is supported only. You should add meta.js to provide ES6 module loader. For example, you can substitute a module path by a mock module path this way:

export const loader = true;

export async function resolve(specifier, context, defaultResolve) {
  switch (specifier) {
    case './base.mjs':
      specifier = './base_mock.mjs';
      break;
  }
  return defaultResolve(specifier, context, defaultResolve);
}

Testsuite options

  • --debunk to enable debunk mode which will run a test the number of times or until it fails whichever is first
  • -v or --verify to re-run failing tests
  • --timeout to set up a custom timeout for webdriver tests, for example, to break wd condition early