-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdefine_config.spec.ts
51 lines (42 loc) · 1.56 KB
/
define_config.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
50
51
/*
* @adonisjs/i18n
*
* (c) AdonisJS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { test } from '@japa/runner'
import { ApplicationService } from '@adonisjs/core/types'
import { AppFactory } from '@adonisjs/core/factories/app'
import { FsLoader } from '../src/loaders/fs.js'
import { IcuFormatter } from '../src/messages_formatters/icu.js'
import { defineConfig, formatters, loaders } from '../src/define_config.js'
const BASE_URL = new URL('./', import.meta.url)
const app = new AppFactory().create(BASE_URL, () => {}) as ApplicationService
test.group('Define config', () => {
test('throw error when missing formatter', ({ assert }) => {
assert.rejects(
() => defineConfig({} as any),
'Cannot configure i18n manager. Missing property "formatter"'
)
})
test('transform config with a formatter', async ({ assert }) => {
const config = await defineConfig({
loaders: [],
formatter: formatters.icu(),
}).resolver(app)
assert.isFunction(config.formatter)
assert.instanceOf(config.formatter(config), IcuFormatter)
})
test('transform config with loaders', async ({ assert }) => {
const config = await defineConfig({
loaders: [loaders.fs({ location: BASE_URL })],
formatter: formatters.icu(),
}).resolver(app)
assert.isFunction(config.formatter)
assert.instanceOf(config.formatter(config), IcuFormatter)
assert.isFunction(config.loaders[0])
assert.instanceOf(config.loaders[0](config), FsLoader)
})
})