35 行
979 B
TypeScript
35 行
979 B
TypeScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
|
|
import {
|
|
_notifyInitialized,
|
|
_registerInitializationHandler,
|
|
getConfig,
|
|
initConfigFromRemote,
|
|
} from '../src/config'
|
|
|
|
test('all extensions observe the same initialized config exactly once', async () => {
|
|
const observed: string[] = []
|
|
const unregister = _registerInitializationHandler('test-extension', config => {
|
|
observed.push(`${config.appKey}:${config.apiUrl}`)
|
|
})
|
|
|
|
initConfigFromRemote(
|
|
{
|
|
appKey: 'shared-app',
|
|
platformUrl: 'https://platform.example.test',
|
|
},
|
|
{
|
|
apiUrl: 'https://api.example.test',
|
|
imApiUrl: 'https://im.example.test',
|
|
},
|
|
)
|
|
await _notifyInitialized()
|
|
|
|
assert.equal(getConfig().apiUrl, 'https://api.example.test')
|
|
assert.equal(getConfig().platformUrl, 'https://platform.example.test')
|
|
assert.equal(getConfig().updateEnabled, false)
|
|
assert.deepEqual(observed, ['shared-app:https://api.example.test'])
|
|
unregister()
|
|
})
|