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

testdom

v3.0.1

Published

Testdom helps you write tests for the browser & node

Downloads

1,221

Readme

Testdom

Testdom is a jsdom wrapper to help developers write test code that works both in the browser and in node.

It works by checking if a global document exists in it's current environment. If it does it bails out and expects the browser to provide all available browser globals. If a global document does not exists, it will create one using jsdom.

WANTED! PRs with more tested additional globals.

Install

npm install testdom

Usage

require('testdom')('<html><body></body></html>')
console.log(document)

Additional globals

Testdom supports an argument of additional globals that will be loaded (using require) only if no DOM exists. This way users can experiment with different modules as browser global replacements and polyfills.

require('testdom')('<html><body></body></html>', {
    localStorage : 'localStorage',
})
console.log(localStorage)

In the additional globals object the key is the name of the global the the value is the module name to be require'd.

Since v1.1.0 we also support arbitrary globals, so anything passed to additional globals that is not a string, we be added globally as is.

Confirmed modules

A list of modules confirmed to work well as a global/polyfill for jsdom.

| Global | Module | Notes | |:------------- |:------------- |:----- | | localStorage | localStorage | 404 link but npm install works | | Promise | es6-promises | Different than es6-promise (singular). |

Testling

Testling uses browserify to create a browser compatible bundle of your javascripts. Unfortunately jsdom is not compatible with browserify, so we have to tell testling to ignore it.

In your package.json add a browser field and add tell browserify to ignore jsdom.

$ vi package.json

...
"browser" : {
    "jsdom" : false
},
...

Since testdom only tries to require jsdom if no document exists; the browser will never reach that code and we are good. The tests will use the browser's DOM.

Changelog

3.0.0

  • Upgraded jsdom to 13.0.0 -- requires node 8+

2.0.0

  • Upgraded jsdom to 6.5.1 -- requires node 4+

1.1.0

  • Support for arbitrary globals

1.0.1

  • Upgraded jsdom dependency from 2.x.x to 3.x.x

1.0.0

  • Removed non-jsdom dependencies (& globals)
  • Added ability to require non-jsdom modules only if DOM does not exists
  • Started list of working globals & polyfills

0.1.0

  • Pre changelog era. Who knows what went on.

enjoy.