-
Notifications
You must be signed in to change notification settings - Fork 395
/
config.test.ts
47 lines (40 loc) · 1.34 KB
/
config.test.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
import { describe, test, assert } from 'vitest'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { loadConfig } from '../../src/cli/utils'
import { ERR_UNSUPPORTED_CONFIG_FORMAT } from '../../src/cli/errors'
import { expect } from 'vitest'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
describe('loadConfig', () => {
const RE_ERR = RegExp(ERR_UNSUPPORTED_CONFIG_FORMAT)
test('js', async () => {
const config = await loadConfig(
path.resolve(__dirname, 'fixtures/rolldown.config.js'),
)
assert.deepEqual(config, { input: 'src/index.js' })
})
test('mjs', async () => {
const config = await loadConfig(
path.resolve(__dirname, 'fixtures/rolldown.config.mjs'),
)
assert.deepEqual(config, [
{ input: 'src/app1/index.js' },
{ input: 'src/app2/index.js' },
])
})
test('cjs', async () => {
await expect(
loadConfig(path.resolve(__dirname, 'fixtures/rolldown.config.cjs')),
).rejects.toThrowError(RE_ERR)
})
test('other format', async () => {
await expect(
loadConfig(path.resolve(__dirname, 'fixtures/rolldown.config.json')),
).rejects.toThrowError(RE_ERR)
})
test('not found file', async () => {
await expect(
loadConfig(path.join(__dirname, 'fixtures/rollup.config.js')),
).rejects.toThrowError(Error)
})
})