import test from 'node:test'; import assert from 'node:assert/strict'; import { spawnSync } from 'node:child_process'; import { mkdtempSync, readdirSync, rmSync } from 'node:fs'; import os from 'node:os'; import path from 'node:path'; const pkgRoot = path.join(import.meta.dirname, '..'); test('pack: tarball устанавливается локально, bhl version отвечает конвертом', (t) => { const tmp = mkdtempSync(path.join(os.tmpdir(), 'bhl-pack-')); t.after(() => rmSync(tmp, { recursive: true, force: true })); const pack = spawnSync('npm', ['pack', '--pack-destination', tmp], { cwd: pkgRoot, encoding: 'utf8', }); assert.equal(pack.status, 0, pack.stderr); const tarball = readdirSync(tmp).find((name) => name.endsWith('.tgz')); assert.ok(tarball, 'tarball создан'); const installDir = path.join(tmp, 'install'); const install = spawnSync( 'npm', [ 'install', path.join(tmp, tarball), '--prefix', installDir, '--no-save', '--ignore-scripts', '--no-audit', '--no-fund', ], { encoding: 'utf8' }, ); assert.equal(install.status, 0, install.stderr); const bin = path.join(installDir, 'node_modules', '.bin', 'bhl'); const run = spawnSync(bin, ['version'], { encoding: 'utf8' }); assert.equal(run.status, 0, run.stderr); const envelope = JSON.parse(run.stdout); assert.equal(envelope.ok, true); assert.equal(envelope.command, 'version'); assert.equal(envelope.data.name, '@baseline-harness/bhl'); assert.equal(envelope.data.version, '0.0.1'); });