-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
builder_spec.ts
49 lines (41 loc) · 1.25 KB
/
builder_spec.ts
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
import { expect } from 'chai'
import FormatterBuilder from './builder'
import { pathToFileURL } from 'url'
import path from 'path'
describe('custom class loading', () => {
it('should handle a file:// url', async () => {
const fileUrl = pathToFileURL(
path.resolve(__dirname, './fixtures/module_dot_exports.cjs')
).toString()
const CustomClass = await FormatterBuilder.loadCustomClass(
'formatter',
fileUrl,
__dirname
)
expect(typeof CustomClass).to.eq('function')
})
it('should handle cjs module.exports', async () => {
const CustomClass = await FormatterBuilder.loadCustomClass(
'formatter',
'./fixtures/module_dot_exports.cjs',
__dirname
)
expect(typeof CustomClass).to.eq('function')
})
it('should handle cjs exports.default', async () => {
const CustomClass = await FormatterBuilder.loadCustomClass(
'formatter',
'./fixtures/exports_dot_default.cjs',
__dirname
)
expect(typeof CustomClass).to.eq('function')
})
it('should handle esm default export', async () => {
const CustomClass = await FormatterBuilder.loadCustomClass(
'formatter',
'./fixtures/esm.mjs',
__dirname
)
expect(typeof CustomClass).to.eq('function')
})
})