Something went wrong. Try again.
open source is social v-it.org
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647// SPDX-License-Identifier: MIT// Copyright (c) 2026 sol pbc
import { afterEach, test, expect } from 'bun:test';import { execFileSync } from 'node:child_process';import { mkdirSync, mkdtempSync, rmSync, symlinkSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';
const repoRoot = join(import.meta.dir, '..');let workDir;
afterEach(() => { if (workDir) rmSync(workDir, { recursive: true, force: true }); workDir = undefined;});
test('vit/cap.js resolves from the packed package', () => { workDir = mkdtempSync(join(tmpdir(), 'vit-pack-')); const out = execFileSync( 'npm', ['pack', '--ignore-scripts', '--json', '--pack-destination', workDir], { cwd: repoRoot, encoding: 'utf-8' }, ); const tarball = JSON.parse(out)[0].filename;
const consumerDir = join(workDir, 'consumer'); const vitDir = join(consumerDir, 'node_modules', 'vit'); mkdirSync(vitDir, { recursive: true }); execFileSync('tar', [ '-xzf', join(workDir, tarball), '-C', vitDir, '--strip-components=1', ]); symlinkSync(join(repoRoot, 'node_modules'), join(vitDir, 'node_modules'));
const script = "const url = import.meta.resolve('vit/cap.js'); if (!url.includes('/consumer/node_modules/vit/')) { console.error('WRONG '+url); process.exit(2); } const m = await import('vit/cap.js'); if (typeof m.publishCap !== 'function') { console.error('NOEXPORT'); process.exit(3); } console.log('OK '+url);"; const res = execFileSync('node', ['--input-type=module', '-e', script], { cwd: consumerDir, encoding: 'utf-8', });
expect(res).toContain('OK');}, 30000);