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

@genx/test

v2.1.5

Published

Gen-X test framework

Downloads

16

Readme

@genx/test

Gen-X test framework

Usage

testSuite

const testSuite = require('@genx/test');
testSuite(async (suite) => { ... }, options);
  • Options:
    • before: async function run bofore the whole test suite
    • after: async function run after the whole test suite
    • beforeEach: async function run bofore each test suite
    • afterEach: async function run after each test suite
    • serverEntry {string}: server entry file to be instrumented for code coverage
    • verbose {boolean}: verbose output mode
    • skip {boolean}: skip the whole test suite
    • only {boolean}: run this test suite only
    • testDir {string='test'}: test case root directory

testCase

suite.testCase('test case name', async () => { ... }, options);
  • Options:
    • data
    • cleanUp
    • skip
    • only

testCaseFromFixtures

suite.testCaseFromFixtures('test case name', async (data) => { ... }, options);

data are loaded from fixtures/<suite name>.js

{
    cases: {
        '<test case name>': [
            {
                params: {
                    key1: 'value1',
                    key2: () => 'value2' //generator 
                },
                expected: {}
            }
        ]
    },
    // others to be added into test report
    // description, epic, feature, owner, tag, issues, severity
}

Helpers inside test case

startWebServer_

Start a @genx/server instance for code coverage testing.

startWorker_

Start a @genx/app worker to faciliate testing with features.

startRestClient_

Start a http client with customzable authencation

benchmark_

Run benchmark against a group of different methods.

testStep

Define a test step to show progress in the test report.

attathObject

Attach an object to the test report.

Setup test scripts

  • Add below scripts into package.json
    • Set NODE_RT=babel to enable directly testing against untranspiled ES code.
    • Set COVER_MODE=1 to enable web server code coverage and replace superagent with supertest.
"test:clean": "rm -rf allure-results",
"test": "npm run test:clean && cross-env NODE_RT=babel mocha --reporter mocha-multi --reporter-options mocha-multi=test/mocha-multi-reporters.json test/*.spec.js",
"cover": "npm run test:clean && cross-env COVER_MODE=1 NODE_RT=babel nyc --reporter=html --reporter=text -- mocha --reporter progress test/*.spec.js && open ./coverage/index.html",
"report": "allure generate allure-results --clean -o allure-report && allure open allure-report"

Setup test configs

  • test/mocha-multi-reporters.json
{    
    "progress": {
        "stdout": "-",        
        "options": {
            "verbose": true
        }
    },
    "allure-mocha": {
        "stdout": "-",
        "options": {
            "resultsDir": "./allure-results"
        }
    }
}
  • test/conf/test.*.json e.g. test.default.json See

Test spec file sample

const testSuite = require("@genx/test");
const Expression = require("@genx/jes");

testSuite(function (suite) {
    suite.testCase("login and get profile", async function () {
        await suite.startRestClient_("<endpointKey>", "<userIdentityKey>", async (app, client) => {
            await suite.testStep_("my-profile", async () => {
                const myProfile = await client.get(["my-profile"]);

                Expression.match(myProfile, {
                    status: "success",
                    response: {
                        id: { $exists: true },
                        agency: { $exists: true },
                        user: { $exists: true },
                    },
                })[0].should.be.ok();
            });
        });
    }, {});
}, { verbose: true });

Local config to run specific cases only or to skip specified cases

module.exports = {
    only: [
        // similar to describe.only
        // 
    ],
    skip: [
        // similar to describe.skip
    ]
}

Note: another way to do the same thing is to put skip or only in the suite options or test case options passed in through testSuite() and suite.testCase().

"skip" and "only" option will override those specified in the config.

License

MIT