Comparing version 1.1.1 to 1.2.0
21
index.js
@@ -9,2 +9,3 @@ /*------------------------------------- | ||
const chalk = require('chalk') | ||
const deepEqual = require('./deepEqual.js') | ||
@@ -41,4 +42,3 @@ if (!chalk) | ||
if (name) { | ||
console.log(chalk.bold.blue("🢚 "+name)) | ||
name += ' ' | ||
console.log(chalk.bold.blue("[ " + chalk.underline(name) + " ]")) | ||
} | ||
@@ -51,7 +51,7 @@ | ||
if (totalErrors == 1) | ||
console.log(chalk.bold.yellow(`One error occured during the test ${name}${sad()}\n`)) | ||
console.log(chalk.bold.yellow(`One error occured during the test ${chalk.underline(name)} ${sad()}\n`)) | ||
else if (totalErrors > 1) | ||
console.log(chalk.bold.yellow(`${fails.length} errors occured during the test ${name}${sad()}\n`)) | ||
console.log(chalk.bold.yellow(`${fails.length} errors occured during the test ${chalk.underline(name)} ${sad()}\n`)) | ||
else | ||
console.log(chalk.bold.green(`The test ${name}has been successfully passed ${happy()}\n`)) | ||
console.log(chalk.bold.green(`The test ${name} has successfully passed ${happy()}\n`)) | ||
} | ||
@@ -96,3 +96,3 @@ catch (error) { | ||
for (const fail of fails) | ||
console.log(chalk.gray.italic(" Error at : " + chalk.reset.bold.italic.red(fail))) | ||
console.log(chalk.gray(" Error at : " + chalk.reset.bold.red(fail))) | ||
fails.length = 0 | ||
@@ -105,7 +105,9 @@ totalErrors++ | ||
function test(conditionA, testDescription='') { | ||
if (conditionA) return | ||
fails.push(testDescription) | ||
function test(conditionA, description='') { | ||
if (!conditionA) fails.push(testDescription) | ||
} | ||
function same(valueA, valueB, description='') { | ||
test(deepEqual(valueA, valueB), description) | ||
} | ||
@@ -117,2 +119,3 @@ module.exports = { | ||
test, | ||
same, | ||
} |
{ | ||
"author": { | ||
"name": "Lepzulnag" | ||
}, | ||
"bundleDependencies": false, | ||
"dependencies": { | ||
"chalk": "^2.4.2" | ||
}, | ||
"deprecated": false, | ||
"description": "A minimal, colorful and enjoyable test library for small applications", | ||
"keywords": [ | ||
"test", | ||
"js", | ||
"minimal", | ||
"easy", | ||
"async", | ||
"simple" | ||
], | ||
"license": "ISC", | ||
"main": "index.js", | ||
"name": "fartest", | ||
"scripts": { | ||
"test": "echo \"Error: you don't test a test library!\" && exit 1" | ||
}, | ||
"version": "1.1.1" | ||
} | ||
"author": { | ||
"name": "Lepzulnag" | ||
}, | ||
"bundleDependencies": false, | ||
"dependencies": { | ||
"chalk": "^2.4.2" | ||
}, | ||
"deprecated": false, | ||
"description": "A minimal, colorful and enjoyable test library for small applications", | ||
"keywords": [ | ||
"test", | ||
"js", | ||
"minimal", | ||
"easy", | ||
"async", | ||
"simple" | ||
], | ||
"license": "ISC", | ||
"main": "index.js", | ||
"name": "fartest", | ||
"scripts": { | ||
"test": "echo \"Error: you don't test a test library!\" && exit 1" | ||
}, | ||
"version": "1.2.0" | ||
} | ||
*FAst and smaRT TESTing* | ||
FarTest is an obvious, colorful and enjoyable test library for small applications. | ||
.. for those who want to enjoy simple and colorful tests without having to learn the whole ecosystem of a rich test library. | ||
Your terminal need to accept UTF-8 characters and ANSI colors for a better experience. | ||
 | ||
# Installation | ||
FarTest is an obvious, colorful and enjoyable test library for small applications. It does not do cool stuff like code coverage, but you'll learn to use in no time. | ||
## Installation | ||
``` | ||
npm install --save-dev fartest | ||
``` | ||
In short : | ||
``` | ||
npm i -D fartest | ||
``` | ||
# Usage | ||
FarTest export three functions : | ||
## Usage | ||
FarTest simplest API export three functions : | ||
- *start* - start a new test, | ||
- *stage* - define the current stage inside a test, | ||
- *test* - check an assertion inside a test. | ||
- `start(test: Function)` - start a new test, | ||
- `stage(name: string)` - define the current stage inside a test, | ||
- `test(condition: boolean, name?: string)` - check an assertion inside a test. If `condition` is `true` then the assertion has succeeded, otherwise it failed. | ||
- `same(a: any, b: any, name?: string)` - check if two values are the same. When `a` and `b`are objects, execute a deep comparison. Values can be of any type : numbers, strings, arrays, maps, sets, ... | ||
And that's all. | ||
First, let's import the functions we need : | ||
```javascript | ||
const { start, stage, test } = require('fartest') | ||
import { start, stage, test } from 'fartest' | ||
``` | ||
With ES modules : | ||
```javascript | ||
import { start, stage, test } from 'fartest') | ||
``` | ||
@@ -49,3 +46,10 @@ Then, we start the test : | ||
test(21 === "21", "Test description") // will fail because types don't match | ||
same(21, "21", "Test description") // will fail as well | ||
stage('Comparing objects') | ||
same({x: 1, y: 2}, {x: 1, y: 2}) // will pass | ||
stage('Comparing object and array') | ||
same(['foo'], {0: 'foo'}) // will not pass | ||
stage('Crash test') | ||
@@ -56,5 +60,5 @@ undefined.coco = 321321 // any invalid code will be caught | ||
## Test asynchronous functions | ||
### Test asynchronous functions | ||
Declare your main test functions as `async` and just use `await` anywhere an asynchronous function is used. | ||
Because your main test functions is declared as `async` you can just use `await` anywhere you need it. | ||
@@ -68,6 +72,9 @@ | ||
stage('1 == 1') | ||
test(1 == 1) | ||
test(1 == 1) // ok, pass | ||
stage('2 == "2"') | ||
test(2 == "2") | ||
test(2 == "2") // also pass because non-strict equality | ||
stage('same(2, "2")') | ||
same(2, "2") // does not pass | ||
}) | ||
@@ -82,4 +89,7 @@ | ||
## That's all... | ||
### Conclusion | ||
Congratulations! You've learned a new test library in less that 5 minutes! | ||
What you waiting for? | ||
*Let's FarT!* |
const { start, stage, test } = require('./index') | ||
start(function() { | ||
start(function MySweetTest() { | ||
stage("ZABU") | ||
@@ -6,0 +6,0 @@ test(1 == 1, 'check raw equality') |
278503
7
149
92