1.2.1 • Published 6 years ago

test-builder v1.2.1

Weekly downloads
18
License
-
Repository
github
Last release
6 years ago

Test-Builder

A node.js library made to test the latest build of your amazing APIs.

This library is made to be as simple as possible, to get your tests completed in style. To do this, Test-Build has built in styles using chalk template litterals such as green.bold.underline. You can read more about those types of litterals on chalk's npm readme. Note: those literals have minor changes. Hex:

`bgHex(#FFFF)` // The hex color #FFFF as the background.

`hex(#FFFF)` // The hex color #FFFF as the text color.

Rgb:

`bgRgb(255, 255, 255)` // Black in RGB as the background

`rgb(#FFFF)` // Black in RGB as the text color.

These chain the same way:

`underline.rgb(1,2,3).bold`

Getting Started:

Instalation:

npm install test-builder

Setup

Creating an instance:

/*
Import the required class to make a test.

Test class is the constructor to create test instances.
*/
const { Test } = require('test-builder'); 


/*
Import the api or to test using test-builder.
*/
const someAPI = require('path/to/some/api');

let ApiTest = new Test(
    'someAPI', // Sets the name of the test, shown in the first scope label.
    true, // Determines if values are shown in the detail.
    theme // The theme configuration determining the layout of the output. See 'Themes'.
);

ApiTest.test(
    true, // Detail, same as in the Test class, but overrides the parent.
    'Random-Emoji', // Name of the sub-test displayed in the second scope.
    'A random emoji api.' // The description displayed after 'failure' or 'success' in the console.
).notEqual( // Function to test if two or more values are not all the same.
    someAPI.randomEmote(), // Get random emote from some api.
    someAPI.randomEmote() // Get another random emote.
);
/*
The test would have tested if the emotes are random, which means there is only a small test of being equal.
*/

ApiTest.test(
    true, // Detail, same as in the Test class, but overrides the parent.
    'Alphabet', // Name of the sub-test displayed in the second scope.
    'Get first letter of alphabet.' // The description displayed after 'failure' or 'success' in the console.
).equals( // Function to test if two or more values are equivelent.

    someAPI.nthOfAlphabet(1), // Get 1st letter of the alphabet, in this example it is supposed to be 1 for first.
    'a' // First letter of the alphabet

);
/*
In this example, 'someAPI.nthOfAlphabet' was 0-based instead of starting at one, causing it to fail the test.
*/

The above code would yield a result simmilar to the one below, results may differ for theme and api.

Test Functions

const { Test } = require('test-builder');
let test = new Test().test(); // The test instance with the test functions.


/*
Tests if all values supplied in the arguments are equivelent.
*/
test.equals(value[,value...])


/*
Tests if the arguments supplied are not all the same.
*/
test.notEqual(value[,value...])


/*
Tests if all values supplied in the arguments are of the same type.
(from `typeof value`)
*/
test.sameType(value[,value...])


/*
Tests if the types of the values in the arguments are not all equivelent.
(from `typeof value`)
*/
test.notEqual(value[,value...])

Themes

Remember the theme option in the constructor? Well the following is how to get additional themes.

let { themes } = require('test-builder');

themes.default // The default theme

themes.halloween // A halloween theme, bats and candy.

More themes?

Make a theme using the structure of the default theme? Want to share it in production? Make a pull request on the github repo adding your theme to src/theme and it may go into production!

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.5

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.0-rc.1

6 years ago

1.0.1

6 years ago

1.0.0

9 years ago