示例工程 25-declaration-distribution
25-declaration-distribution/04-types-versions/main.test.mjs
点击「运行示例」后,左侧显示源码、右侧显示运行结果;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('typesVersions 为不同编译器范围提供不同声明', () => {
assert.deepEqual(run(), []);
const pkg = JSON.parse(readFileSync(join(here, 'fixtures', 'pkg', 'package.json'), 'utf8'));
assert.equal(pkg.types, 'modern/index.d.ts');
assert.deepEqual(Object.keys(pkg.typesVersions), ['<5.0', '>=5.0']);
assert.deepEqual(pkg.typesVersions['>=5.0']['*'], ['modern/index.d.ts']);
});