示例工程 25-declaration-distribution

25-declaration-distribution/02-exports-matrix/main.test.mjs

javascript · 0.7 KB

运行:25 · exports-matrix

点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
import { run } from './dist/main.js';
 
const here = dirname(fileURLToPath(import.meta.url));
 
test('exports 矩阵为根与子路径分别提供 types/import/require', () => {
  assert.deepEqual(run(), []);
  const pkg = JSON.parse(readFileSync(join(here, 'fixtures', 'pkg', 'package.json'), 'utf8'));
  assert.deepEqual(Object.keys(pkg.exports['.']), ['types', 'import', 'require', 'default']);
  assert.equal(pkg.exports['.'].types, './types/index.d.ts');
  assert.equal(pkg.exports['./feature'].types, './types/feature.d.ts');
});