🎊 Add all main files

This commit is contained in:
Wessel T
2019-01-18 17:21:18 +01:00
parent 7bc1a1339d
commit ec58121b22
9 changed files with 125 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
tmp/

View File

@@ -1,6 +1,7 @@
MIT License
Copyright (c) 2019 Wessel T
The MIT License (MIT)
Copyright (c) 2019-present Wessel "wesselgame" T
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

42
README.md Normal file
View File

@@ -0,0 +1,42 @@
<div align="center">
<br />
<p>
<a href="https://github.com/PassTheWessel/lumah"><img src="media/logo.png" alt="lumah" /></a>
</p>
<br />
<p>
<a href="#"><img src="https://packagephobia.now.sh/badge?p=lumah" alt="Install Size" /></a>
<a href="https://discord.gg/SV7DAE9"><img src="https://discordapp.com/api/guilds/107131083958538240/embed.png" alt="Discord" /></a>
<a href="https://www.npmjs.com/package/lumah"><img src="https://img.shields.io/npm/v/lumah.svg?maxAge=3600" alt="NPM version" /></a>
<a href="https://www.npmjs.com/package/lumah"><img src="https://img.shields.io/npm/dt/lumah.svg?maxAge=3600" alt="NPM version" /></a>
<a href="https://www.patreon.com/wessel"><img src="https://img.shields.io/badge/donate-patreon-F96854.svg" alt="Patreon" /></a>
</p>
<p>
<a href="https://nodei.co/npm/lumah/"><img src="https://nodei.co/npm/lumah.png?downloads=true&stars=true" alt="npm installnfo" /></a>
</p>
</div>
> A simple and lightweight testing framework for Node.js
> [GitHub](https://www.github.com/PassTheWessel/Kirbe) **|** [NPM](https://www.npmjs.com/package/kirbe)
## Installing
```sh
$ yarn add lumah # Install w/ Yarn (the superior package manager)
$ npm i lumah # Install w/ NPM
```
## Usage
```js
const l = require( 'lumah' ); // Define lumah
l.register( 'Hello', ( res ) => res( true, 'Danceboye' ) ); // Register a test with the name "Hello" and succeed with the message "Danceboye"
l.register( 'This is so sad', ( res ) => res( false, 'Sadcat' ) ); // Fail with the message "sadcat"
l.register( 'Late ;_;', ( res ) => setTimeout( () => res( true, 'I\'ve came!' ), 500 ) ); // Succeed after 500ms
l.register( 'memes', ( res ) => {
if ( process.env.MEMES ) res( true, 'You are a true memester' ) // Success if process.env has the value "MEMES"
res( false, 'Well, that\'s a shame :(' ) // Fail otherwise
});
l.start(); // Run all tests
```

5
lib/index.js Normal file
View File

@@ -0,0 +1,5 @@
const run = require( './runTests' );
let tests = [];
exports.register = ( name, method ) => tests.push({ method, name });
exports.start = () => run( tests );

24
lib/result.js Normal file
View File

@@ -0,0 +1,24 @@
module.exports = ( tests ) => {
process.stdout.write( '\r\n' );
let totals = { 'fail': 0, 'pass': 0 };
for( let i = 0; i < tests.length; i++ ) {
if( tests[ i ].result.success ) totals.pass++;
else totals.fail++;
}
process.stdout.write([
`\x1b[33mA total of \x1b[32m${totals.pass} \x1b[33m( \x1b[32m${( ( totals.pass / tests.length ) *100 ).toFixed( 2 )}% \x1b[33m) test(s) \x1b[32mpassed \x1b[33mand`,
`${totals.fail <= 0 ? `\x1b[32m0 \x1b[33m( \x1b[32m0% \x1b[33m)` : `\x1b[31m${totals.fail} \x1b[33m( \x1b[31m${( ( totals.fail / tests.length ) *100 ).toFixed( 2 )}% \x1b[33m)`} test(s) \x1b[31mfailed\x1b\x1b[33m:\x1b[0m\r\n`
].join( ' ' ));
for( let i = 0; i < tests.length; i++ ) {
if ( tests[ i ].result.success )
process.stdout.write(` \x1b[32m✓ \x1b[34m${tests[ i ].name} \x1b[32mpassed \x1b[33min \x1b[32m${tests[ i ].extData.timeTaken}ms ${( tests[ i ].result.info ? `\x1b[33m>> \x1b[34m${tests[ i ].result.info}\x1b[0m\x1b[0m` : `\x1b[0m` )}\r\n`);
else
process.stdout.write(` \x1b[31m✗ \x1b[34m${tests[ i ].name} \x1b[31mfailed \x1b[33min \x1b[32m${tests[ i ].extData.timeTaken}ms ${( tests[ i ].result.info ? `\x1b[33m>> \x1b[34m${tests[ i ].result.info}\x1b[0m\x1b[0m` : `\x1b[0m` )}\r\n`);
}
process.stdout.write( '\r\n' );
};

27
lib/runTests.js Normal file
View File

@@ -0,0 +1,27 @@
const ui = require( './result' );
module.exports = ( testData ) => {
let tests = testData;
let completed = 0;
process.stdout.write( '\x1B[2J\x1B[0f\u001b[0;0H\r\n' );
process.stdout.write( `\x1b[33mExecuting \x1b[32m${tests.length} \x1b[33mtest(s)...\x1b[0m\r\n` );
for ( let i = 0; i < tests.length; i++ ) {
tests[ i ].extData = { startTime : new Date().getTime() };
const testCompleted = ( success, info ) => {
tests[ i ].result = { executed: true, success: success, info: info };
tests[ i ].extData.endTime = new Date().getTime();
tests[ i ].extData.timeTaken = tests[ i ].extData.endTime - tests[ i ].extData.startTime;
process.stdout.write( ` \x1b[33mTask \x1b[34m${tests[ i ].name} ${( success ? `\x1b[32mpassed` : `\x1b[31mfailed` )}\x1b[0m\r\n` );
completed++;
if ( completed >= tests.length ) ui( tests );
};
try { tests[ i ].method( testCompleted ); }
catch( ex ) { testCompleted( false, ex.toString() ); }
}
};

BIN
media/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

16
package.json Normal file
View File

@@ -0,0 +1,16 @@
{
"name": "lumah",
"version": "0.0.1",
"description": "🔩 A simple and lightweight testing framework for Node.js",
"author": "Wessel \"wesselgame\" T <discord@go2it.eu>",
"license": "MIT",
"main": "lib/index.js",
"files": [ "lib", "LICENSE" ],
"bugs": { "url": "https://www.github.com/PassTheWessel/lumah/issues" },
"homepage": "https://www.github.com/PassTheWessel/lumah#readme",
"repository": {
"type": "git",
"url": "https://www.github.com/PassTheWessel/lumah"
},
"keywords": [ "test", "console", "lumah", "testing", "framework", "async", "lightweight" ]
}

7
test.js Normal file
View File

@@ -0,0 +1,7 @@
const l = require( './lib' );
l.register( 'Hello', ( res ) => res( true, 'Danceboye' ) );
l.register( 'This is so sad', ( res ) => res( false, 'Sadcat' ) );
l.register( 'Late ;_;', ( res ) => setTimeout( () => res( true, 'I\'ve came!' ), 500 ) );
l.start();