0.0.63 • Published 5 months ago

@dogu-tech/dest v0.0.63

Weekly downloads
-
License
SEE LICENSE IN ht...
Repository
-
Last release
5 months ago

@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

propertyrequired/optionaltypedefaultdescription
timeoutoptionalnumber60000execution timeout.
logToFileoptionalbooleanfalselog 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)
0.0.63

5 months ago

0.0.62

5 months ago

0.0.60

5 months ago

0.0.61

5 months ago

0.0.59

5 months ago

0.0.58

5 months ago

0.0.55

5 months ago

0.0.56

5 months ago

0.0.57

5 months ago

0.0.51

6 months ago

0.0.52

6 months ago

0.0.53

6 months ago

0.0.54

6 months ago

0.0.50

6 months ago

0.0.48

6 months ago

0.0.49

6 months ago

0.0.40

6 months ago

0.0.41

6 months ago

0.0.42

6 months ago

0.0.43

6 months ago

0.0.44

6 months ago

0.0.45

6 months ago

0.0.46

6 months ago

0.0.47

6 months ago

0.0.37

6 months ago

0.0.38

6 months ago

0.0.39

6 months ago

0.0.30

6 months ago

0.0.31

6 months ago

0.0.32

6 months ago

0.0.33

6 months ago

0.0.34

6 months ago

0.0.35

6 months ago

0.0.36

6 months ago

0.0.26

8 months ago

0.0.27

7 months ago

0.0.28

7 months ago

0.0.29

7 months ago

0.0.20

9 months ago

0.0.21

9 months ago

0.0.22

9 months ago

0.0.23

8 months ago

0.0.24

8 months ago

0.0.25

8 months ago

0.0.15

10 months ago

0.0.16

10 months ago

0.0.17

10 months ago

0.0.18

10 months ago

0.0.19

9 months ago

0.0.10

10 months ago

0.0.11

10 months ago

0.0.12

10 months ago

0.0.13

10 months ago

0.0.14

10 months ago

0.0.8-development.1

11 months ago

0.0.7-development.1

11 months ago

0.0.6-development.3

12 months ago

0.0.6-development.2

12 months ago

0.0.9

11 months ago

0.0.8

11 months ago

0.0.7

12 months ago

0.0.6-development.1

12 months ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.1-0

1 year ago

0.0.0

1 year ago