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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ahr-ahr/selftest

v1.0.0

Published

Universal self-test runner with JSON output and CLI support

Readme

SelfTest

Universal self-test runner lintas bahasa (JavaScript, PHP, Python) dengan output konsisten ke terminal dan JSON.

Node.js CI PHP CI Python CI


✨ Fitur

  • API sederhana: selftest(name, fn) + run().
  • Output CLI interaktif + JSON.
  • Bisa dipanggil dari JS, PHP, atau Python.
  • Mendukung cache hasil test di .cache/.

📦 Instalasi

Node.js (wajib, core di sini)

npm install selftest

PHP Wrapper

Pastikan php ada di PATH, lalu copy wrapper/php/selftest.php ke project.

Python Wrapper

Pastikan python ada di PATH, lalu copy wrapper/python/selftest.py ke project.


🚀 Cara Pakai

JavaScript

const { selftest, run } = require("selftest");

selftest("math add", () => {
  expect(1 + 2).toBe(3);
});

selftest("truthy test", () => {
  expect(true).toBeTruthy();
});

const result = run({ dev: true, keepCache: false });
console.log("Summary:", result.summary);

PHP

<?php
require_once __DIR__ . "/../selftest.php";

SelfTest::selftest("math add", function () {
    return "expect(1 + 2).toBe(3);";
});

SelfTest::selftest("truthy test", function () {
    return "expect(true).toBeTruthy();";
});

$result = SelfTest::run(dev:true, keepCache:true);
print_r($result);

Python

from selftest import selftest, run

selftest("math add", "expect(1 + 2).toBe(3)")
selftest("truthy test", "expect(True).toBeTruthy()")

result = run(dev=True, keep_cache=True)
print("Summary:", result["summary"])

⚙️ Opsi Wrapper

  • dev: true → tampilkan log progres + detail.
  • dev: false → diam, hasil langsung JSON.
  • keepCache: true → file JSON test & result tetap disimpan di .cache/.
  • keepCache: false → file otomatis dihapus.

📂 Struktur Direktori

selftest/
 ├─ core.cjs        # Core runner CJS
 ├─ core.mjs        # Core runner ESM
 ├─ wrapper/
 │   ├─ js/selftest-wrapper.js
 │   ├─ php/selftest.php
 │   └─ python/selftest.py
 └─ examples/
     └─ tests.json

📊 Output

Mode Dev

RUNNING [██████████] 100% | 2/2 tests
✔ math add (0ms)
✔ truthy test (0ms)

=== SUMMARY ===
Total: 2
Passed: 2
Failed: 0
Duration: 0 ms

Mode JSON

{
  "total": 2,
  "passed": 2,
  "failed": 0,
  "duration_ms": 0
}

📝 Tips

  • Tambahkan .cache/ ke .gitignore.

  • Bisa dipanggil lintas bahasa via CLI:

    npx selftest examples/tests.json --json result.json

⚡ CI/CD dengan GitHub Actions

Tambahkan workflow berikut ke repo Anda:

.github/workflows/node.yml

name: Node.js CI
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18, 20]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
      - run: npm install
      - run: npm test

.github/workflows/php.yml

name: PHP CI
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: shivammathur/setup-php@v2
        with:
          php-version: "8.2"
      - run: php wrapper/php/examples/test_math.php

.github/workflows/python.yml

name: Python CI
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: "3.11"
      - run: python wrapper/python/examples/test_math.py

📜 Lisensi

MIT