Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/clubedaentrega/test-spec
A parser and runtime for markdown-inspired documentation and testing files
https://github.com/clubedaentrega/test-spec
Last synced: 28 days ago
JSON representation
A parser and runtime for markdown-inspired documentation and testing files
- Host: GitHub
- URL: https://github.com/clubedaentrega/test-spec
- Owner: clubedaentrega
- License: mit
- Created: 2016-01-14T23:53:14.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-07-26T16:52:09.000Z (over 8 years ago)
- Last Synced: 2024-12-01T12:37:30.241Z (about 1 month ago)
- Language: JavaScript
- Size: 407 KB
- Stars: 0
- Watchers: 7
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE
Awesome Lists containing this project
README
# Test Spec Parser
[![Build Status](https://travis-ci.org/clubedaentrega/test-spec.svg?branch=master)](https://travis-ci.org/clubedaentrega/test-spec)
[![Inline docs](http://inch-ci.org/github/clubedaentrega/test-spec.svg?branch=master)](http://inch-ci.org/github/clubedaentrega/test-spec)
[![Dependency Status](https://david-dm.org/clubedaentrega/test-spec.svg)](https://david-dm.org/clubedaentrega/test-spec)A parser and runtime for markdown-inspired documentation and testing files
## Install
`npm install @clubedaentrega/test-spec --save`## Usage
```js
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 repetitiveThis 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](https://github.com/clubedaentrega/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](https://github.com/clubedaentrega/test-spec/blob/master/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](http://clubedaentrega.github.io/test-spec)