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

domesticate

v3.2.3

Published

Make Browser UI Tests at Home in Node

Downloads

24

Readme

Build Status Code Climate Dependency Status

   |
 __|   __   _  _  _    _   , _|_ .   __   __, _|_  _
/  |  /  \_/ |/ |/ |  |/  / \_|  |  /    /  |  |  |/
\_/|_/\__/   |  |  |_/|__/ \/ |_/|_/\___/\_/|_/|_/|__/
------------------------------------------------------

// @example using tape

domesticate = require('domesticate')
test = require('tape')

test('domesticate me', function (t) {
  t.plan(2)
  // ADD DOM
  domesticate.addDOM(function () {
    // TRANSPILE YOUR FRONT-END DOO-DADS (i.e. riot tags)
    domesticate.transpile('/path/to/riot.tag', riot.compile)
    var tag = riot.mount('riot-tag')[0]
    tag.on('submit', function () {
      t.pass('riot form should submit on click')
    })
    // INTERACT WITH YOUR DOM
    document.getElementById('submit-button').click()
    // WRITE ASSERTS AS IF YOU WHERE IN THE BROWSER
    t.equal(typeof document.body, 'object', 'document body should be typeof object')
  }, {
    html: '<html><head></head><body><riot-tag></riot-tag></body></html>',
    scripts: [
      {
        src: 'node_modules/riot/riot+compiler.min.js',
        exports: ['riot']
      }
    ]
  })
})

"Exotic: a plant, shrub or tree, not native; a plant introduced from a foreign country" -- Webster

Most poetical translations resemble the reverse side of a piece of Gobelin tapestry. The figures and colours are there, but the charm is wanting. But what is the use of making a translation at all, unless you can infuse into it some that element which makes the original poem immortal? If the essential spirit, which is the attraction in it, has evaporated, of what advantage is the residdum? You present us with an English version of an ode of Horace, or a song of Goethe; and we can only say "If this where all. Horace and Goethe would not be remembered ten years, Why is it, then, that they are immortal?"

The reason why we who translate are not aware of own failures is perhaps this, -- that we are so enchanted with the original poem that we associate this pleasure with our own. A translater does not see the bladness and prosaic character of their work, because every word suggest to them the beauty which it is meant to represent. So a person travelling through pcituresque scenery sometimes makes rud sketches of what he sees, which convey to others no idea of the landscape; but to them the are accociated with the light, the color, the perspectve, in effable charm of nature, so are valuable to them as souveniers of the scene.

A successfull translation must produce in the reader unacquanited with the original the same sort of feeling which that conveys. The ideal of a translation would be one which , if the original were lost, would remain forever as immortal. Without any thought of it as a translation, it should give as so much pleasure in itself as to a live of its own in literature. Is this impossibe? We have some examples to prove that it can be done.

-- "Exotics: attemps to domesticate them, J.F.C and L.C, 1875"

Domesticate

Testing front-end functionality usually requires a lot of tooling, browser automation software or services, with the requisite yack shaving and biolerplating to make it go, and still the resulting tests are slow, brittle and often convoluted.

Domesticate uses jsdom to make front-end tests at home in the shell, so they are simple, expressive and fast, with minimal setup rigamarole.

install

$ npm install domesticate --save-dev

writing tests

the example tests below are mocha tests run with mocha --delay so that the dom is prepared before tests are run, the mocha run function is called in a domesticate callback.

provide the dom

var assert = require('assert')
var domesticate = require('domesticate')

domesticate.addDOM(
  function () { run() }
)

describe('domesticate', function () {
  it('should make the dom accessible', function () {
    assert.equal(document.getElementById('test').innerHTML, 'test')
  })
})

configure the dom

The above test will fail at first, because there is no element with the id "test" in the dom by default, to add it, we need to add a domesticate section to our project's package.json.

"domesticate": {
  "html": "<html><head></head><body><div id=\"test\">test</div></body></html>"
}

Now our test will pass, because domestivate will add the html to the dom that os available to our test. You can also include this html from a file by replacing "html" with "include"

"domesticate": {
  "include": "/path/to/testdom.html"
}

adding scripts

Scripts like jquery can be added as well.

"domesticate": {
  "html": "<html><head></head><body><div id=\"test\">test</div></body></html>",
  "scripts": [
    {
      "src": "/path/to/jquery.js",
      "exports": [
        "$"
      ]
    }
  ]
}

Exports tells domesticate which globals defined by the script to make available for your tests, and src is the path to the script.

transpiling

You can include code written in jsx, riot tags, coffeescript, es6 or whatever by using domesticate.transpile. Which takes two arguments, the path to the code and a callback wich will transpile and return plain javascript. i.e, this React class:

window.MyReact = React.createClass({
  work: function (event) {
    window.ReactIsWorking = 'working'
  },
  render: function () {
    return (
      <form id='test-form-react' onSubmit={this.work}>
        <input id='test-form-react-submit' type='submit' onClick={this.work}></input>
      </form>
    )
  }
})

Can be tested as follows:

var domesticate = require('domesticate')
var assert = require('assert')
var ReactTools = require('react-tools')

domesticate.addDOM(function () { run() })

describe('domesticate with React', function () {
  it('should work with react jsx', function () {
    domesticate.transpile('./react.jsx', function (code) {
      return ReactTools.transform(code)
    })
    ReactDOM.render(React.createElement(window.MyReact, null), document.getElementById('test-react'))
    document.getElementById('test-form-react-submit').click()
    assert.equal(window.ReactIsWorking, 'working')
  })
})

for the above test to work, 'test-react' must be present in the dom, by way of either "html" or "include" in the "domesticate" section of your package.json, react and react-dom, must be present in the "scripts" of your "domesticate" section, and the node module "react-tools' must be installed.

"Caelum non animum mutant qui trans mare currunt."

Domesticate is a very short script, if you want to understand what it does better, see examples in tests and read the source code.