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

@kkitahara/esdoc-examples-test-plugin

v1.1.6

Published

ESDoc Examples-Test Plugin - an ESDoc plugin which converts the contents of @example blocks into test codes.

Downloads

7

Readme

JavaScript Style Guide license pipeline status version bundle size downloads per week downloads per month downloads per year downloads total

ESDoc Examples-Test Plugin

This plugin converts the contents of @exmaple blocks into test codes.

Currently, the plugin can generate only the codes that use ES6 modules.

Instllation

npm install esdoc @kkitahara/esdoc-examples-test-plugin

Configuration

The minimum configuration may like:

{
  "source": "./src",
  "destination": "./doc",
  "includes": ["\\.js$|\\.mjs$"],
  "plugins": [
    {
      "name": "@kkitahara/esdoc-examples-test",
      "option": {
        "path": "./examples-test"
      }
    }
  ]
}

Complete list of options:

| Name | Default | Description | |-------------------|--------------------------------------------------------------------|------------------------------------------------------------------------| | path | — | Output directory path. (required) | | suffix | "-example" | Added to the name of each test code. | | mainOutput | "run-test.mjs" | Name of the main test code. | | testDriverPath | "@kkitahara/esdoc-examples-test-plugin/src/simple-test-driver.mjs" | Test driver path. | | quietPass | false | If true, no log output for passed tests. | | testDriverVarName | "testDriver" | Change it if the default conflicts with your example codes. | | replace | [] | e.g. [['a', 'b']] will replace all 'a' in the examples with 'b'. |

Example

Here, we consider that path is set at ./examples-test, and other options are set at the default values. Let's consider an @example block like:

/**
 * @example
 * let a = 2
 * let b = 3
 *
 * // pass
 * a + b // 5
 *
 * // fail
 * a - b // 5
 *
 * // pass
 * a() // Error
 *
 * // fail
 * a + b // Error
 */

it will be converted into a test code like:

import testDriver from '@kkitahara/esdoc-examples-test-plugin/src/simple-test-driver.mjs'

let a = 2
let b = 3

// pass
testDriver.test(() => { return a + b }, 5, 'my-awesome-example0_0', false)

// fail
testDriver.test(() => { return a - b }, 5, 'my-awesome-example0_1', false)

// pass
testDriver.test(() => { return a() }, Error, 'my-awesome-example0_2', false)

// fail
testDriver.test(() => { return a + b }, Error, 'my-awesome-example0_3', false)

What this plugin does is to detect the lines that match the pattern A // B. If A is not empty, then, the line is converted to a code like testDriver.test(() => { return A }, B, 'my-awesome-example0_0'). Inside the testDriver.test() call, the default test driver will assert the input values by using the default assert module like assert.strictEqual(A, B) if B !== Error and assert.throws(() => { return A }) otherwise.

A test code will be produced per @example block. To run all the tests, do

node --experimental-modules ./examples-test/run-test.mjs

Coverage

The following may be used to get test-coverage report.

npx nyc --extension .mjs -i esm node ./examples-test/run-test.mjs

For this, you need nyc and esm.

LICENSE

© 2019 Koichi Kitahara
Apache 2.0