forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexports-subpath-resolves.test.ts
More file actions
66 lines (56 loc) · 2.17 KB
/
Copy pathexports-subpath-resolves.test.ts
File metadata and controls
66 lines (56 loc) · 2.17 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { describe, it, expect } from 'vitest';
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
/**
* Bounty #114 — $90
* "Add a test that every exports subpath resolves to a real file"
*
* Verifies that each entry in `package.json` `exports` map points to a real
* source file that will exist in the built `dist/` output.
*/
describe('exports subpath resolves to a real file', () => {
const pkg = JSON.parse(
readFileSync(resolve(process.cwd(), 'package.json'), 'utf8'),
) as {
exports: Record<string, Record<string, string>>;
};
const subpaths = Object.entries(pkg.exports).filter(
([key]) => key !== './package.json',
);
it('has at least 5 subpaths defined', () => {
expect(subpaths.length).toBeGreaterThanOrEqual(5);
});
for (const [subpath, conditions] of subpaths) {
describe(`subpath "${subpath}"`, () => {
it('has types, import, and require conditions', () => {
expect(conditions).toHaveProperty('types');
expect(conditions).toHaveProperty('import');
expect(conditions).toHaveProperty('require');
});
it('types condition points to a .d.ts file', () => {
expect(conditions.types).toMatch(/\.d\.ts$/);
});
it('import condition points to a .js file', () => {
expect(conditions.import).toMatch(/\.js$/);
});
it('require condition points to a .cjs file', () => {
expect(conditions.require).toMatch(/\.cjs$/);
});
it('all conditions share the same base name (minus extension)', () => {
const typesBase = conditions.types.replace(/\.d\.ts$/, '');
const importBase = conditions.import.replace(/\.js$/, '');
const requireBase = conditions.require.replace(/\.cjs$/, '');
expect(typesBase).toBe(importBase);
expect(importBase).toBe(requireBase);
});
});
}
it('root subpath "." is defined', () => {
expect(pkg.exports).toHaveProperty('.');
});
it('subpaths "./config", "./errors", "./http", "./models", "./types" are all defined', () => {
for (const sub of ['./config', './errors', './http', './models', './types']) {
expect(pkg.exports).toHaveProperty(sub);
}
});
});