src/import.test.ts
v0.1.0 · 1.4 KB
import { spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { expect, it } from 'vitest';
it('loads all public source entries in Node ESM without a bundler inferring type exports', () => {
const entries = ['index.ts', 'testing/index.ts', 'experimental/index.ts'].map(
(path) => new URL(path, import.meta.url).href,
);
const code = `const [root,testing,experimental]=await Promise.all(${JSON.stringify(entries)}.map(url=>import(url)));for(const [entry,name]of [[root,'createTradeSession'],[testing,'createFakeExchange'],[experimental,'createFillLedger'],[experimental,'createHeaderAuthTradeSession'],[experimental,'createStreamAgeMarketData']])if(typeof entry[name]!=='function')throw new Error('Missing public runtime export: '+name);for(const name of ['createFakeExchange','createFillLedger','createHeaderAuthTradeSession','createStreamAgeMarketData'])if(name in root)throw new Error('Optional entry leaked into root: '+name);console.log('IMPORT_SMOKE_OK');`;
const result = spawnSync(process.execPath, ['--import', 'tsx', '--input-type=module', '--eval', code], {
cwd: fileURLToPath(new URL('../', import.meta.url)),
encoding: 'utf8',
timeout: 10_000,
});
expect(result.error).toBeUndefined();
expect(result.stderr).toBe('');
expect(result.status).toBe(0);
expect(result.stdout.trim()).toBe('IMPORT_SMOKE_OK');
});