forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexports-resolve.test.ts
More file actions
34 lines (29 loc) · 1.21 KB
/
Copy pathexports-resolve.test.ts
File metadata and controls
34 lines (29 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { describe, it, expect } from 'vitest';
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const pkgPath = resolve(__dirname, '../package.json');
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as { exports: Record<string, unknown> };
describe('package exports subpaths', () => {
const exportEntries = Object.entries(pkg.exports).filter(
([key]) => key !== './package.json',
);
for (const [subpath, conditions] of exportEntries) {
it(`${subpath} resolves to existing files with type declarations`, () => {
if (typeof conditions === 'string') {
const filePath = resolve(__dirname, '..', conditions);
expect(() => require.resolve(filePath)).not.toThrow();
return;
}
const condMap = conditions as Record<string, string>;
for (const [condition, relativePath] of Object.entries(condMap)) {
const filePath = resolve(__dirname, '..', relativePath);
expect(() => require.resolve(filePath)).not.toThrow();
if (condition === 'types') {
expect(relativePath).toMatch(/\.d\.(ts|cts)$/);
}
}
});
}
});