npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kitmi/tester

v1.1.2

Published

JavaScript application unit test framework

Downloads

10

Readme

@kitmi/tester

Unit Test Utility

@kitmi/tester is a JavaScript unit test utility with api code coverage, async dump for tracking async leak.

Features

  • [x] Support coverage test of @kitmi/jacaranda applicaiton
  • [x] Support allure report
  • [x] Support async dump for debugging application hanging issue caused by pending async event
  • [x] Support @kitmi/jacaranda worker
  • [x] Support authencation protected api test
  • [x] Support JSON Validation Syntax
  • [x] Support configurable test case on/off switches
  • [x] Support profiling
  • [x] Support benchmark
  • [x] Support test step and progress record
  • Support job pipeline for long-run test

Interface

gobal object jacat, or can also be imported by

import { jacat } from '@kitmi/tester';
  • startServer_(serverName?): start a server with options specified by serverName in the test config

  • startWorker_(name?, async app => {/* test to run */}, options): start a worker

  • withClient_(serverName?, authentication, async (client, server) => {/* test to run */}, options?): // start a worker and create a http client

  • benchmark_(mapOfMethods, verifier, payload): // run benchmark againest several different implementions of the same purposes

  • profile_(name, async () => { //test }): // run profiling againest a test function

  • step_(name, fn): // test step

  • param(name, value): // record param used in a test into test report

  • attach(name, value): // attach object produced during a test into test report

Usage

1. add .mocharc.js to the project root

require('@swc-node/register'); // for esmodule and commonjs hybid mode
require('@kitmi/utils/testRegister'); // adding should and expect dialects for chai

module.exports = {
    timeout: 300000,
    require: ['@kitmi/tester'], // for bootstrapping tester
    reporter: 'mocha-multi', // for combining console reporter and allure reporter
    reporterOptions: 'mocha-multi=test/mocha-multi-reporters.json', // as above
};

2. add test/mocha-multi-reporters.json config

{       
    "spec": {
        "stdout": "-",        
        "options": {
            "verbose": true
        }
    },     
    "allure-mocha": {
        "stdout": "-",
        "options": {
            "resultsDir": "./allure-results"
        }
    }
}

3. add test/test.config.json config

{
    "skip": {
        "suites": {            
        }
    },
    "enableAsyncDump": false,
    "enableAllure": true,
    "servers": {
        "server1": {
            "configPath": "test/conf",
            "controllersPath": "test/actions",
            "sourcePath": "./",
            "logLevel": "info"
        }
    },
    "workers": {
        "tester": { 
            "configName": "test",
            "configPath": "test/conf"
        }
    },
    "authentications": {
        "client1": {
            "loginType": "password",
            "accessType": "jwt",
            "loginOptions": {
                "endpoint": "/login",
                "username": "user",
                "password": "pass"
            }
        }
    }
}

4. write test cases

More examples refers to test/*.spec.js.

describe('test1', function () {
    it('should pass1', function () {
        expect(true).to.be.true;
    });

    it('should pass2', function () {
        expect(true).to.be.true;
        jacat.attach('test2 result', {
            key: 'tesst',
            key2: 'tesst',
            key3: 'tesst',
        });
    });

    it('should pass async', async function () {
        await jacat.step_('step1', async () => {
            await new Promise((resolve) => setTimeout(resolve, 100));
        });

        expect(true).to.be.true;
    });
});

5. run test cases

mocha --recursive test/**/*.spec.js

6. generate test report

allure generate allure-results --clean -o allure-report && serve ./allure-report

7. run code coverage test and report

nyc --reporter=html --reporter=text mocha --recursive test/**/*.spec.js && open ./coverage/index.html

API test

Authentication

  • loginType
    • password
  • accessType
    • jwt
  • loginOptions:

{
    "authentications": {
        "client1": {
            "loginType": "password",
            "accessType": "jwt",
            "loginOptions": {
                "endpoint": "/login",
                "username": "user",
                "password": "pass"
            }
        }
    }
}
it('/test/protected ok', async function () {
    await jacat.withClient_('server1', 'client1', async (client, server) => {
        const res = await client.get('/test/protected');
        expect(res).to.deep.equal({ status: 'ok' });
    });
});

License

This project is licensed under the MIT License.

Copyright (c) 2023 KITMI PTY LTD