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

qtester

v0.1.4

Published

A tool for automatically testing results from search engines

Downloads

3

Readme

Build Status Coverage Status View this project on NPM Join the chat at https://gitter.im/htaunay/qtester

qtester

Index

Overview

A tool for testing results from search engines. In a nutshell, the user can specify a set of tests through a JSON object, where each one will perform a query to a given search engine and compare an element of the resulting DOM with a given condition.

Therefore, each individual test should consist of:

  • A text query with 0 to n additional url parameters
  • A search engine
  • A jQuery path to access an element of the DOM resulted from the given query
  • An expected value of return and condition

The main motivation of this tool is automatically guarantee that a set of specific answer experiences on search engines are triggering as expected.

qtester allows - and incentives - the use of a tree-like data-structure to specify test routines, in order to avoid code repetition.

Installing

# Add package as dependency
npm install --save qtester
# Run tests to see if everyting is fine
npm test

# Or install global binary
npm install -g qtester

The Test Spec

Basics

The input for qtester consists of a JSON object that, by convention, must follow the format shown in the example below:

// Tests if, when running a query through bing, the query input is placed
//  correctly in the search box
{
    "name": "TestName",  
    "testRoot": {
       "searchEngine": "bing",
       "query": "test query",
       "path": "input#sb_form_q",
       "attribute": "text",
       "condition": "equals",
       "expectedValue": "test query"
    }
};

The root of the object should contain a name string and a testRoot object. The testRoot can consist of a single test - as shown above - or it can consist or a tree-like object working with the children keyword, which will result in the automatic generation of multiple tests, as exemplified below:

// This will generate two tests
// Both of them testing the search box content of bing
// But with each one presenting a different query and expected result
{
    "name": "TestName",  
    "testRoot": {
        "searchEngine": "bing",
        "path": "input#sb_form_q",
        "attribute": "text",
        "condition": "equals",
        "_children_": [
            {"query": "test query", "expectedValue": "test query"},
            {"query": "another test", "expectedValue": "another test"}
        ]
    }
};

Keywords

name

A string placed outside the testRoot. Meta-data useful for describing the test.

testRoot

Object containg the all elements necessary for test execution. At the moment no elements inside testRoot can be considered meta-data.

searchEngine

Currently the supported options are:

  • bing
  • google
  • duckduckgo

Anything else should result in an error.

query

Query string to be executed on top of the given searchEngine. At the moment, qtester only supports text-base search on each engine's web vertical.

path

jQuery path for accessing an element of the DOM resulting from the executed query.

attribute

Which attribute should be extracted from the element obtained from the path.

The result of the combination of the path and attribute is what will be compared with the expectedValue and condition.

The attribute can be a html attribute as is, or can be the keyword text which returns the content of the element returned from the jQuery path.

expectedValue

Value that should match the result of the path and attribute combination given the tests condition.

condition

Currently the supported conditions are:

  • equals
  • contains

Anything else should result in an error.

children

Special keyword that will get all same and higher level tests specifications, and apply them to all of its child objects. The children keyword must always be an array, or else an error should be returned.

[extra parameters]

On top of the minimal input necessary to run a test, the user can include as many extra url parameters as required, given that it doesn't conlfit with any pre-defineid test keywords.

For example:

// This will generate a query to the following url:
//  http://www.bing;com/search?q=example&param1=value&param2=value2
{
    "name": "TestName",  
    "testRoot": {
       "searchEngine": "bing",
       "query": "example",
       "path": "input#sb_form_q",
       "attribute": "text",
       "condition": "equals",
       "expectedValue": "example",
       "param1": "value1",
       "param2": "value2"
    }
};

Input types

The test spec can be passed to the qtest as three different types of input:

  • As a javascript object
  • As a string containing a path to a JSON file
  • As a string containing a path to a javascript file. In this case, it will be expected that such file exports only a single javascript object.

It's worth noting that the javascript file as input option offers much flexibility, and is the recommended choice of input type.

Working with the package

var runTest = require('qtester');

var testSpec = {

    "name": "Example",
    "testRoot": {
        "searchEngine": "duckduckgo",
        "query": "working with the qtester package",
        "path": "input#search_form_input",
        "attribute": "text",
        "condition": "contains",
        "_children_": [
            {"expectedValue": "with the qtester"},
            {"expectedValue": "without the qtester"}
        ]
    }
};

runTest(testSpec, function(err, testResults) {

    console.log(testResults);
});

/* Output:

[
    {
        name: 'Example',
        path: 'input#search_form_input',
        query: 'working with the qtester package',
        passed: true,
        condition: 'contains',
        actualValue: 'working with the qtester package',
        expectedValue: 'with the qtester'
    },
    {
        name: 'Example',
        path: 'input#search_form_input',
        query: 'working with the qtester package',
        passed: false,
        condition: 'contains',
        actualValue: 'working with the qtester package',
        expectedValue: 'without the qtester'
    }
]
*/

Working with the CLI

To run qtester from the command line, just pass a single input following one of the supported formats.

# Runs an example test spec in javascript file format from command line,
#  that checks if the basic Soccer answers are being triggered as expected
qtester ./examples/soccer.js