0.0.11 • Published 5 months ago

@tonkite/jest-tolk v0.0.11

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 months ago

Jest Runner for Tolk

A Jest runner that enables you to write and execute unit tests for Tolk code using familiar testing patterns.

Example

Consider a simple Tolk function in sum.tolk:

fun calculateSum(a: int, b: int) {
    return a + b;
}

You can write unit tests for this function using Tolk:

import "sum.tolk"

// @scope sum()
get test_returns_sum_of_numbers() {
    val a: int = 4;
    val b: int = 7;

    assert(calculateSum(a, b) == a + b) throw 100;
}

// @scope sum()
// @exitCode 7 (type check error)
get test_fails_if_value_is_not_int() {
    val a: int = null;
    val b: int = 7;

    calculateSum(a, b);
}

Test result:

Installation

  1. Install @tonkite/jest-tolk:
    pnpm add -D @tonkite/jest-tolk
  2. Add runner configuration to jest.config.ts:

    import type { Config } from 'jest';
    
    const config: Config = {
      projects: [
        {
          displayName: 'test',
          preset: 'ts-jest',
          testEnvironment: 'node',
          testPathIgnorePatterns: ['/node_modules/', '/dist/'],
        },
        {
          displayName: 'tolk',
          moduleFileExtensions: ['tolk'],
          testMatch: ['**/*[._]test.tolk'],
          runner: '@tonkite/jest-tolk',
        },
      ],
    };
    
    export default config;

Annotations

The runner allows you to configure the behavior of tests using special annotations in comments.

Example:

/**
 * @test
 * @scope examples
 * @exitCode 500
 */
get should_fail_with_exit_code_500() {
    throw 500;
}

Supported Annotations:

AnnotationExampleDescription
@exitCode [exitCode]// @exitCode 500Specifies the expected exit code. Default: 0.
@scope [scope]// @scope Pool::onSwapSpecifies the scope of a test (useful for test grouping).
@skip// @skipMarks a test to be skipped.
@todo// @todoMarks a test to be done later.
@test// @testMarks a get-method (which isn't prefixed by test_) as a test.
@balance [balance]// @balance 1000000000Sets a balance for a test. Default: 1000000000 (1 TON).
@gasLimit [gas limit]// @gasLimit 50000Sets a gas limit for a test. Default: 10000.
@unixTime [unix time]// @unixTime 1735231203Sets a Unix time for a test. Default: current time.
@no-main// @no-mainDisables adding an entrypoint fun main() {} to avoid collision with an existing one.

License

0.0.10

5 months ago

0.0.11

5 months ago

0.0.9

5 months ago

0.0.8

7 months ago

0.0.7

7 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.4

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago