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

@dogu-tech/dest

v0.0.63

Published

Library for running test cases. Created to run on Dogu Routine, but designed to run independently without Dogu Routine.

Downloads

399

Readme

@dogu-tech/dest

Library for running test cases.
Created to run on Dogu Routine, but designed to run independently without Dogu Routine.

Descriptions

Dest.describe((context: DestContext) => void)

describe() is a function that creates a test collection.
The context contains the logger in the dest.

Dest.withOptions(options: DestOptions).describe((context: DestContext) => void)

withOptions() is a function that creates a test collection with options.
options are described below.

job(name, () => void)

Job is a collection of test cases.
at least one job is required.
allow nested jobs.

test(name, () => Promise<void> | void)

Test is a function that runs a test case.
must be used in job.
if failed test exists, the job will fail and the next test will not be executed.

beforeAll(() => Promise<void> | void)

called before all tests in the same level.

afterAll(() => Promise<void> | void)

called after all tests in the same level.

beforeEach(() => Promise<void> | void)

called before each test.

afterEach(() => Promise<void> | void)

called after each test.

Options

| property | required/optional | type | default | description | | :-------- | :---------------- | :----- | :------ | :----------------- | | timeout | optional | number | 60000 | execution timeout. | | logToFile | optional | boolean | false | log to file. |

Usage

run with default options

If used without Dest.withOptions(), the default option is used.

import { Dest, job, test } from '@dogu-tech/dest';

Dest.describe(({ logger }) => {
  job('my first test', () => {
    test('my first test case', () => {
      logger.info('hello world');
    });
  });
});

run with options

If you use withOptions() you can change the option value instead of the default option.

import { Dest, job, test } from '@dogu-tech/dest';

Dest.withOptions({
  timeout: 60 * 60 * 1000, // 1 hour
  logToFile: true,
}).describe(({ logger }) => {
  job('my first test', () => {
    test('my first test case', () => {
      logger.info('hello world');
    });
  });
});

run without job

At least one job is required. If there is no job, an exception occurs.

import { Dest, job, test } from '@dogu-tech/dest';

Dest.describe(({ logger }) => {
  // ❌ this will throw an error. you must use job() to create a job.
  test('my first test case', () => {
    logger.info('hello world');
  });

  // ✅ this is ok.
  job('my first job', () => {
    test('my first test case', () => {
      logger.info('hello world');
    });
  });
});

run with nested jobs

import { Dest, job, test } from '@dogu-tech/dest';

Dest.describe(({ logger }) => {
  // ✅ nested jobs
  job('my first test', () => {
    job('my nested test', () => {
      test('my second test case', () => {
        logger.info('hello world');
      });
    });
  });

  // ❌ nested tests. this will throw an error.
  job('my second test', () => {
    test('my second test case', () => {
      test('my nested test case', () => {
        logger.info('hello world');
      });
    });
  });
});

run with beforeAll, afterAll

This is useful for initialization and cleanup operations. write what you want to initialize in beforeAll() and what you want to clean up in afterAll().

import { afterAll, beforeAll, Dest, job, test } from '@dogu-tech/dest';

Dest.describe(({ logger }) => {
  job('my first test', () => {
    beforeAll(() => {
      logger.info('beforeAll');
    });

    // this called after same level tests
    afterAll(() => {
      logger.info('afterAll');
    });

    test('my first test case', () => {
      logger.info('hello world');
    });

    test('my second test case', () => {
      logger.info('hello world');
    });
  });
});

log output:

 my first test 
  ✓ beforeAll (0.0s)
  ✓ my first test case (0.0s)
  ✓ my second test case (0.0s)
  ✓ afterAll (0.0s)

run with beforeEach, afterEach

beforeEach() and afterEach() are useful when each test requires the same initialization and cleanup.

import { afterEach, beforeEach, Dest, job, test } from '@dogu-tech/dest';

Dest.describe(({ logger }) => {
  job('my first test', () => {
    beforeEach(() => {
      logger.info('beforeEach');
    });

    // this called after each test
    afterEach(() => {
      logger.info('afterEach');
    });

    test('my first test case', () => {
      logger.info('hello world');
    });

    test('my second test case', () => {
      logger.info('hello world');
    });
  });
});

log output:

my first test 
  ✓ beforeEach (0.0s)
  ✓ my first test case (0.0s)
  ✓ afterEach (0.0s)
  ✓ beforeEach (0.0s)
  ✓ my second test case (0.0s)
  ✓ afterEach (0.0s)

run with timeout

If the test takes longer than the timeout, the test will fail.

import { Dest, job, test } from '@dogu-tech/dest';

Dest.withOptions({
  timeout: 1000, // 1 seconds
}).describe(({ logger }) => {
  job('my first test', () => {
    test('my first test case', () => {
      logger.info('hello world');
    });

    test('my second test case', async () => {
      logger.info('hello world');
      await new Promise((resolve) => setTimeout(resolve, 2000));
    });
  });
});

log output:

  FAIL  
 my first test 
  ✓ my first test case (0.0s)
  ✕ my second test case (1.0s)