-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathagent.test.js
More file actions
48 lines (38 loc) · 1.49 KB
/
agent.test.js
File metadata and controls
48 lines (38 loc) · 1.49 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
const assert = require('node:assert');
const mm = require('egg-mock');
const utils = require('../../utils');
describe('test/app/extend/agent.test.js', () => {
afterEach(mm.restore);
describe('agent.addSingleton()', () => {
let app;
before(() => {
app = utils.app('apps/singleton-demo');
return app.ready();
});
after(() => app.close());
it('should add singleton success', async () => {
let config = await app.agent.dataService.get('second').getConfig();
assert(config.foo === 'bar');
assert(config.foo2 === 'bar2');
const ds = app.agent.dataService.createInstance({ foo: 'barrr' });
config = await ds.getConfig();
assert(config.foo === 'barrr');
const ds2 = await app.agent.dataService.createInstanceAsync({ foo: 'barrr' });
config = await ds2.getConfig();
assert(config.foo === 'barrr');
config = await app.agent.dataServiceAsync.get('second').getConfig();
assert(config.foo === 'bar');
assert(config.foo2 === 'bar2');
try {
app.agent.dataServiceAsync.createInstance({ foo: 'barrr' });
throw new Error('should not execute');
} catch (err) {
assert(err.message === 'egg:singleton dataServiceAsync only support create asynchronous, please use createInstanceAsync');
}
const ds4 = await app.agent.dataServiceAsync.createInstanceAsync({ foo: 'barrr' });
config = await ds4.getConfig();
assert(config.foo === 'barrr');
});
});
});