Poku Test Runner

website·Indexed 33 days ago

https://poku.io/docs

A feature-rich, modular, zero-dependency, and cross-platform test runner for Node.js designed to bring the JavaScript essence back to testing.

Tokens
654
Snippets
4
Records
4
Agent score
15%

What's inside Poku

  1. Write basic tests and assertions in Poku

    Poku provides a familiar Node.js-style assertion API. Every assertion method accepts an optional human-readable message as its last argument, which is printed on both success and failure.

    • Use assert for plain assertions.
    • Use test to group logic and assertions into a unit test.
    • Use describe to group test suites (supports nesting).
    • Use it to label individual test cases inside a describe block.
    import { assert, test, strict } from 'poku';
    
    // Plain assertion
    assert.strictEqual(1 + 2, 3, 'Math should add up');
    
    // Unit test with grouping
    test('sum', () => {
      const actual = 2 + 3;
      strict.strictEqual(actual, 5, 'It sums two numbers');
    });
  2. Handle asynchronous tests and resource cleanup in Poku

    For asynchronous tests, await the it or test call to run them sequentially; omit await to run them in parallel.

    Critical Resource Management: Never open or close a service, process, or resource (like a database connection) in the same scope as an assertion that may fail. If an assertion throws, the cleanup code will never run, causing the process to hang. Instead, open and close resources in an outer describe scope.

    import { createConnection } from 'mysql2/promise';
    import { describe, it, assert } from 'poku';
    
    await describe('Users table', async () => {
      // Open resource in outer scope
      const connection = await createConnection({
        host: 'localhost',
        user: 'root',
        database: 'app',
      });
    
      await it('returns the seeded user', async () => {
        const [rows] = await connection.query(
          'SELECT name FROM users WHERE id = ?',
          [1]
        );
    
        assert.deepStrictEqual(
          { ...rows[0] },
          { name: 'Poku' },
          'The seeded user is present'
        );
      });
    
      // Close resource in outer scope to ensure it runs even if 'it' fails
      await connection.end();
    });
  3. Install Poku for Node.js, Bun, or Deno

    Poku is a cross-platform test runner that can be installed across different JavaScript runtimes. For Node.js users wanting TypeScript support, tsx is recommended as an additional dependency.
    # Node.js
    npm i -D poku
    
    # Node.js with TypeScript
    npm i -D poku tsx
    
    # Bun (TypeScript supported natively)
    bun add -d poku
    
    # Deno (TypeScript supported natively, installation is optional)
    deno add npm:poku
  4. Run Poku tests across different runtimes

    Poku can be executed using the CLI for the respective runtime. For repeatable runs, it is recommended to use a package.json script or a deno.json task. Configuration is automatically detected from poku.config.js, .pokurc.json, or .pokurc.jsonc, though a custom path can be provided via the --config (or -c) flag.
    # Node.js
    npx poku
    
    # Bun
    bun --bun poku
    
    # Deno
    deno run npm:poku