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

tdt

v0.0.5

Published

Typed Decision Table

Downloads

7

Readme

Typed Decision Table

Overview

This tool, written in Typescript, automates the generation of test cases in the form of a Decision Table from minimal inputs. There's no need to manually input each cell in the table.

Leveraging the power of Typescript generics, the tool ensures that the generated test cases are typed according to your specifications. This feature facilitates the accurate handling of keys and values in any test code you write.

Furthermore, not just the outputs but also some of the inputs are typed using generics, streamlining the process of preparing the necessary inputs.

Additional features of this tool include:

  • File output in JSON or Markdown format.
  • Support for the strength of the Covering Array.

Install

npm install tdt

Example

Generate test cases as shown in the example below. The output is an array of objects, with each object representing a single test case.

Example:
const tests = generateTests(
	domain,
	defaults,
	exclusions,
	perspectives,
);

console.log(tests)
/*
[
	{
		'Condition.User.IsRegistered': 'True',
		'Condition.User.IsAdmin': 'True',
		'Condition.Device': 'Mobile',
		ExpectedResult: 'Failure',
		Perspective: 'Only registered users accessed from PC can access.',
		ID: '1'
	},
	{
		'Condition.User.IsRegistered': 'True',
		'Condition.User.IsAdmin': 'True',
		'Condition.Device': 'PC',
		ExpectedResult: 'Success',
		Perspective: 'Only registered users accessed from PC can access.',
		ID: '2'
	},
	{
		'Condition.User.IsRegistered': 'True',
		'Condition.User.IsAdmin': 'False',
		'Condition.Device': 'Mobile',
		ExpectedResult: 'Failure',
		Perspective: 'Only registered users accessed from PC can access.',
		ID: '3'
	},
	{
		'Condition.User.IsRegistered': 'True',
		'Condition.User.IsAdmin': 'False',
		'Condition.Device': 'PC',
		ExpectedResult: 'Success',
		Perspective: 'Only registered users accessed from PC can access.',
		ID: '4'
	},
	{
		'Condition.User.IsRegistered': 'False',
		'Condition.User.IsAdmin': 'False',
		'Condition.Device': 'Mobile',
		ExpectedResult: 'Failure',
		Perspective: 'Only registered users accessed from PC can access.',
		ID: '5'
	},
	{
		'Condition.User.IsRegistered': 'False',
		'Condition.User.IsAdmin': 'False',
		'Condition.Device': 'PC',
		ExpectedResult: 'Failure',
		Perspective: 'Only registered users accessed from PC can access.',
		ID: '6'
	}
]
*/

Usage

To generate test cases, you'll need the following inputs:

  1. Prepare arguments of generateTests function. 1-1. Parameter domains (all potential values for the parameters). 1-2. Default values for the parameters. 1-3. Combinations of values to exclude. 1-4. Testing perspectives.
  2. Call generateTests function.

1. Prepare arguments of generateTests function

1-1. Parameter Domains

List all potential values for every parameter associated with the test condition. This should also encompass expected results.

Example:
const domain = {
	"Condition":{
		"User":{
			"IsRegistered":[
				"True",
				"False"
			],
			"IsAdmin":[
				"True",
				"False"
			]
		},
		"Device":[
			"Mobile",
			"PC"
		]
	},
	"ExpectedResult":[
		"Success",
		"Failure",
		"Any"
	]
} as const;
type ExampleDomain = typeof domain;

Unlike other inputs, this one isn't typed as a generic type. You have the flexibility to define its structure, provided it meets the necessary criteria. Based on this structure, the subsequent inputs (items 2., 3., and 4.) will be automatically typed.

1-2. Default Values for the Parameters

Specify the default values for the parameters outlined in section 1.. For each parameter, select a value from the list of potential values. These defaults are used when a parameter value isn't explicitly set in a test case.

Example:
const defaults : Defaults<ExampleDomain> = {
	"Condition":{
		"User":{
			"IsRegistered" : "True",
			"IsAdmin" : "False"
		},
		"Device":"Mobile"
	},
	"ExpectedResult":"Any"
} as const;

1-3. Combinations of Values to Exclude

Use this to omit combinations of parameter values that are either impossible or lack significance. Multiple combinations can be excluded.

Example:
const exclusions:Exclusions<ExampleDomain> = [
	{
		"Condition.User.IsRegistered" : "False",
		"Condition.User.IsAdmin" : "True"
	}
] as const;

1-4. Testing Perspectives

This determines the approach for generating test cases. Typically, test cases should be formulated based on a specific perspective or focus. Hence, this tool generates all test cases in alignment with the provided perspectives.

Example:
const perspectives:Perspectives<ExampleDomain> = [
	{
		"title": "Only registered users accessed from PC can access.",
		"constants": {},
		"variables": [
			"Condition.User.IsRegistered",
			"Condition.User.IsAdmin",
			"Condition.Device",
		],
		"expect": (test:Test<ExampleDomain>)=>{
			if(
				test["Condition.User.IsRegistered"] === "True" &&
				test["Condition.Device"] === "PC"
			){
				test["ExpectedResult"] = "Success";
			}else{
				test["ExpectedResult"] = "Failure";
			}
			return test
		},
	}
] as const;

2. Call generateTests function

const tests = generateTests(
    domain,
    defaults,
    exclusions,
    perspectives,
);
console.log(tests)

Features

File Output in JSON or Markdown Format

By setting certain options in the generateTests arguments, you can export the test cases to files.

Example of setting an option:
const tests = generateTests(
	domain,
	defaults,
	exclusions,
	perspectives,
+	{
+		json:{
+			file_path: '01.json',
+		},
+		markdown:{
+			file_path: '01.md',
+			true_symbol: 'X',
+			false_symbol: '-'
+		}
+	}
);
Example of a JSON file:
[
	{
		"Condition.User.IsRegistered": "True",
		"Condition.User.IsAdmin": "True",
		"Condition.Device": "Mobile",
		"ExpectedResult": "Failure",
		"Perspective": "Only registered users accessed from PC can access.",
		"ID": "1"
	},
	{
		"Condition.User.IsRegistered": "True",
		"Condition.User.IsAdmin": "True",
		"Condition.Device": "PC",
		"ExpectedResult": "Success",
		"Perspective": "Only registered users accessed from PC can access.",
		"ID": "2"
	},
	{
		"Condition.User.IsRegistered": "True",
		"Condition.User.IsAdmin": "False",
		"Condition.Device": "Mobile",
		"ExpectedResult": "Failure",
		"Perspective": "Only registered users accessed from PC can access.",
		"ID": "3"
	},
	{
		"Condition.User.IsRegistered": "True",
		"Condition.User.IsAdmin": "False",
		"Condition.Device": "PC",
		"ExpectedResult": "Success",
		"Perspective": "Only registered users accessed from PC can access.",
		"ID": "4"
	},
	{
		"Condition.User.IsRegistered": "False",
		"Condition.User.IsAdmin": "False",
		"Condition.Device": "Mobile",
		"ExpectedResult": "Failure",
		"Perspective": "Only registered users accessed from PC can access.",
		"ID": "5"
	},
	{
		"Condition.User.IsRegistered": "False",
		"Condition.User.IsAdmin": "False",
		"Condition.Device": "PC",
		"ExpectedResult": "Failure",
		"Perspective": "Only registered users accessed from PC can access.",
		"ID": "6"
	}
]
Example of a Markdown file:

|||#1|#2|#3|#4|#5|#6| |--|--|--|--|--|--|--|--| |Condition.User.IsRegistered|True|X|X|X|X|-|-| ||False|-|-|-|-|X|X| |Condition.User.IsAdmin|True|X|X|-|-|-|-| ||False|-|-|X|X|X|X| |Condition.Device|Mobile|X|-|X|-|X|-| ||PC|-|X|-|X|-|X| |ExpectedResult|Success|-|X|-|X|-|-| ||Failure|X|-|X|-|X|X| ||Any|-|-|-|-|-|-|

Support for strength in Covering Array

By default, this tool generates all possible combinations of the variables defined in the perspectives. However, this can result in a significantly large number of test cases.

To mitigate this, you can set the strength for each perspective. By adjusting the strength, less relevant test cases will be filtered out. The strength value can range from 2 up to the total number of variables in the perspective. A lower strength value will yield fewer test cases.

For instance, if the perspective is structured as below, and there are 3 variables, the strength can be set anywhere between 2 and 3.

Example of setting the strength:
{
	"title": "Only registered users accessed from PC can access.",
	"constants": {},
	"variables": [
		"Condition.User.IsRegistered",
		"Condition.User.IsAdmin",
		"Condition.Device",
	],
	"expect": (test:Test<ExampleDomain>)=>{
		if(
			test["Condition.User.IsRegistered"] === "True" &&
			test["Condition.Device"] === "PC"
		){
			test["ExpectedResult"] = "Success";
		}else{
			test["ExpectedResult"] = "Failure";
		}
		return test
	},
+	"strength" : 2,
}