Skip to content

HtetLinMaung/starless-unit-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Starless Unit Test

Command Line Unit Testing tool.

Installation

npm install -g starless-unit-test

Getting Started

Let's get started by writing a test for a hypothetical function that adds two numbers. First, create a calculator.js file under utils folder:

function sum(a, b) {
  return a + b;
}

exports.sum = sum;

Then, create a file named calculator.json. This will contain our actual test:

{
  "adds 1 + 2 to equal 3": {
    "type": "function",
    "scriptPath": "./utils",
    "function": "calculator.sum",
    "expect": [1, 2],
    "toBe": 3
  }
}

Finally, run starless-unit-test calculator.json and it will print this message:

PASS  ./calculator.test.js
✓ adds 1 + 2 to equal 3 (5ms)

You just successfully wrote your first test using Starless Unit Test program!

API Test

You can also test for api endpoints. Response format for api is like this {data: {}, status: 200}. That's why we add expectArg to data.data.

{
  "adds 1 + 2 to equal 3": {
    "type": "api",
    "expect": {
      "url": "http://localhost:3000/sum",
      "method": "post"
      "body": {
        "a": 1,
        "b": 2
      }
    },
    "expectArg": "data.data",
    "toBe": 3
  }
}

Test With Browser

You can also test from browser. Puppeteer is used for testing with browser.

{
  "Is starless unit test package existed?": {
    "type": "browser",
    "expect": [
      {
        "action": "goto",
        "args": [
          "'https://www.npmjs.com/package/starless-unit-test'",
          {
            "waitUntil": "networkidle2"
          }
        ]
      },
      {
        "action": "evaluate",
        "args": [
          "(selector) => {return document.querySelector(selector).textContent;}",
          "'#readme h1'"
        ]
      }
    ],
    "toBe": "'Starless Unit Test'"
  }
}

More Resources

Jest is internally used for unit testing. You can see more at Jest .

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published