Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ioncakephper/yamlspec

Generate Jasmine-compatible .js specification files from .yaml-formatted specification file
https://github.com/ioncakephper/yamlspec

generated-code jasmine spec test test-automation testing-tools yaml

Last synced: 12 days ago
JSON representation

Generate Jasmine-compatible .js specification files from .yaml-formatted specification file

Awesome Lists containing this project

README

        

# yamlspec

Generates `JavaScript` package specification files from a `.yml` specification file, giving both developers and QA team a quick and productive tool for writing specifications.

## Installation

Install `yamlspec` globally so you can invoke it as command-line program:

```bash
npm i -g yamlspec
```

Check `yamlspec` runs at command-prompt:

```bash
yamlspec -V
v1.0.5
```

## YML-format specifications

To expedite specification formulation process, `yamlspec` introduces its alternative to traditional `.js` code. Those familiar with `Jasmine` and its related specification frameworks based on `.js` will recognize the `describe` and `it` entries.

The example below contains specifications for `` package, which is invoked with a `require` statement. The package is placed in a constant whose name is also ``.

The specification contains two `describe` sections, aka "test sets", inside the `items` key. Each section contains its own test cases as `it` entries. The test cases fall under a test set's `items`.

```yaml
package:
- require:
- const:
items:
- describe:
what:
items:
- it: should have method a
- describe:
what: method a
items:
- it: should return a string
- it: should return an empty string when input parameter is empty
- it: should return en empty string when input parameter is not specified
- it: should return an empty string when input parameter has only delimiters
```

## JavaScript Code

```js
const yamlspec = require('yamlspec')

let sourceFilename = '/path/to/specsInYamlFormat.yml';

let source = yamlspec.loadFile(sourceFilename)
yamlspec.renderFile('/path/to/spec/folder/specfilename.js', source);
```

## CLI

```bash
yamlspec [options] sourceFilename
```
```bash
yamlspec -h
Usage: yamlspec [options] sourceFilename

YAML to Jasmine specification generator.

Options:
-V, --version output the version number
-o, --output name of extended specification filename
-s, --suffix suffix text to go after test basename (default: "Spec")
-p, --path root path for generated specification files (default: "./spec")
-t, --templatepath path to templates (default: ".\\bin\\templates")
-h, --help display help for command
```

## Examples

1. Create your working folder with `mkdir myfolder`, `cd myfolder`, and create `mypackage.yml` as follows:

```yaml
package:
request: fs
const: fs

items:
- describe:
what: Simple test suite
items:
- it: First test description
- it: Second test description
- it: Third test description
```

2. Run `yamlspec`

```bash
yamlspec mypackage
```

`yamlspec` generates the `./spec/mypackageSpec.js`

```js
const fs = require('fs');

describe('Simple test suite', () => {

// First test description
it('First test description', () => {
//
// @todo First test description
//
expect(0).toEqual(1)
})

// Second test description
it('First test description', () => {
//
// @todo Second test description
//
expect(0).toEqual(1)
})

// Third test description
it('Third test description', () => {
//
// @todo Third test description
//
expect(0).toEqual(1)
})
})
```

3. Invoke `Jasmine`, confirming your specifications are available. All will fail.

```bash
jasmine
```

## API
### Functions



loadFile(sourceFilename, [options])Object


Load source file with YAML specification.




render(source, [options])string


Render extended specification content.



renderFile(outputFilename, source, [options])


Render file with exptended specification content.



### loadFile(sourceFilename, [options]) ⇒ Object
Load source file with YAML specification.

**Kind**: global function
**Returns**: Object - Specification object.

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| sourceFilename | string | | Source filename in .yaml format |
| [options] | Object | {} | File loading options. |

### render(source, [options]) ⇒ string
Render extended specification content.

**Kind**: global function
**Returns**: string - Expanded resulting specification content.

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| source | Object | | Specification object. |
| [options] | Object | {} | Rendering options. |

### renderFile(outputFilename, source, [options])
Render file with exptended specification content.

**Kind**: global function

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| outputFilename | string | | Path-like string of output filename. |
| source | Object | | Specification object. |
| [options] | Object | {} | Rendering options. |