Files
jackwener__opencli/src/runtime-detect.test.ts
T
AlexYue 6d1fb6d219 feat(runtime): add Bun runtime compatibility (#459)
* feat(runtime): add runtime detection utility for Bun/Node.js

Add runtime-detect.ts module that detects whether opencli is running
under Bun or Node.js via globalThis.Bun check. Includes helper
functions for version string and label formatting.

Add corresponding unit tests that work correctly under both runtimes.

* feat(runtime): integrate Bun runtime support into CLI tooling

- doctor: show runtime label (e.g. 'node v22.13.0') in diagnostic output
- package.json: add dev:bun, start:bun, test:bun convenience scripts
- E2E helpers: support OPENCLI_TEST_RUNTIME env var for runtime selection

* ci: add Bun compatibility test job and document runtime support

- ci.yml: add bun-test job using oven-sh/setup-bun@v2
- README.md: update Prerequisites to mention Bun, add Runtime Support
  section with usage examples for dev:bun, start:bun, test:bun

* ci: pin Bun version in compatibility job

---------

Co-authored-by: jackwener <jakevingoo@gmail.com>
2026-03-26 19:10:31 +08:00

31 lines
932 B
TypeScript

import { describe, it, expect } from 'vitest';
import { detectRuntime, getRuntimeVersion, getRuntimeLabel } from './runtime-detect.js';
describe('runtime-detect', () => {
it('detectRuntime returns a valid runtime string', () => {
const rt = detectRuntime();
expect(['bun', 'node']).toContain(rt);
});
it('getRuntimeVersion returns a non-empty version string', () => {
const ver = getRuntimeVersion();
expect(typeof ver).toBe('string');
expect(ver.length).toBeGreaterThan(0);
});
it('getRuntimeLabel returns "<runtime> <version>" format', () => {
const label = getRuntimeLabel();
expect(label).toMatch(/^(bun|node) .+$/);
});
it('detects the current environment correctly', () => {
const isBun = typeof (globalThis as any).Bun !== 'undefined';
const rt = detectRuntime();
if (isBun) {
expect(rt).toBe('bun');
} else {
expect(rt).toBe('node');
}
});
});