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 🙏

© 2026 – Pkg Stats / Ryan Hefner

code-tester

v4.3.0

Published

React component to run Mocha tests on-the-fly on live code edits.

Downloads

231

Readme

Code Tester

React component to run Mocha tests on-the-fly on live code edits.

Installation

Code-Tester can be used as a standalone app or as a component in an existing React app. To use standalone, clone the repo and run:

$ git clone https://github.com/OperationSpark/code-tester.git
$ cd code-tester
$ yarn install
$ yarn start

A server will spin up and serve the app at http://localhost:3000

Use as React Component

$ npm install code-tester

Usage

  <CodeTester
    autoRun
    initialCode={boilerplate}
    instructions={instructions}
    iFrameUrl="/test-runner.html"
    onAnyCode={handleAnyCode}
    onLintedCode={handleLintedCode}
    onTestResults={handleTestResults}
    showLints
    testSpec={testSpec}
  />

Props

| Name | Type | Default | Description | |--------------------------|----------|---------|-------------------------------------------------------------------------| | autoRun | Boolean | false | If enabled, tests will run after any Editor input. | | initialCode | String | | Initial text in the Editor | | instructions | String | | Instructions for the user to pass the tests. (GitHub-flavored Markdown) | | iFrameUrl | String | | Path to HTML file for running Mocha tests | | onAnyCode | Function | | Handler called on any code input to the Editor | | onLintedCode | Function | | Handler called on Editor input only if Editor code passes lint tests | | onTestResults | Function | | | | onPaste | Function | | Handler called on paste to the Editor | | disablePasting | Boolean | false | If true the user cannot paste into the Editor | | showLints | Boolean | | | | testSpec | String | | | | handleInstructionsChange | Function | | | | handleTestSpecChange | Function | | | | handleBoilerplateChange | Function | | | | editMode | Boolean | false | | | preventGrep | Boolean | false | Disables mocha grepping in html reporter |

Add additional notes about how to deploy this on a live system

Examples

Inside an app:

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import CodeTester from 'code-tester';

class App extends Component {
  renderTester() {
    const handleTestResults = (passCount, failCount, runTime) => {
      // Results from Mocha tests
    };

    const handleLintedCode = (lintedCode) => {
      // Do something only if Editor code passes lint tests
    };

    const handleAnyCode = (code) => {
      // Do something on any input to Editor
    };

    return (
      <CodeTester
        autoRun
        initialCode={boilerplate}
        instructions={instructions}
        iFrameUrl="/test-runner.html"
        onAnyCode={handleAnyCode}
        onLintedCode={handleLintedCode}
        onTestResults={handleTestResults}
        showLints
        testSpec={testSpec}
      />
    );
  }
}

ReactDOM.render(<App />, document.getElementById('app'));

Testing code locally

You'll need to run a repo containing code you want to test through a static server with CORS support. I recommend http-server.

 $ npm install http-server -g
 $ cd [path/to/local/repo]
 $ http-server --cors
  Starting up http-server, serving ./
 Available on:
   http://127.0.0.1:8080

Once that is running update the componentDidMount cycle in src/App.jsx to take an appropriate path to a code quiz directory.

Then run npm run dev to start the code tester.

Testing code locally

You'll need to run a repo containing code you want to test through a static server with CORS support. I recommend http-server.

  $ npm install http-server -g
  $ cd [path/to/local/repo]
  $ http-server --cors

  Starting up http-server, serving ./
  Available on:
    http://127.0.0.1:8080

Once that is running update the componentDidMount cycle in src/App.jsx to take an appropriate path to a code quiz directory.

Then run npm run dev to start the code tester.

Built With

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

License

MIT