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

osh-iso-test

v0.1.0

Published

openscihub.org: test your isomorphic web apps and frameworks

Downloads

30

Readme

Iso test

Test your isomorphic web app or framework.

Installation

npm install osh-iso-test

Usage

A file test/test.js that uses the mocha testing framework:


var iso = require('osh-iso-test');

describe('app', function() {
  it('should work', function(done) {
    this.timeout(0);
    iso({
      basedir: __dirname + '/iso',
      port: 3333
    }, done);
  });
});

where the test directory looks like:

- test/
  - test.js
  - iso/
    - test1/
      - index.js
      - main.js
    - test2/
      - index.js
      - something.js

Each index file in each test directory of the iso folder should export a single function that accepts an express instance and a callback. For example, test/iso/test1/index.js could be:

var serveStatic = require('serve-static');

module.exports = function(app, done) {
  var test = this;

  app.get('/', function(req, res) {
    res.send(
      '<html><body>' +
      test.iso +                  // injects '<script src="/iso.js"></script>'
      test.script('/main.js') +   // injects '<script src="/test1/main.js"></script>'
      '</body></html>'
    );
  });
  app.use(serveStatic(__dirname));
  done();
};

Notice that we needed to lookup this.route to inject the correct path to a script for the browser.

Including the /iso.js script exposes the iso object on the global scope in the browser; the main.js script uses the iso object to report the test result back to the test runner.

this/iso properties

The following variables are accessible on the this object within the exported function in a test's index.js file and on the global iso object in the browser.

name

The name of the test. It is simply the name of the directory in which the index.js file is defined.

For example, in test/iso/test1/index.js, you get

module.exports = function(app, done) {
  console.log(this.name); // test1
  done();
};

route

Simply this.name prefixed with '/'.

this properties

These are available in only the index.js function (i.e. the "server").

script

A function to inject a script element with the proper path. Every test is hosted under a route defined by the name of its containing directory; it's annoying to have to manipulate __dirname.

For example, in test/iso/test1/index.js:

this.script('/main.js'); // '<script src="/test1/main.js"></script>'

iso properties

These are available in the browser only.

iso.report

In the browser, call this function to report the status of your test back to the runner. It takes a string as argument.

For example, a really useless test/iso/test1/main.js:

iso.report('Success');

License

MIT