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 🙏

© 2025 – Pkg Stats / Ryan Hefner

harmonyc

v0.14.0

Published

Harmony Code - model-driven BDD for Vitest

Downloads

788

Readme

Harmony Code

A test design & BDD tool that helps you separate the what to test from the how to automate it. You write test cases in a simple easy-to-read format, and then automate them with Vitest (and soon with other frameworks and languages).

Setup

You need to have Node.js installed. Then you can install Harmony Code in your project folder by:

npm install harmonyc

Then add it to your vitest.config.js or vite.config.js file, and specify which folder to watch for .harmony files:

import harmony from 'harmonyc/vitest'

export default {
  plugins: [harmony({ watchDir: 'src' })],
}

You can run it manually for all .harmony files in your src folder:

harmonyc src/**/*.harmony

This will generate .test.mjs files next to the .harmony files, and generate empty definition files for you.

Syntax

A .harmony file is a text file with a syntax that looks like this:

+ Products API:
  + Create:
    + Anonymous:
      - create product => !! "unauthorized"
    + Admin:
      - authenticate with "admin" => product count `0`
      - create product
        => product created
        => product count `1`
      - Delete:
        - delete product => product deleted => product count `0`

Indentation

The lines of a file are nodes of a tree. The tree is specified with the indentation of the lines, which is n times 2 spaces and a + or - with one more space. The + or - sign is considered to be part of the indentation.

Sequences and forks

- means a sequence: the node follows the previous sibling node and its descendants.

+ means a fork: the node directly follows its parent node. All siblings with + are separate branches, they will generate separate scenarios.

Phrases (actions and responses)

After the mark, every node can contain an action and zero or more responses, together called phrases. The action is the text before the =>, and the responses are the text after the =>.

Both actions and responses get compiled to simple function calls - in JavaScript, awaited function calls. Actions will become When_* functions, and responses will become Then_* functions. The return value of the action is passed to the responses of the same step as the last argument.

Arguments

Phrases (actions and responses) can have arguments which are passed to the implementation function. There are two types of arguments: strings and code fragments:

+ strings:
  + hello "John"
+ code fragment:
  + greet `3` times

becomes

test('T1 - strings', async () => {
  const P = new Phrases();
  await P.When_hello_("John");
})
test('T2 - code fragment', async () => {
  const P = new Phrases();
  await P.When_greet__times(3);
})

Labels

Labels are lines that start with - or + and end with :. You can use them to structure your test design. They are not included in the test case, but the test case name is generated from the labels.

Comments

Lines starting with # or // are comments and are ignored.

Error matching

You can use !! to denote an error response. This will verify that the action throws an error. You can specify the error message after the !!.

Variables

You can set variables in the tests and use them in strings and code fragments:

+ set variable:
  + ${name} "John"
    + greet "${name}" => "hello John"
+ store result into variable:
  + run process => ${result}
    + "${result}" is "success"

becomes

test('T1 - set variable', (context) => {
  const P = new Phrases();
  (context.task.meta.variables ??= {})['name'] = "John";
  await P.When_greet_(context.task.meta.variables?.['name']);
})
test('T2 - store result in variable', (context) => {
  const P = new Phrases();
  const r = await P.When_run_process();
  (context.task.meta.variables ??= {})['result'] = r;
  await P.Then__is_(`${context.task.meta.variables?.['result']});
})

Running the tests

License

MIT