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

yaml2test

v1.0.6

Published

Create tests from YAML notation

Downloads

4

Readme

yaml2test

Create jest-compatible tests from YAML notation.

DeepScan grade

Synopsis

$ yaml2jest -h
$ yaml2jest help

$ yaml2jest -V
$ yaml2jest [build] <basename>[.yaml]
$ yaml2jest [build] <basename>[.yaml] -o <testbasename>[.test[s]][.[jt]s]
$ yaml2jest [build] <basename>[.yaml] -c <configbasename>[.json]
$ yaml2jest [build] <basename>[.yaml] -o <testbasename>[.test[s]][.[jt]s] -c <configbasename>[.json]

$ yamljest init [<configbasename>[.json]]

Install

Use npm and install with -g switch to have the yaml2jest CLI.

$ npm i -g yaml2test

Usage

Create app-tests.yaml as follows:

- 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:

$ yaml2jest -h
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] <yamlfile>  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:

$ yaml2jest help build
Usage: yaml2jest build [options] <yamlfile>

build tests in a test file (default command)

Options:
  -o, --output <testfile>  fullpath to test file to create (default: <yamlfile-basename>.test.js)
  -c, --config <filename>  configuration filename (default: "yaml2jest.json")
  -h, --help               display help for command

Example 1: Create test file from .yaml file:

$ 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:

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)

$ 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.

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

- test case 1
- test case 2

Suite as array item with test cases

- Suite:
  - test case 1
  - test case 2

Parent suite with as item several child suites (as items)

- 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)

- 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

Suite:
  - test case 1
  - test case 2

Parent suite with several child suites (as object)

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)

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