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

dom-validate

v0.1.3

Published

A tool to check required/refused DOM nodes, can also output TAP or JUnit reports

Downloads

9

Readme

dom-validate

A tool to check required/refused DOM nodes, can also output TAP or JUnit reports

npm version Build Status

Usage

# Install
npm install dom-validate -g

# Check for Google page, there should be a .lsb element
node-validate -u 'https://google.com/' -r '.lsb' -v=2

# Check for Yahoo page, there should not be any empty link
node-validate -u 'https://us.yahoo.com/' -n 'a[href=""]' -v=2

# Yes, there should not be any broken images...check again
node-validate -u 'https://us.yahoo.com/' -n 'img[src=""]' -v=2

Command line options

  • -u specify a url string to verify
  • -r specify the css selector for the required element
  • -n specify the css selector for the refused element
  • -v show verbose message for the error cases
  • -v=2 show verbose message for the success cases
  • -v=3 show verbose message for the html of css selector selected elements
  • -c [BATCH] specify a local yaml config file to do batch check
  • -b [BATCH] specify base URL
  • -t [BATCH] output result as TAP format

The exit code will be the number of failed cases.

BATCH check example

Try this command: node-validate -c sample.yaml -b https://tw.search.yahoo.com -v=2

The content of sample.yaml can be:

# do one check for one URL
http://google.com:
  require: .lsb

# do 2 required element checks for the URL
http://us.yahoo.com:
  require:
    - body > div
    - form

# do many required and refused element check for the URL
/search?p=test:
  require:
    - body > div
    - form button
  refuse:
    - 'a[href=""]'

Sample output:

# check for http://google.com
OK: required element ".lsb" found(2)
# check for http://us.yahoo.com
OK: required element "body > div" found(2)
OK: required element "form" found(1)
# check for https://tw.search.yahoo.com/search?p=test
OK: required element "body > div" found(1)
OK: required element "form button" found(2)
OK: refused element "a[href=""]" not found

Output test report

Try this to save TAP report file as result.tap:

node-validate -c sample.yaml -b https://tw.search.yahoo.com -t > result.tap

You may also get JUnit (xUnit) report file by:

npm install tap-xunit -g
node-validate -c sample.yaml -b https://tw.search.yahoo.com -t | tap-xunit > junit-result.xml

node module usage

var DV = require('dom-validate');

// validate by a HTML string
DV.validateHTML(htmlString, options);

// validate by an URL
DV.validateURL(urlString, options);

// validate by a yaml config file
DV.validateByYaml(yamlFileName, options);

Options

var options = {
    url: 'http://sample.com',                  // URL for error or debug message
    baseURL: 'https://test.com',               // Will be used for relative URL when call .validateByYaml()
    require: 'body',                           // String or Array of CSS selector to check
    refuse: ['a[href=""]', 'img[src=""]'],     // String or Array of CSS selector to check
    exit: false,                               // true to end process when test done, the exit code will be number of failed case
    verbose: false,                            // true to show message for success cases
                                               // 2 to show verbose message for the success cases
                                               // 3 to show verbose message for the html of css selector selected elements
    report: false,                             // true to output TAP report
    callback: function (err, options) {        // Will be executed for every cases
        if (err) {
            // err will be the error message string when the case failed
            console.log('ERROR!' + err);
            return;
        } else {
            // success case
            connsole.log('OK!');
        }
        // You can get the whole options object in callback function, plus:
        // options.selector will be the CSS selector of current case
        // options.nodes will be the selected nodes (check cheerio document)
        // options.task will be 'require' or 'refuse'
    }
};