1.1.0 • Published 2 years ago

jtester-tool v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

jTester

jTester is a lightweight JavaScript code tester utility for the browser and Node.js. It provides a flexible way to perf test arbitrary code and exposes related performance informations.

Summary

Installation

The main package's bundle uses the UMD format, meaning that it can be installed in multiple ways.
An ESM-specific bundle is also available for use in modern projects.

CDN (browser-only)

As this tool will often be used only temporary for testing purposes, the quickest way to add it to your codebase is by using a CDN-based script (which can be easily removed after testing).

<script src="https://cdn.jsdelivr.net/npm/jtester-tool@latest/dist/jtester.min.js"></script>

Package manager

However, you can also use a package manager to install jTester to your project.

npm i -D jtester-tool
yarn add -D jtester-tool

Usage

When used as an IIFE (e.g. <script> tags), a jtester function is exposed in the global context and can be used directly.

jtester().test(/* ... */)

The package can also be imported using CommonJS or ESM syntaxes.

import jtester from 'jtester-tool' // ESM
// or
const jtester = require('jtester-tool') // CJS

jtester().test(/* ... */)

Each call of the jTester function returns a new JTester instance on which the .test method can be called to test inner code.

const testData = []
for (let i = 0; i < 10000; i++) testData.push(Math.random())

jtester()
  .test(() => {
    testData.sort()
  })
  .showAnalysis()

Multiple tests can be executed at once by chaining the .test method multiple times.

const testData = []
for (let i = 0; i < 10000; i++) testData.push(Math.random())

jtester()
  .test(() => {
    testData.sort()
  })
  .test(() => {
    testData.map((item) => Math.toFixed(3))
  })
  .test(() => {
    // ...
  })
  .showAnalysis()

Note that only the inner code of the .test-provided function will be analysed, which means that you need to isolate the tested code in this function to get accurate running informations.

Configuration

jTester can be customized by passing to it a configuration object.

jtester({ /* options */ })

All available options are described below.

autorun

typedefault
booleantrue

Defines the global running strategy.

By default, code tests will be executed on-the-fly right away after they are defined through the .test method.
Setting this option to false will prevent code tests to be executed directly. The execution must be triggered manually using the .run method in that case.

verbose

typedefault
booleanfalse

Displays advanced informations about system and code tests.

Set to false by default, it can be enabled to display advanced debug informations, like system and hardware-related infos.

:warning: Note: Especially in browsers contexts, system or hardware-related informations are mostly based on properties that can be user-modified or are experimental features. They are only presented for testing and informational purposes.

Public API

Here is the full list of the public properties and methods exposed by the jTester instance.

Methods

Note: All methods that return a JTester object can be chained during calls.

.test

Signature .test(nameOrFn: string | Function, fn?: Function): JTester

Params

  • nameOrFn (required): Defines the test name in case of string given, or the code test otherwise (function).
  • fn (optional): Required to define the code test if first argument is of type string.

Defines a test task.

This method accepts a function as only argument which is internally executed and analysed.
Each call to this method will automatically trigger the corresponding testFn function execution unless autorun configuration option is set to false.

.run

Signature .run(): JTester

Runs previously defined test tasks.

This method manually triggers tasks' execution. It is not needed if autorun configuration option is set to true. It is chainable with other instance methods.

.showAnalysis

Signature .showAnalysis(): JTester

Logs testing results.

Method used to log performance results of previous test tasks in the console.
It is chainable with other instance methods.

.log

Signature .log(): JTester

Alias of .showAnalysis.

.getAnalysis

Signature .getAnalysis(format: string = 'js'): Object | string

Params

  • format (optional): Defines output format for analysis data. Defaults to js.

Get analysis logs data.

Use this method to retrieve analysis data using various formats.
Accepts one format argument which must be one of: js, json or xml.

Here is the list of analysis properties returned by this method (applicable to all formats).

{
  version: "x.x.x", // jTester version
  tests: [
    {
      name: 'test', // test name
      runtime: 0, // test's execution runtime (milliseconds)
    }
  ]
}

Properties

/

Licensing

This package is released under the MIT license.

1.1.0

2 years ago

1.0.0

2 years ago

1.0.0-beta.5

2 years ago

1.0.0-beta.4

2 years ago

1.0.0-beta.3

2 years ago

1.0.0-beta.2

2 years ago

1.0.0-beta.1

2 years ago