About: how pages are checked

tests/sims/eventloop.test.ts

The automated tests for the /simulators/event-loop simulator. They run the model on its own, outside the browser, and compare it with a reference that doesn't depend on the model being right. They run on every change to the simulator's code.

  1. Every example without requestAnimationFrame prints the same lines in the same order when Node runs the code shown on the page.
// /simulators/event-loop: tasks, microtasks and timers, against the same JavaScript run in Node.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import { PROGRAMS, outputOf } from '../../src/lib/sims/eventLoop.ts';

// requestAnimationFrame exists only in browsers, so those programs are left out here
const runnable = PROGRAMS.filter((p) => !p.code.includes('requestAnimationFrame'));

test('every example without requestAnimationFrame prints the same lines in the same order when Node runs the code shown on the page', () => {
	assert.ok(runnable.length >= 5, `only ${runnable.length} programs to check`);
	for (const p of runnable) {
		const real = execFileSync(process.execPath, ['--input-type=module', '-e', p.code]).toString().trim().split('\n');
		assert.deepEqual(outputOf(p), real, `${p.id}: model and Node disagree`);
	}
});

Shared helpers: tests/sims/check.ts. The model under test is imported from src/lib/sims/.

Published