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

jstd-shim

v0.1.3

Published

A jstd shim for executing jstd tests outside the JSTD environment

Downloads

9

Readme

JSTD shim

Execute jstd tests in your test runner of choice (for example, Karma). This project attempts to replicate the jstd window environment and its API (functions such as TestCase and AsyncTestCase) so that a project can continue to run existing jstd tests while migrating to other test runners and libraries.

General Use

Include the jstd.shim.js file in the window before including/injecting jstd test files. The file will define a global called JSTD_SHIM which can be used after jstd test files have loaded to execute the tests with JSTD_SHIM.execute(). It will also define global functions that exist in the jstd environment (TestCase, AsyncTestCase, asserts, etc.).

Reporter

Default

By default JSTD_SHIM outputs general test result information to the console. The following code implements the default reporter object inside jstd.shim.js:

var reporter = Object.create({
    // test pass
    success: function (resultObj) {},
    // test fail
    error: function (error, resultObj, name) {
        var message;
        name = name || error.name;
        console.log(name, error);
        if (error.stack) {
            console.error(error.stack);
        }
    },
    // occurs after a success OR error
    result: function (resultObj) {
        console.log((resultObj.success ? 'SUCCESS' : 'FAIL') + ' ' + resultObj.description);
    },
    // occurs on test complete
    complete: function (stats) {
        console.log("  ****  JSTD SHIM RESULTS: " + (stats.fail > 0 || stats.error > 0 ? 'FAIL' : 'SUCCESS') + "  ****  ");
        console.log(" Ran:     " + stats.total + " in " + (stats.totalTime / 1000).toFixed(3) + " secs");
        console.log(" Passed:  " + stats.pass);
        console.log(" Failed:  " + stats.fail);
        console.log(" Error:   " + stats.error);
        console.log(" Ignored: " + stats.ignore);
    }
});

Overriding

In order to adapt the code to other uses the JSTD_SHIM global provides a method to override the default functions of the reporter.

JSTD_SHIM.modifyReporter(function (defaultReporter) {
    // return modified reporter
    return defaultReporter.success = function (resultObj) {
        console.log("A test passed! Description: " resultObj.description);
    }
});

Use with Karma/Jasmine

In karma.conf.js, include the jstd.shim.js and jstdshim-jasmine-karma.js files after jasmine has been loaded in the files array:

files = [
    JASMINE,
    JASMINE_ADAPTER,
    'jstd.shim.js',
    'adapters/jstdshim-jasmine-karma.js',
    'some-jstd-tests/**/*.js'
]

Contributing

Running Tests

Test changes to jstd.shim.js after installing Karma (e.g. npm install) from the command line with karma start.

Changes

  • 0.1.0 - Initial release
  • 0.1.1 - Noop reporter, package.json updates, doc refinement