Files
harness-lab/packages/bhl/tests/pack.test.mjs
T
Suslov-MD e7adc89089 build: NPM-упаковка @baseline-harness/bhl (BHL-028)
- tsc → dist/ (prepare при pack); bin dist/cli.js — Node запрещает
  type-stripping в node_modules; rewriteRelativeImportExtensions
- files: dist+src+доки; engines >=22.19; private:true — публикация
  только по отдельному поручению (D-034); publishConfig.access public
- тест pack: pack → установка tarball → bhl version (пакет 42/42)
- dist/ в .gitignore
2026-11-29 02:34:24 +03:00

45 lines
1.6 KiB
JavaScript

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');
});