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

real-test-js

v1.9.3

Published

RealTestJS - Fast and trustworthy testing for everything JS!

Downloads

37

Readme

RealTestJS is a JavaScript test framework running on Node.js making testing simple and fun.

Getting started

Before you follow the steps below, make sure you have the

Node.js installed globally only your system

Installing

Install RealTestJS for Mac, Linux, or Windows:

npm install real-test-js --save-dev

or

yarn add real-test-js --dev

Write test:

Use the test function to write test cases and the describe function to group them.

More example:

https://github.com/VadimNastoyashchy/real-test-js-boilerplate-project

Let's start with test.js test file creation.

Example↓

test.js

import { describe, test, expect} from 'real-test-js'

describe('Title for describe block', () => {
  test('Title for test', () => {
    const arr = [1, 2, 3]
    expect(arr).toHaveLength(3)
  })
})

Run test:

npx real-test-js --test="test.js"

or

yarn real-test-js --test="test.js"

Where --test= your test file path

Configuration via config file

  • test.config.js - config for Real Test JS (works as an engine)

Example↓

test.config.js

const config = {
  testDir: 'test',
  // testFile: 'test.js'
  reporter: {
    type: 'html',
    folderName: 'report',
    fileName: 'result',
  },
}

export default config

| Option Name | Required | Type | Description | | ------------ | -------- | ------ | ----------------------- | | "testFile" | false | string | path to the test file | | "testDir" | true | string | path to the test folder |


Reporter options

By default report is disabled.

To enable, add report configuration inside test config:

{
    testDir: "your_test_folder",
    reporter: {
      type: "html"
  },
}

| Option Name | Required | Type | Description | | -------------- | -------- | ------ | -------------------------------------------- | | "type" | false | string | reporter type. Now available: "json", "html" | | "folderName" | false | string | define reporter folder name | | "fileName" | false | string | define reporter file name |


Test runner API


| Option Name | Description | | -------------- | ------------------------------------------------------------------------------------- | | "test" | test is where you perform individual tests | | "describe" | describe is for organizing and grouping tests. Describe can be nested in describe | | "beforeEach" | Command allows to define setup tasks at the beginning of every It block | | "afterEach" | Command allow to define teardown tasks at the end of every It block | | "beforeAll" | Command allow to define setup tasks at the beginning of describe block | | "afterAll" | Command allow to define teardown tasks at the end of describe block |


Assertions

Use expect(actual_value) with assertions:

Example↓

  const arr = [1, 2, 3]
  expect(arr).toHaveLength(3)

| Assert Name | Description | | -------------------- | ----------------------------------------------------------------------------------------------- | | .toBeDefined() | Check actual value to be not undefined expect(1).toBeDefined() | | .toHaveLength() | Check actual array length to have expected value expect(arr).toHaveLength(number) | | .toBeFalsy() | Check actual value to be false | | .toBeTruthy() | Check actual value to be true | | .toEqual() | Check actual and expected values are the same (using ===) expect(value).toEqual(value) | | .notToEqual() | Check actual and expected values are not the same (using ===) expect(value).notToEqual(value) | | .toBeNull() | Check actual value to be null | | .notToBeNull() | Check actual value to be not null | | .toBeUndefined() | Check actual value to be undefined | | .toBeNaN() | Check actual value to be NaN | | .toBeGreaterThan() | Check actual value to be greater than expected value | | .toBeLessThan() | Check actual value to be less than expected value | | .toContain() | Use when you want to check that an item is in an array or a string. | | .toMatch() | Use .toMatch() to check that a string matches a regular expression. |


Context options

Use {} as the second param for describe and tests func.

Example↓

test('description', {}, () => {})

or

describe('description', {}, () => {})

Example↓

  describe('description', { skip: true }, () => {})
  //or
  test('description', { skip: true }, () => {})

| Option Name | Description | | ------------------- | ----------------------------------------------------------------------- | | { skip: true } | Option for skipping describe/test where it was provided | | { timeout: 2000 } | Option timeout (in ms) for specifying how long to wait before aborting. | | | The default timeout is 5 seconds. |


Async/Await support

RealTestJS also supports async/await approach. To use it just add async keyword before function callback inside test block

Example↓

test('Wait 1 sec and check', async () => {
  const number = await new Promise((resolve) =>
    setTimeout(() => resolve(1), 1_000)
  )
  expect(number).toBeDefined()
})