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

autodom

v0.1.3

Published

AutoDOM is an automatic DOM fixture CLI util. If you're building a product that depends on third-party markup, such as a browser extension that looks for selectors and injects itself into a page. You can use AutoDOM to download a pages HTML which can be u

Downloads

3

Readme

AutoDOM

AutoDOM is an automatic DOM fixture CLI util. If you're building a product that depends on third-party markup, such as a browser extension that looks for selectors and injects itself into a page. You can use AutoDOM to download a pages HTML which can be used as test fixtures.

AutoDOM keeps a lockfile to determine the last time a fixture was downloaded see updatePolicy below. That way if the DOM changes and your selectors will miss, you're aware just before you publish.

Having a cron job can do the same thing and you can notify yourself. But that's not the purpose of this library. Your fixtures can be used to check if your code will mount against a realistic environment.

Why not just use something like Cypress or Selenium and do end-to-end testing?

Valid argument, and if you can get your e2e tests stable enough that you don't want to comment them out. Go for it! This might not be the library for you. You will get much, much more value from something like Cypress. For those edge cases where you need a little bit more predictability and stability. This could be for you.

This project is just testing the grounds to see if it adds value to a project I work on. Use with caution and respect of the third-party you're snapshotting.

Should I use this library?

  1. Do you have e2e tests that work fine for you?
    • Yes - You don't need this library
    • No - This library may help you.

Setup

Create a autodom.config.js at your project root. See below for options.

Update your package.json to include a pretest script. For example:

{
  "scripts": {
    "test": "jest",
    "pretest": "autodom"
  }
}

Use your fixture

import { homepage } from './__domfixtures/'
describe('Homepage tests', () => {
  it('should have mount point', () => {
    document.body.innerHTML = homepage()
    const match = document.querySelector('#sidebar')
    expect(match.length).toEqual(1)
  })
})

autodom.config.js

const path = require('path')
module.exports = {
  updatePolicy: iso => addDays(iso, 7) > new Date(), // Only update weekly
  outputDirectory: path.resolve('./tests/__domfixtures__'),
  resourceFetchType: 'puppeteer',
  urls: [{ url: 'https://www.example.com', name: 'homepage' }],
  outputJavascript: true,
  removeScripts: true,
}

If you look for multiple DOM nodes for your entry points then this function may come in handy for your tests:

/**
 * Test if DOM has one of the given selectors
 *
 * @export
 * @param {*} selectors
 * @returns
 */
export function hasSelectorMatch(selectors) {
  return selectors.some(
    selector => document.querySelectorAll(selector).length > 0
  )
}

Configuration Options

| Option | Description | Default value | | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | | urls | The collection of urls to download the markup from. Must match the following shape. {url: string, name: string} | [] | | updatePolicy | How often should be new fixtures be downloaded? You can use the following options: daily or a function with the following signature: (dateIsoString:string) => Boolean | daily | | outputJavascript | If outputJavascript is true then the markup is placed in a javascript file. Useful when you don't want to use a HTML loader in Webpack for example. If false a HTML file is created instead. | true | | outputDirectory | The absolute path to output the fixtures | path.join(process.cwd(), './__domfixtures__') | | resourceFetchType | fetch or puppeteer | fetch | | removeScripts | Do you want to remove script tags from the downloaded markup | true |