mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-01 11:17:50 +02:00
d7c732b282
* fix: Windows support — Node.js server fallback for Playwright Setup hangs on Windows 11 because Bun's child_process can't handle Playwright's --remote-debugging-pipe (fd 3/4 pipe handles). Fall back to Node.js on Windows for both the setup verification and server runtime. macOS/Linux completely unaffected — all Windows code behind IS_WINDOWS / process.platform === 'win32' guards. Based on community PR #194 by @sozairali. Fixed sed -i portability (perl -pi -e) in build-node-server.sh for macOS compatibility. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: cross-platform path handling for Windows compatibility Replace hardcoded '/tmp' and 'dir + "/"' path checks with platform-aware constants from new platform.ts module. On macOS/Linux this evaluates identically ('/tmp', '/'); on Windows it uses os.tmpdir() and path.sep. Zero behavior change on Unix. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * test: add tests for Windows polyfill, platform constants, and Node server resolution Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * docs: Windows support in README + CHANGELOG (v0.9.1.1) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: bump version and changelog (v0.9.3.0) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
73 lines
2.9 KiB
TypeScript
73 lines
2.9 KiB
TypeScript
import { describe, test, expect, afterAll } from 'bun:test';
|
|
import * as path from 'path';
|
|
|
|
// Load the polyfill into a fresh object (don't clobber globalThis.Bun)
|
|
const polyfillPath = path.resolve(import.meta.dir, '../src/bun-polyfill.cjs');
|
|
|
|
describe('bun-polyfill', () => {
|
|
// We test the polyfill by requiring it in a subprocess under Node.js
|
|
// since it's designed for Node, not Bun.
|
|
|
|
test('Bun.sleep resolves after delay', async () => {
|
|
const result = Bun.spawnSync(['node', '-e', `
|
|
require('${polyfillPath}');
|
|
(async () => {
|
|
const start = Date.now();
|
|
await Bun.sleep(50);
|
|
const elapsed = Date.now() - start;
|
|
console.log(elapsed >= 40 ? 'OK' : 'TOO_FAST');
|
|
})();
|
|
`], { stdout: 'pipe', stderr: 'pipe' });
|
|
expect(result.stdout.toString().trim()).toBe('OK');
|
|
expect(result.exitCode).toBe(0);
|
|
});
|
|
|
|
test('Bun.spawnSync runs a command and returns stdout', () => {
|
|
const result = Bun.spawnSync(['node', '-e', `
|
|
require('${polyfillPath}');
|
|
const r = Bun.spawnSync(['echo', 'hello'], { stdout: 'pipe' });
|
|
console.log(r.stdout.toString().trim());
|
|
console.log('exit:' + r.exitCode);
|
|
`], { stdout: 'pipe', stderr: 'pipe' });
|
|
const lines = result.stdout.toString().trim().split('\n');
|
|
expect(lines[0]).toBe('hello');
|
|
expect(lines[1]).toBe('exit:0');
|
|
});
|
|
|
|
test('Bun.spawn launches a process with pid', async () => {
|
|
const result = Bun.spawnSync(['node', '-e', `
|
|
require('${polyfillPath}');
|
|
const p = Bun.spawn(['echo', 'test'], { stdio: ['pipe', 'pipe', 'pipe'] });
|
|
console.log(typeof p.pid === 'number' ? 'HAS_PID' : 'NO_PID');
|
|
console.log(typeof p.kill === 'function' ? 'HAS_KILL' : 'NO_KILL');
|
|
console.log(typeof p.unref === 'function' ? 'HAS_UNREF' : 'NO_UNREF');
|
|
`], { stdout: 'pipe', stderr: 'pipe' });
|
|
const lines = result.stdout.toString().trim().split('\n');
|
|
expect(lines[0]).toBe('HAS_PID');
|
|
expect(lines[1]).toBe('HAS_KILL');
|
|
expect(lines[2]).toBe('HAS_UNREF');
|
|
});
|
|
|
|
test('Bun.serve creates an HTTP server that responds', async () => {
|
|
const result = Bun.spawnSync(['node', '-e', `
|
|
require('${polyfillPath}');
|
|
const server = Bun.serve({
|
|
port: 0, // Note: polyfill uses port directly, so we pick one
|
|
hostname: '127.0.0.1',
|
|
fetch(req) {
|
|
return new Response(JSON.stringify({ ok: true }), {
|
|
headers: { 'Content-Type': 'application/json' },
|
|
});
|
|
},
|
|
});
|
|
// The polyfill doesn't support port 0, so we test the object shape
|
|
console.log(typeof server.stop === 'function' ? 'HAS_STOP' : 'NO_STOP');
|
|
console.log(typeof server.port === 'number' ? 'HAS_PORT' : 'NO_PORT');
|
|
server.stop();
|
|
`], { stdout: 'pipe', stderr: 'pipe' });
|
|
const lines = result.stdout.toString().trim().split('\n');
|
|
expect(lines[0]).toBe('HAS_STOP');
|
|
expect(lines[1]).toBe('HAS_PORT');
|
|
});
|
|
});
|