https://github.com/ioncakephper/yaml2test
Create jest-compatible tests from YAML notation.
https://github.com/ioncakephper/yaml2test
generate generate-code jest test testing-tool tests yaml yaml-files
Last synced: 8 months ago
JSON representation
Create jest-compatible tests from YAML notation.
- Host: GitHub
- URL: https://github.com/ioncakephper/yaml2test
- Owner: ioncakephper
- License: mit
- Created: 2022-01-27T19:14:09.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-12-07T23:55:10.000Z (about 1 year ago)
- Last Synced: 2025-04-14T07:07:24.605Z (8 months ago)
- Topics: generate, generate-code, jest, test, testing-tool, tests, yaml, yaml-files
- Language: JavaScript
- Homepage:
- Size: 1020 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# yaml2test
Create jest-compatible tests from YAML notation.
[](https://deepscan.io/dashboard#view=project&tid=15501&pid=20018&bid=531871)
## Synopsis
```shell-session
$ yaml2jest -h
$ yaml2jest help
$ yaml2jest -V
$ yaml2jest [build] [.yaml]
$ yaml2jest [build] [.yaml] -o [.test[s]][.[jt]s]
$ yaml2jest [build] [.yaml] -c [.json]
$ yaml2jest [build] [.yaml] -o [.test[s]][.[jt]s] -c [.json]
$ yamljest init [[.json]]
```
## Install
Use `npm` and install with `-g` switch to have the `yaml2jest` CLI.
```shell-session
$ npm i -g yaml2test
```
## Usage
Create `app-tests.yaml` as follows:
```yaml
- my application:
- can:
- create files and folders
- read data from .csv files
- should:
- work as cli
- work as an importable package
- tests for my application:
- should be:
- easy to read
- error free
```
### CLI
Get help:
```shell-session
$ yaml2jest -h
```
```txt
Usage: yaml2jest [options] [command]
Create tests from YAML notation
Options:
-V, --version output the version number
-h, --help display help for command
Commands:
build [options] build tests in a test file (default command)
init [configname] create settings file
help [command] display help for command
```
Get help of `build` -- `yaml2jest`'s defauld sub-command:
```shell-session
$ yaml2jest help build
```
```txt
Usage: yaml2jest build [options]
build tests in a test file (default command)
Options:
-o, --output fullpath to test file to create (default: .test.js)
-c, --config configuration filename (default: "yaml2jest.json")
-h, --help display help for command
```
**Example 1**: Create test file from `.yaml` file:
```shell-session
$ yaml2jest app-tests
```
> use `app-tests.yaml` file as source and generate `app-tests.test.js` file, which is a `jest` compatible test file.
Generated `app-tests.test.js` will look as follows:
```js
describe("my application", () => {
describe("can", () => {
it.todo("create files and folders");
it.todo("read data from .csv files");
});
describe("should", () => {
it.todo("work as cli");
it.todo("work as an importable package");
});
});
describe("tests for my application", () => {
describe("should be", () => {
it.todo("easy to read");
it.todo("error free");
});
});
```
**Example 2**: Specify an output file (path and name of test file to generate)
```shell-session
$ yaml2jest app-tests -o my-app
```
> use `app-tests.yaml` file as source and generate the output file `my-app.app.test.js`
### Code
Use the `app-tests.yaml` as described for CLI.
```js
const {createSuite} = 'yaml2test`;
const yamljs = require('yamljs');
let items = yamljs.load('app-tests.yaml');
let code = createSuite(items);
console.log(code);
```
## YAML file examples
### One of more test cases
```yaml
- test case 1
- test case 2
```
### Suite as array item with test cases
```yaml
- Suite:
- test case 1
- test case 2
```
### Parent suite with as item several child suites (as items)
```yaml
- Suite:
- child suite 1:
- test case 1
- test case 2
- child suite 2:
- test case 3
- test case 4
```
### Several parent suites as items with several child suites (as items)
```yaml
- Parent Suite 1:
- child suite 1:
- test case 1
- test case 2
- child suite 2:
- test case 3
- test case 4
- Parent Suite 2:
- child suite 3:
- test case 5
- test case 6
- child suite 4:
- test case 7
- test case 8
```
### Suite object (as object) with test cases
```yaml
Suite:
- test case 1
- test case 2
```
### Parent suite with several child suites (as object)
```yaml
Suite:
child suite 1:
- test case 1
- test case 2
child suite 2:
- test case 3
- test case 4
```
### Several parent suites with several child suites (as object)
```yaml
Parent Suite 1:
child suite 1:
- test case 1
- test case 2
child suite 2:
- test case 3
- test case 4
Parent Suite 2:
child suite 3:
- test case 5
- test case 6
child suite 4:
- test case 7
- test case 8
```