-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.test.js
More file actions
32 lines (28 loc) · 1.31 KB
/
Copy pathpackage.test.js
File metadata and controls
32 lines (28 loc) · 1.31 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
import { describe, test, expect } from 'bun:test'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'))
// Item 3: package must expose an exports map covering the documented subpath
// import `fast-hashring/jump-hash.js` (README), with types.
describe('package exports map', () => {
test('defines "." export with default, import and types', () => {
expect(pkg.exports).toBeDefined()
expect(pkg.exports['.']).toBeDefined()
expect(pkg.exports['.'].import).toBe('./consistent-hash.js')
expect(pkg.exports['.'].types).toBeDefined()
})
test('defines "./jump-hash.js" subpath export (documented in README)', () => {
expect(pkg.exports['./jump-hash.js']).toBeDefined()
expect(pkg.exports['./jump-hash.js'].import).toBe('./jump-hash.js')
expect(pkg.exports['./jump-hash.js'].types).toBeDefined()
})
test('uses node: protocol for builtin imports in sources', () => {
for (const f of ['consistent-hash.js', 'jump-hash.js']) {
const src = fs.readFileSync(path.join(__dirname, f), 'utf8')
expect(src).not.toMatch(/from ['"]crypto['"]/)
expect(src).toMatch(/from ['"]node:crypto['"]/)
}
})
})