import assert from 'node:assert/strict' import { execFileSync } from 'node:child_process' import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' import { test } from 'node:test' test('the README zero-config example reads the block number and closes the client', () => { const readme = readFileSync(new URL('../README.md', import.meta.url), 'utf8') const example = readme.match(/\x60\x60\x60js\n([^\x60]*\/\/ Zero-config:[^\x60]*)\x60\x60\x60/)?.[1] assert.ok(example, 'expected a zero-config JavaScript example in README.md') const directory = mkdtempSync(join(tmpdir(), 'tevm-readme-')) try { // Stand in for the public package so this only tests the documented consumer code. const pkg = join(directory, 'node_modules', '@tevm', 'memory-client') mkdirSync(pkg, { recursive: true }) writeFileSync(join(pkg, 'package.json'), '{"exports":"./index.mjs"}') writeFileSync( join(pkg, 'index.mjs'), `import assert from 'node:assert/strict' export function createMemoryClient(...args) { assert.deepEqual(args, []) return { async getBlockNumber() { return 0n }, async tevmClose() { console.log('closed') }, } } `, ) const entry = join(directory, 'example.mjs') writeFileSync(entry, example) assert.equal(execFileSync(process.execPath, [entry], { encoding: 'utf8' }), '0n\nclosed\n') } finally { rmSync(directory, { recursive: true, force: true }) } })