/ src / runtime-detect.test.ts
runtime-detect.test.ts
 1  import { describe, it, expect } from 'vitest';
 2  import { detectRuntime, getRuntimeVersion, getRuntimeLabel } from './runtime-detect.js';
 3  
 4  describe('runtime-detect', () => {
 5    it('detectRuntime returns a valid runtime string', () => {
 6      const rt = detectRuntime();
 7      expect(['bun', 'node']).toContain(rt);
 8    });
 9  
10    it('getRuntimeVersion returns a non-empty version string', () => {
11      const ver = getRuntimeVersion();
12      expect(typeof ver).toBe('string');
13      expect(ver.length).toBeGreaterThan(0);
14    });
15  
16    it('getRuntimeLabel returns "<runtime> <version>" format', () => {
17      const label = getRuntimeLabel();
18      expect(label).toMatch(/^(bun|node) .+$/);
19    });
20  
21    it('detects the current environment correctly', () => {
22      const isBun = typeof (globalThis as { Bun?: unknown }).Bun !== 'undefined';
23      const rt = detectRuntime();
24      if (isBun) {
25        expect(rt).toBe('bun');
26      } else {
27        expect(rt).toBe('node');
28      }
29    });
30  });