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

jest-builder

v1.0.26

Published

Unit Tests builder is a testing toolkit developed on the top of Facebook's Jest framework for the developers and testers to seamlessly write unit tests for every scenarios.

Downloads

7

Readme

Build Status

Create and execute unit tests within minutes using Jest Framework


Unit Tests builder is a testing toolkit developed on the top of Facebook's Jest framework for the developers and testers to seamlessly write backend unit tests for every scenarios.

Installation


npm i jest-builder --save

Configuration


const testApp = require('jest-builder');
const test = new testApp({<--config-->})

Setting up your config


| Property | Description | Default Value | Type | | --- | --- | --- | --- | | file_path | Excel File Path | UnitTest.xlsx | string | | jest_flags | Jest CLI Flags (https://jestjs.io/docs/cli) | ["--passWithNoTests", "--coverage"] | array of string | | suite_name | Name of the test suite | Unit Test Suite | string | | html_report | Test case execution report in HTML format | false | boolean | | excel_report | Test case execution report in Excel format | false | boolean | | text_report | Test case execution report in Text format | false | boolean | | mail_report | Send an email using Nodemailer SMTP Service | {} | object |

Steps


  • Import and initialize the package
  • Add configuration (if required)
  • Create an excel file (if required)
  • Add the unit tests (Each row will be considered as a single unit test)
  • Execute the code

Excel Columns


| Test Case Name | Data | Expected Data | Validation | Function | Path | Skip Tests | | --- | --- | --- | --- | --- | --- | --- |

  • Test Case Name - Name of the Test Case
  • Data - Data that has to be provided to the function (Given Data)
  • Expected Data - Data that is expected after successful completion of test case or the data that is to be passed to the validations.
  • Validation - Jest validation expect functions. (For more: https://jestjs.io/docs/expect)
  • Function - Name of the function (without parentheses) that is to be executed for a specific test case.
  • Path - Relative path of the file where the function is declared.
  • Skip Tests - It is boolean or a Yes/No value. Yes/true will skip that test case and No/false will run it.

Note: (1) All the above columns are mandatory with the same name (2) To use multiple validations in one unit test use '/' as a delimeter. eg: toBe/toEqual (3) If you're not specifying the parameters in jest validation functions, it will take Expected Data as a parameter. e.g: If the Expected Data is "Login Success" and Validation is toBe, then toBe function will take "Login Success" as a parameter. Similarly, if you can also pass the parameters inside the validation function eg: toBeGreaterThan(20)

Example


Without configuration

After installing the package, create app.js file and initialize the test application.

const testApp = require('jest-builder');
const test = new testApp({})

Execute the code.

node app.js

Note:

As the config is empty it will create a dummy test file named UnitTest.xlsx in the root folder and execute the demo test written inside it. It can be used as a future reference as well

With configuration

After installing the package, create app.js file and initialize the test application (Now with a configuration)

const testApp = require('jest-builder');
const test = new testApp({
	"file_path" : "./UT_Manual.xlsx"
})

Create a controller file Login.js

module.exports.login = function (data) {
    if (data.username == 'xyz.abc')
        return "Login Success"
    else
        return "Login Failure"
}

Create a excel file UT_Manual.xlsx with the following tests.

| Test Case Name | Data | Expected Data | Validation | Function | Path | | --- | --- | --- | --- | --- | --- | | Login with Valid Data | {"username": "xyz.abc"} | Login Success | toBe | login | ./Login.js | | Login with invalid Data | {"username": "abc.xyz"} | Login Failure | toBe/toEqual | login | ./Login.js |

Execute the code.

node app.js

Result

Unit Tests
   √ Login with Valid Data (10 ms)
   √ Login with invalid Data (10 ms)
   Test Suites: 1 passed, 1 total
   Tests:       2 passed, 2 total
   Snapshots:   0 total
   Time:        0.781 s, estimated 1 s

Generate reports


3 types of reports are available in this toolkit i.e html, excel and text

app.js

const testApp = require('jest-builder');
const test = new testApp({
	"file_path" : "./UT_Manual.xlsx",
   "html_report": true,
   "excel_report": true,
   "text_report": true
})

Note:

  1. HTML, Excel and Text reports are generated in html-report folder, report.xlsx file and tests folder respectivly.
  2. To generate excel report, excel_reportand text_report property must be true.

Setting up Jest Flags


Jest provides variey of CLI flags which can also be passed in the configuration.

app.js

const testApp = require('jest-builder');
const test = new testApp({
	"jest_flags": ["--silent", "--showConfig"]
})

Note:

For more Jest CLI flags, follow https://jestjs.io/docs/cli

Send the reporting email


This toolkit also provides a feature of sending an test reporting email.

app.js

const testApp = require('jest-builder');
const test = new testApp({
	"mail_report": {
       "send_mail": true/false //Must be true if you want to activate the reporting email,
       "reports": ["html", "excel", "text"],
       "smtp_config": {
           "host": "<--SMTP Host-->",
           "port": 1234,
           "secure": true/false,
           "auth": {
               "user": "<--User Name-->",
               "pass": "<--Password-->",
           }
       },
       "mail_options": {
           from: "<--From Email Address-->",
           to: "<--To Email Address(1), To Email Address(2)...,To Email Address(n)-->",
           subject: "<--Email Subject-->",
           html: "<--Email HTML Body-->",
           attachments: [],
       }
   }
})

For more details, follow https://jestjs.io/docs

For queries, reach out to [email protected] (Jenil Thakkar)