Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

2.9 KB
Raw Blame
// Runs one Playwright suite and its TypeScript check side by side.
//
//   node scripts/e2e-suite.mjs <tsconfig> <playwright config> [playwright args...]
//
// Each `npm run test:<suite>` used to run `tsc -p <tsconfig> --noEmit &&
// playwright test --config <config>`: the browser run waited for a type check it
// shares nothing with. Checking a suite's specs, fixtures and the app sources they
// import takes 20 to 35 seconds on a CI runner, once per suite. Both now start
// together and the suite fails when either one fails, so the same two checks run
// in the time of the longer one.
//
// The type checker runs at a lower scheduling priority. On a four-vCPU runner it
// otherwise slowed the first browser cases by 10 to 13 seconds per suite. Those
// cases compile the app in the dev server at the same time.
//
// Playwright's output streams as it runs. The type checker's is held and printed
// once both have finished, so the two never interleave. Arguments after the config
// go to Playwright, as `npm run test:<suite> -- <spec files>` did before.
import { spawn } from 'node:child_process';
import { createRequire } from 'node:module';
import os from 'node:os';

const require = createRequire(import.meta.url);
const [tsconfig, config, ...forwarded] = process.argv.slice(2);
if (!tsconfig || !config) {
  console.error('usage: node scripts/e2e-suite.mjs <tsconfig> <playwright config> [playwright args...]');
  process.exit(2);
}

const children = new Set();
for (const signal of ['SIGINT', 'SIGTERM']) {
  process.on(signal, () => {
    for (const child of children) child.kill(signal);
  });
}

function run(script, args, { capture, background = false }) {
  return new Promise((resolve) => {
    const child = spawn(process.execPath, [script, ...args], {
      stdio: capture ? ['ignore', 'pipe', 'pipe'] : 'inherit',
    });
    children.add(child);
    if (background && child.pid !== undefined) {
      try {
        os.setPriority(child.pid, 10);
      } catch {
        // Only scheduling is lost; the check itself still runs.
      }
    }
    let output = '';
    if (capture) {
      child.stdout.on('data', (chunk) => (output += chunk));
      child.stderr.on('data', (chunk) => (output += chunk));
    }
    child.on('error', (error) => {
      children.delete(child);
      resolve({ code: 1, output: `${output}${error.message}\n` });
    });
    child.on('close', (code) => {
      children.delete(child);
      resolve({ code: code ?? 1, output });
    });
  });
}

const [typecheck, suite] = await Promise.all([
  run(require.resolve('typescript/bin/tsc'), ['-p', tsconfig, '--noEmit'], { capture: true, background: true }),
  run(require.resolve('@playwright/test/cli'), ['test', '--config', config, ...forwarded], { capture: false }),
]);

if (typecheck.code === 0) {
  console.log(`tsc -p ${tsconfig}: no type errors`);
} else {
  console.error(`\ntsc -p ${tsconfig} failed:\n${typecheck.output}`);
}
process.exitCode = suite.code || typecheck.code;