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

@olton/easytest

v0.39.0

Published

Simple test framework for JavaScript and TypeScript with DOM supports

Downloads

84

Readme

EasyTest

Simple testing framework for JavaScript and TypeScript, written in pure JavaScript.


Documentation: https://easy.org.ua/


Core features:

  • No need to import it, test, describe or ecpext in your test file. These functions are available globally.
  • You can use both js and ts test files in the same project.
  • Asynchronous code testing.
  • TypeScript testing out of the box.
  • Global DOM object for testing HTML objects.
  • Built-in coverage tool.
  • Verbose or non verbose mode.
  • Mock functions.
  • Big set of built-in matchers.
  • Extend expect function with your own matchers.
  • Compatible with codecov report viewer.
  • A lot of expects in one test case.
  • Setup and Teardown functions (beforeEach, afterEach, beforeAll, afterAll).

Support for PayPal to [email protected]


NPM Version License: MIT codecov NPM Downloads


verbose-off.png


Installation

npm install @olton/easytest -D

Usage

To use EasyTest you don't need to import it, test or describe in your test file. Create a test file with *.test.js or *.test.ts extension (for example). You can use both of them in the same project.

function hello() {
    return "Hello"
}

describe(`Common tests suite`, () => {
    it(`says hello`, () => {
        return expect(hello()).toBe("Hello")
    })
})

test(`Bad test 2 !== 1`, () => {
    return expect(2).toBe(1)
})

Async tests

async function fetchData() {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve("Data received");
        }, 1000);
    });
}

describe('Async function tests', async () => {
    it('should return data after 1 second', async () => {
        const data = await fetchData();
        return expect(data).toBe("Bad Data");
    });
});

Update package.json to run tests with easytest command.

{
    "scripts": {
        "test": "easytest"
    }
}

Functions

  • describe - create test suite
  • it - create a test case
  • expect - create assertion
  • beforeEach - run before each test case
  • afterEach - run after each test case
  • beforeAll - run before all test cases
  • afterAll - run after all test cases
  • test - create simple test
  • mocker - create mock function
  • DOM - create DOM object (not global)

Matchers

EasyTest contains a big set of built-in matchers:

  • A simple comparison
  • A strong comparison
  • Type checking
  • Number checking
  • String checking
  • Array checking
  • Object checking
  • Color checking
  • IP, Email, Url checking
  • JSON, XML checking
  • Date, RegExp, Symbol checking
  • Function checking
  • HTML element checking
  • and more...

TypeScript

To use EasyTest with TypeScript you need to install tsx package.

npm install tsx -D

and then

{
    "scripts": {
        "test": "cross-env NODE_OPTIONS=\"--import tsx\" easytest"
    }
}

cross-env

Run scripts that set and use environment variables across platforms.

npm install --save-dev cross-env

Configuration

To configure EasyTest you need to create a easytest.json file in the root of your project. Also, you can use argument --config=fileName to specify a configuration file.

{
    "scripts": {
        "test": "easytest --config=myconfig.json"
    }
}

EasyTest designed as a config-free testing framework. But you can configure it to your needs. The default values are:

{
  "include": ["**/*.spec.{t,j}s", "**/*.spec.{t,j}sx", "**/*.test.{t,j}s", "**/*.test.{t,j}sx"],
  "exclude": ["node_modules/**"],
  "coverage": false,
  "verbose": false,
  "dom": false,
  "test": "*",  
  "report": {
    "type": "lcov",
    "dir": "coverage"
  }
}

You can use cli arguments to configure EasyTest:

  • --config=file_name.json - path to the configuration file.
  • --coverage - enable coverage tool.
  • --verbose - enable verbose mode.
  • --include=**/*.spec.{t,j}s - include files for testing.
  • --exclude=node_modules/** - exclude files from testing.
  • --test=test_name - execute only tests whose name contains value.
  • --dom - enable global DOM.
{
  "scripts": {
    "test": "easytest --coverage --verbose --include=**/core.spec.{t,j}s"
  }
}

DOM Environment

EasyTest has a global DOM object for testing HTML objects (we use JSDOM to create DOM environment). To enable global DOM, you need to use parameter --dom in the command line, or set dom to true in the configuration file.

{
    "scripts": {
        "test": "easytest --dom"
    }
}

Extend expect

You can extend the expect function with your own matchers.

import {Expect} from "@olton/easytest";

class MyExpect extends Expect {
    toBeEven() {
        let received = this.received
        let result = received % 2 === 0
        if (!result) {
            this.message = `Expected ${received} to be even`
        }
    }
}

const expect = (received) => new MyExpect(received)

test(`Custom expect`, () => {
    expect(2).toBeEven()
})

License

EasyTest licensed under MIT license.

Contributing

Bug Reports & Feature Requests

Use issue tracker to report bugs or request new features.


Copyright

© 2024 Serhii Pimenov. All rights reserved.