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

@clubedaentrega/test-spec

v1.5.1

Published

A parser and runtime for markdown-inspired documentation and testing files

Downloads

9

Readme

Test Spec Parser

Build Status Inline docs Dependency Status

A parser and runtime for markdown-inspired documentation and testing files

Install

npm install @clubedaentrega/test-spec --save

Usage

var spec = require('@clubedaentrega/test-spec')

// Usually, the source is read from some *.md file
var source = '# Title\n'+
	'## Sub section\n'+
	'Some textual content\n'+
	'\tuser:\n'+
	'\t\tname: "Gui".toUpperCase()'

// Compile the source to a tree of section, text and value blocks
var mainSection = spec.compile(source),
	subSection = mainSection.children[0],
	valueBlock = subSection.children[1],
	// Execute the value block
	value = valueBlock.run()

console.log(value) // {user: {name: 'GUI'}}

Concepts

Testing is, at the same time:

  • very great because it lets you trust code is ready for production!
  • extremely boring to write, because test code is dumb and repetitive

This module tries to solve this by making testing code more concise and unifying testing and documentation.

Markdown was choosen because it's easy to write/read and it's not code!

This module is the fundamental parser and compiler for api-test, but can be used separately.

Syntax and parsing

This module implements a tiny subset of markdown: headers, paragraphs and code blocks. It does not aim at understanding any other feature (like lists, images, links, etc), but those constructions are accepted. That is, they are not considered valid syntax, but are simply treated as text.

The source is first transformed into a tree of sections (headers). Each section may have sub-sections, text paragraphs and value blocks.

Compiling

Parsed values are compiled to native JS functions, exposing a run() method, like in example above.

Value syntax

The syntax for value expressions was designed to be concise and expressive. The values will be eval'ed as normal JS with a context with special variables (see default context bellow).

The object can be a simple JS value, like:

new Date

Or an object with one property by line and tabs used to declare sub-objects:

user:
	name:
		first: 'Happy'
		last: 'Customer'
	age: 37 + 2
	country: 'cm'.toUpperCase()

Or mixins, like:

user with name.first: 'Unhappy'

Learn more about the syntax in the file value-syntax.md

Default context

The following functions are defined in spec.baseContext and can be used to provide a common set of utility functions to tests.

  • randomStr([len=8], [alphabet=a-zA-Z0-9+/])
  • randomHex([len=8])
  • randomCode([len=8])
  • randomEmail([domain='example.com'])
  • randomUrl([base='http://example.com'])
  • random([min=0],[max=1])
  • randomInt([min=0],[max=100])
  • randomBool()
  • randomDate([interval=1day], [base=now]): return a random date in the past
  • randomOf(...values): return one of its arguments
  • empty: the empty object {}

Docs

See complete docs