0.1.1 • Published 10 months ago
@spmeesseman/test-utils v0.1.1
Test Utils - JS/TS Unit Testing Tools
Description
A unit testing utility suite, primarily to track fastest/slowest runtimes per test/suite, and to make writing tests a little less s******.
Requirements
- NodeJs 16.x
- JavaScript or TypeScript Project
- As of v1, tests written using the Mocha framework
- As of v1, NYC for optional coverage
Installation
To install test-utils globally, run the following command:
npm install -g @spmeesseman/test-utils
To install locally per project, run the following command from the directory containing the projects package.json file:
npm install @spmeesseman/test-utils
General Setup
The main purpose of this package is to provide a convenient interface for tracking of fastest and slowest times for each test / suite in multiple projects.
Example Code:
node ./path/to/tests/runTests.js
runTests.js:
require("./index")()
.then((exitCode: number) =>
{
process.exitCode = exitCode;
})
.catch(() =>
{
process.exitCode = 1;
});
index.ts:
import { TestRunner } from "@spmeesseman/test-utils";
const runner = new TestRunner({ ...options });
try {
await runner.run();
}
catch (error) {
try {
console.error(error.message);
} catch (_) {}
process.exit(1);
};
Within tests one-time initialization:
import { TestTracker, colors, figures } from "@spmeesseman/test-utils";
const testTracker = new TestTracker();
export const consoleWrite = testTracker.utils.writeConsole;
export const isRollingCountError = testTracker.isRollingCountError;
export const getSuccessCount = testTracker.utils.getSuccessCount;
export const suiteFinished = testTracker.utils.suiteFinished;
export const endRollingCount = testTracker.utils.endRollingCount;
export const exitRollingCount = testTracker.utils.exitRollingCount;
Screenshots
Test Runner Options
TODO
Runtime Tracking Usage
TODO