performance-js-tests

1.0.2 • Public • Published

performance-js-tests

Install

$ npm install --save performance-js-tests

Usage

testable.js

// for example
window.somethingHappened = (callback) => {
    setTimeout(callback, 1000);
};

index.html

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <script type="text/javascript">
        const startTime = +new Date();
    </script>

    <script type="text/javascript" src="testable.js"></script>

    <script type="text/javascript">
        somethingHappened(() => {
            const currentTime = +new Date();
            window.onCustomEvent({ type: 'timeStamp', data: currentTime - startTime });
        });
    </script>
</body>
</html>

performance test

const performanceTests = require('performance-js-tests');

(async() => {
    await performanceTests({
        puppeteer: {
            htmlFile: 'index.html'
        }
    });
})()

Browser will launch 100 times and you can see average file download or performance of js in ms

Options

{
    // number of launched browsers
    numberOfStarts: 100,

    // maximum latency from the browser
    waitingTime: 30000,

    // koa
    server: {
        enable: true,
        port: 3000,
        baseDir: '.',

        staticKoaOptions: {
            // see link below
        },

        rewrite: {
            // see link below
        }
    },

    puppeteer: {
        // will launch firefox-launch instead of chrome-launch
        useFirefox: false,

        // html file where js is launched
        htmlFile: null,
        launchOptions: {
            // see link below
        }
    }
}

staticKoaOptions rewrite launchOptions

/performance-js-tests/

    Package Sidebar

    Install

    npm i performance-js-tests

    Weekly Downloads

    0

    Version

    1.0.2

    License

    ISC

    Unpacked Size

    7.97 kB

    Total Files

    7

    Last publish

    Collaborators

    • mefistosss