Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/ioncakephper/yamlspec
- Owner: ioncakephper
- License: mit
- Created: 2021-03-09T09:50:33.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-09-24T06:30:41.000Z (over 3 years ago)
- Last Synced: 2024-11-21T05:31:35.260Z (2 months ago)
- Topics: generated-code, jasmine, spec, test, test-automation, testing-tools, yaml
- Language: JavaScript
- Homepage:
- Size: 1.42 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
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] sourceFilenameYAML 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: fsitems:
- 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. |