Git Product home page Git Product logo

test-generator-cli's Introduction

test-generator-cli

Tool to generate tests from cases.

Installation

npm install @simplrjs/test-generator-cli -g

Global installation is not necessary. You can install this package with:

npm install @simplrjs/test-generator-cli --save-dev

and use it with npm-scripts.

Command line

Usage

test-generator-cli -h

Arguments

Argument Type Default Description
-h, --help boolean false Show help.
-v, --version boolean false Show current version.
-p, --project string ./ Project directory path.

Project tests structure

Let's say you picked src as your project directory.

├── src
    └── tests
        ├── cases
        │   ├── __tests__
        │   |   └── __snapshots__
        │   ├── case-1
        │   │   ├── ...
        │   │   ├── test-config.json
        │   │   └── case.test.tpl
        │   └── case-2
        └── default.test.tpl
File / Directory Description
__tests__ Generated tests output directory.
__snapshots__ Generated tests snapshots directory.
case-1, case-2 Directories for test cases.
case.test.tpl Test template file for certain test case. It's not required. If case.test.tpl not found in case directory, test template will fallback to default.test.tpl.
test-config.json Config file for a test case. You can reach it template. Config structure is at your discretion.
default.test.tpl Default test template file.

Templates

Package supports two kinds of templates:

  • case.test.tpl - test template file for certain test case. It's not required. If case.test.tpl not found in case directory, test template will fallback to default.test.tpl.
  • default.test.tpl - default test template file.

Template should be a valid TypeScript file that can have Handlebars expressions.

Supported expressions

Expression Description
{{caseName}} Test case name.
{{projectDirectory}} Project directory path.
{{json testConfig}} Test case config file (test-config.json) content.

Sample

import * as path from "path";
import { Bundler } from "@src/bundler";

test("{{caseName}}", async done => {
    const projectDirectory = "{{projectDirectory}}";
    const testConfig = {{{json testConfig}}};
    const entryFile = path.join(projectDirectory, testConfig.Entry);

    try {
        const bundleResult = await new Bundler()
            .BundleAll([entryFile]);
        expect(bundleResult[0].bundledContent).toMatchSnapshot();
        done();
    } catch (error) {
        done.fail(error);
    }
});

License

Released under the MIT license.

test-generator-cli's People

Contributors

martynaszilinskas avatar deividasbakanas avatar shadowtime2000 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.