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

galvanize-superjsdom

v0.6.0

Published

A small library for writing integration tests with superagent and jsdom

Downloads

3

Readme

galvanize-superJSDOM

A simple, opinionated library for writing integration tests with Superagent and JSDOM.

npm version Build Status

Description

This library is maintained for use by Galvanize instructors and curriculum developers to test student exercise code. It's designed to test simple applications written by junior developers by automating user actions, such as filling in a form and clicking a submit button.

Installation

npm install galvanize-superjsdom

Usage

Here's an example of an exercise with some tests that check the DOM for the correct content.

'use strict'
const expect = require('chai').expect
const server = require('../app')
const request = require('supertest')(server)
const Page = require('galvanize-superjsdom')

describe("POST /", () => {
  it("can fill in forms", () => {
    const request = supertest(app)
    const page = new Page(request)

    return page.visit("/")
      .clickLink('New Person')
      .fillIn('First Name', 'Sue')
      .fillIn('Last Name', 'Sylvester')
      .check('Check it out')
      .select('Thirty', {from: 'Age'})
      .clickButton('Submit Me')
      .promise
      .then(function(page){

        // page.$ is a jQuery object representing the document
        expect(page.$("h1").text()).to.equal("It worked")

        // you can also access
        //
        //  - page.window
        //  - page.response.body
      })
  })

});

Page

Kind: global class

new Page(request)

Represents a Page.

Requires an instance of an express server wrapped in supertest:

const server = require('../myApp/app');
const request = require('supertest')(server);

| Param | Type | Description | |:--------|:---------------------|:--------------------------------------------| | request | express | an instance of the app wrapped in supertest |

page.visit(path) ⇒ Promise

Page.prototype.visit - get a jsdom instance with jquery returned as a promise

Kind: instance method of Page
Returns: Promise - a promise containing a jsdom object

| Param | Type | Description | |:------|:--------------------|:------------------| | path | string | the relative path |

page.validate($) ⇒ Promise

Page.prototype.validate - A promise that validates the page against w3c standards

Kind: instance method of Page
Returns: Promise - resolves the promise with the jsdom instance if there are no errors found, otherwise rejects with an object containing the errors

| Param | Type | Description | |:------|:-------------------|:---------------------| | $ | jsdom | an instance of jsdom |

page.get(path) ⇒ Promise

Page.prototype.get - Sends a GET request to the path and resolves a promise with that object

Kind: instance method of Page
Returns: Promise - resolves the promise with the response object, otherwise rejects it with an error

| Param | Type | Description | |:------|:--------------------|:------------| | path | string | the path |

page.post(path, controls) ⇒ Promise

Page.prototype.post - Sends a post request with the data provided. This is typically used in conjunction with the clickButton method.

Kind: instance method of Page
Returns: Promise - Resolves with a request object

| Param | Type | Description | |:---------|:--------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------| | path | string | The path to send | | controls | object | an object formatted as an array of objects controls containing a name and value. jQuery's .serializeArray function will format controls properly. |

page.clickLink(text) ⇒ Promise

Page.prototype.clickLink - A thenable that visits a link by loading the href gotten by the text of the link.

Kind: instance method of Page
Returns: Promise - Returns the resolve or reject value of the promise returned by the visit method

| Param | Type | Description | |:------|:--------------------|:-----------------------------------| | text | string | The text of the link to be clicked |

page.fillIn(text, options) ⇒ function

Page.prototype.fillIn - Fills in an input or textarea that is attached to a label

Kind: instance method of Page
Returns: function - returns a function usable in a promise chain

| Param | Type | Description | |:--------|:--------------------|:---------------------------------------------------------------------------------------| | text | string | the visible content of the label attached to the input via a for | | options | object | the content - a string will be converted to an object with the format: { 'with': str } |

page.check(text) ⇒ function

Page.prototype.check - Checks a checkbox given the text of the checkbox

Kind: instance method of Page
Returns: function - A function usable in a promise chain

| Param | Type | Description | |:------|:--------------------|:--------------------------------------------------------------| | text | string | The visible content of the label associated with the checkbox |

page.clickButton(text) ⇒ Promise

Page.prototype.clickButton - Submits a form by gathering form values and creating a post request

Kind: instance method of Page
Returns: Promise - Returns a promise from the Post method

| Param | Type | Description | |:------|:--------------------|:--------------------------------------| | text | string | The visible text of the submit button |

page.select(text, options) ⇒ function

Page.prototype.select - Selects an option from a select box based on the text of the option

Kind: instance method of Page
Returns: function - a function usable in a promise chain

| Param | Type | Description | |:--------|:--------------------|:-------------------------------------------------------------------------------------------------------------------| | text | string | The visible text of the label associated with the select box | | options | object | an object to configure the selection - - a string will be converted to an object with the format: { 'from': str } |

page.wait(time) ⇒ function

Page.prototype.time - waits for roughly the amount of milliseconds to pass before resolving the next promise

It's important to note that the time the promise actually executes after may be a bit longer than the amount of time specified, due to javascript's event loop not actually interrupting currently executing code. For instance, this method won't interrupt an infinite loop.

Kind: instance method of Page
Returns: function - a function usable in a promise chain

| Param | Type | Description | |:--------|:--------------------|:-------------------------------------------------------------------------------------------------------------------| | text | string | The visible text of the label associated with the select box | | options | object | an object to configure the selection - - a string will be converted to an object with the format: { 'from': str } |

Contributing

  • Clone this repo
  • Run yarn to install dependencies
  • Run npm test to run tests
  • Run DEBUG=true npm test to run tests