@celljs/core 3.9.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -6
- package/cell.remote.yml +8 -0
- package/cell.yml +0 -3
- package/esm/common/application/application-entry.js +21 -3
- package/esm/common/application/application-entry.js.map +1 -1
- package/esm/common/application/application-host.d.ts +38 -0
- package/esm/common/application/application-host.js +17 -0
- package/esm/common/application/application-host.js.map +1 -0
- package/esm/common/application/application-protocol.js +1 -1
- package/esm/common/application/application-protocol.js.map +1 -1
- package/esm/common/application/index.d.ts +1 -0
- package/esm/common/application/index.js +1 -0
- package/esm/common/application/index.js.map +1 -1
- package/esm/common/config/config-provider.js +2 -1
- package/esm/common/config/config-provider.js.map +1 -1
- package/esm/common/config/env-config-util.d.ts +48 -0
- package/esm/common/config/env-config-util.js +185 -0
- package/esm/common/config/env-config-util.js.map +1 -0
- package/esm/common/config/index.d.ts +1 -0
- package/esm/common/config/index.js +1 -0
- package/esm/common/config/index.js.map +1 -1
- package/esm/common/container/auto-bind.js +26 -12
- package/esm/common/container/auto-bind.js.map +1 -1
- package/esm/common/el/expression-compiler.d.ts +4 -15
- package/esm/common/el/expression-compiler.js +6 -163
- package/esm/common/el/expression-compiler.js.map +1 -1
- package/esm/common/el/expression-handler.d.ts +7 -2
- package/esm/common/el/expression-handler.js +14 -53
- package/esm/common/el/expression-handler.js.map +1 -1
- package/esm/common/el/expression-util.d.ts +68 -0
- package/esm/common/el/expression-util.js +347 -0
- package/esm/common/el/expression-util.js.map +1 -0
- package/esm/common/el/index.d.ts +1 -0
- package/esm/common/el/index.js +1 -0
- package/esm/common/el/index.js.map +1 -1
- package/esm/common/logger/abstract-logger.d.ts +4 -2
- package/esm/common/logger/abstract-logger.js +11 -6
- package/esm/common/logger/abstract-logger.js.map +1 -1
- package/esm/common/logger/logger-protocol.d.ts +4 -0
- package/esm/common/logger/logger-protocol.js +2 -0
- package/esm/common/logger/logger-protocol.js.map +1 -1
- package/esm/common/logger/logger.js +7 -7
- package/esm/common/logger/logger.js.map +1 -1
- package/esm/common/test/mock-logger.d.ts +1 -0
- package/esm/common/test/mock-logger.js +3 -0
- package/esm/common/test/mock-logger.js.map +1 -1
- package/esm/common/utils/emitter.d.ts +1 -10
- package/esm/common/utils/emitter.js +0 -56
- package/esm/common/utils/emitter.js.map +1 -1
- package/esm/common/utils/mime-type-util.js +1 -1
- package/esm/common/utils/mime-type-util.js.map +1 -1
- package/esm/common/utils/mime-type.js +1 -1
- package/esm/common/utils/mime-type.js.map +1 -1
- package/esm/node/context/context.d.ts +11 -2
- package/esm/node/context/context.js +36 -12
- package/esm/node/context/context.js.map +1 -1
- package/esm/node/index.d.ts +0 -1
- package/esm/node/index.js +0 -1
- package/esm/node/index.js.map +1 -1
- package/lib/common/aop/aop.spec.d.ts +2 -0
- package/lib/common/aop/aop.spec.d.ts.map +1 -0
- package/lib/common/aop/aop.spec.js +170 -0
- package/lib/common/aop/aop.spec.js.map +1 -0
- package/lib/common/application/application-entry.d.ts.map +1 -1
- package/lib/common/application/application-entry.js +21 -3
- package/lib/common/application/application-entry.js.map +1 -1
- package/lib/common/application/application-host.d.ts +39 -0
- package/lib/common/application/application-host.d.ts.map +1 -0
- package/lib/common/application/application-host.js +20 -0
- package/lib/common/application/application-host.js.map +1 -0
- package/lib/common/application/application-protocol.js +1 -1
- package/lib/common/application/application-protocol.js.map +1 -1
- package/lib/common/application/index.d.ts +1 -0
- package/lib/common/application/index.d.ts.map +1 -1
- package/lib/common/application/index.js +1 -0
- package/lib/common/application/index.js.map +1 -1
- package/lib/common/application/lifecycle.spec.d.ts +2 -0
- package/lib/common/application/lifecycle.spec.d.ts.map +1 -0
- package/lib/common/application/lifecycle.spec.js +155 -0
- package/lib/common/application/lifecycle.spec.js.map +1 -0
- package/lib/common/config/config-provider.js +2 -1
- package/lib/common/config/config-provider.js.map +1 -1
- package/lib/common/config/env-config-util.d.ts +49 -0
- package/lib/common/config/env-config-util.d.ts.map +1 -0
- package/lib/common/config/env-config-util.js +188 -0
- package/lib/common/config/env-config-util.js.map +1 -0
- package/lib/common/config/env-config-util.spec.d.ts +2 -0
- package/lib/common/config/env-config-util.spec.d.ts.map +1 -0
- package/lib/common/config/env-config-util.spec.js +314 -0
- package/lib/common/config/env-config-util.spec.js.map +1 -0
- package/lib/common/config/index.d.ts +1 -0
- package/lib/common/config/index.d.ts.map +1 -1
- package/lib/common/config/index.js +1 -0
- package/lib/common/config/index.js.map +1 -1
- package/lib/common/container/assembly.spec.d.ts +2 -0
- package/lib/common/container/assembly.spec.d.ts.map +1 -0
- package/lib/common/container/assembly.spec.js +464 -0
- package/lib/common/container/assembly.spec.js.map +1 -0
- package/lib/common/container/auto-bind.js +26 -12
- package/lib/common/container/auto-bind.js.map +1 -1
- package/lib/common/el/expression-compiler.d.ts +4 -15
- package/lib/common/el/expression-compiler.d.ts.map +1 -1
- package/lib/common/el/expression-compiler.js +6 -163
- package/lib/common/el/expression-compiler.js.map +1 -1
- package/lib/common/el/expression-handler.d.ts +7 -2
- package/lib/common/el/expression-handler.d.ts.map +1 -1
- package/lib/common/el/expression-handler.js +14 -56
- package/lib/common/el/expression-handler.js.map +1 -1
- package/lib/common/el/expression-handler.spec.d.ts +2 -0
- package/lib/common/el/expression-handler.spec.d.ts.map +1 -0
- package/lib/common/el/expression-handler.spec.js +99 -0
- package/lib/common/el/expression-handler.spec.js.map +1 -0
- package/lib/common/el/expression-util.d.ts +69 -0
- package/lib/common/el/expression-util.d.ts.map +1 -0
- package/lib/common/el/expression-util.js +352 -0
- package/lib/common/el/expression-util.js.map +1 -0
- package/lib/common/el/expression-util.spec.d.ts +2 -0
- package/lib/common/el/expression-util.spec.d.ts.map +1 -0
- package/lib/common/el/expression-util.spec.js +45 -0
- package/lib/common/el/expression-util.spec.js.map +1 -0
- package/lib/common/el/index.d.ts +1 -0
- package/lib/common/el/index.d.ts.map +1 -1
- package/lib/common/el/index.js +1 -0
- package/lib/common/el/index.js.map +1 -1
- package/lib/common/el/value-and-el.spec.d.ts +2 -0
- package/lib/common/el/value-and-el.spec.d.ts.map +1 -0
- package/lib/common/el/value-and-el.spec.js +216 -0
- package/lib/common/el/value-and-el.spec.js.map +1 -0
- package/lib/common/logger/abstract-logger.d.ts +4 -2
- package/lib/common/logger/abstract-logger.d.ts.map +1 -1
- package/lib/common/logger/abstract-logger.js +10 -5
- package/lib/common/logger/abstract-logger.js.map +1 -1
- package/lib/common/logger/logger-protocol.d.ts +4 -0
- package/lib/common/logger/logger-protocol.d.ts.map +1 -1
- package/lib/common/logger/logger-protocol.js +3 -1
- package/lib/common/logger/logger-protocol.js.map +1 -1
- package/lib/common/logger/logger.js +7 -7
- package/lib/common/logger/logger.js.map +1 -1
- package/lib/common/logger/logger.spec.d.ts +2 -0
- package/lib/common/logger/logger.spec.d.ts.map +1 -0
- package/lib/common/logger/logger.spec.js +57 -0
- package/lib/common/logger/logger.spec.js.map +1 -0
- package/lib/common/test/mock-logger.d.ts +1 -0
- package/lib/common/test/mock-logger.d.ts.map +1 -1
- package/lib/common/test/mock-logger.js +3 -0
- package/lib/common/test/mock-logger.js.map +1 -1
- package/lib/common/utils/emitter.d.ts +1 -10
- package/lib/common/utils/emitter.d.ts.map +1 -1
- package/lib/common/utils/emitter.js +1 -58
- package/lib/common/utils/emitter.js.map +1 -1
- package/lib/common/utils/mime-type-util.js +1 -1
- package/lib/common/utils/mime-type-util.js.map +1 -1
- package/lib/common/utils/mime-type.js +1 -1
- package/lib/common/utils/mime-type.js.map +1 -1
- package/lib/common/utils/utils-behavior.spec.d.ts +2 -0
- package/lib/common/utils/utils-behavior.spec.d.ts.map +1 -0
- package/lib/common/utils/utils-behavior.spec.js +232 -0
- package/lib/common/utils/utils-behavior.spec.js.map +1 -0
- package/lib/node/context/context.d.ts +11 -2
- package/lib/node/context/context.d.ts.map +1 -1
- package/lib/node/context/context.js +36 -10
- package/lib/node/context/context.js.map +1 -1
- package/lib/node/context/context.spec.d.ts +2 -0
- package/lib/node/context/context.spec.d.ts.map +1 -0
- package/lib/node/context/context.spec.js +202 -0
- package/lib/node/context/context.spec.js.map +1 -0
- package/lib/node/index.d.ts +0 -1
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +0 -1
- package/lib/node/index.js.map +1 -1
- package/package.json +20 -41
- package/src/common/aop/aop.spec.ts +145 -0
- package/src/common/application/application-entry.ts +20 -4
- package/src/common/application/application-host.ts +46 -0
- package/src/common/application/application-protocol.ts +1 -1
- package/src/common/application/index.ts +1 -0
- package/src/common/application/lifecycle.spec.ts +148 -0
- package/src/common/config/config-provider.ts +1 -1
- package/src/common/config/env-config-util.spec.ts +341 -0
- package/src/common/config/env-config-util.ts +225 -0
- package/src/common/config/index.ts +1 -0
- package/src/common/container/assembly.spec.ts +293 -0
- package/src/common/container/auto-bind.ts +23 -10
- package/src/common/el/expression-compiler.ts +6 -166
- package/src/common/el/expression-handler.spec.ts +110 -0
- package/src/common/el/expression-handler.ts +14 -51
- package/src/common/el/expression-util.spec.ts +45 -0
- package/src/common/el/expression-util.ts +363 -0
- package/src/common/el/index.ts +2 -1
- package/src/common/el/value-and-el.spec.ts +186 -0
- package/src/common/logger/abstract-logger.ts +12 -6
- package/src/common/logger/logger-protocol.ts +5 -0
- package/src/common/logger/logger.spec.ts +61 -0
- package/src/common/logger/logger.ts +7 -7
- package/src/common/test/mock-logger.ts +3 -0
- package/src/common/utils/emitter.ts +1 -63
- package/src/common/utils/mime-type-util.ts +1 -1
- package/src/common/utils/mime-type.ts +1 -1
- package/src/common/utils/utils-behavior.spec.ts +259 -0
- package/src/node/context/context.spec.ts +219 -0
- package/src/node/context/context.ts +35 -10
- package/src/node/index.ts +0 -1
- package/cell-remote.yml +0 -3
- package/esm/node/utils/crc.d.ts +0 -1
- package/esm/node/utils/crc.js +0 -7
- package/esm/node/utils/crc.js.map +0 -1
- package/esm/node/utils/index.d.ts +0 -1
- package/esm/node/utils/index.js +0 -2
- package/esm/node/utils/index.js.map +0 -1
- package/lib/node/utils/crc.d.ts +0 -2
- package/lib/node/utils/crc.d.ts.map +0 -1
- package/lib/node/utils/crc.js +0 -10
- package/lib/node/utils/crc.js.map +0 -1
- package/lib/node/utils/index.d.ts +0 -2
- package/lib/node/utils/index.d.ts.map +0 -1
- package/lib/node/utils/index.js +0 -18
- package/lib/node/utils/index.js.map +0 -1
- package/src/node/utils/crc.ts +0 -7
- package/src/node/utils/index.ts +0 -1
|
@@ -7,24 +7,24 @@ import { Logger } from './logger-protocol';
|
|
|
7
7
|
export class LoggerImpl extends AbstractLogger {
|
|
8
8
|
|
|
9
9
|
error(message: any, context?: string): void {
|
|
10
|
-
this.log(message, context, console.error.bind(console));
|
|
10
|
+
this.log(message, context, console.error.bind(console), 'error');
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
info(message: any, context?: string): void {
|
|
14
|
-
if (
|
|
15
|
-
this.log(message, context);
|
|
14
|
+
if (this.isEnabled('info')) {
|
|
15
|
+
this.log(message, context, console.info.bind(console), 'info');
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
warn(message: any, context?: string): void {
|
|
20
|
-
if (
|
|
21
|
-
this.log(message, context, console.warn.bind(console));
|
|
20
|
+
if (this.isEnabled('warn')) {
|
|
21
|
+
this.log(message, context, console.warn.bind(console), 'warn');
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
debug(message: any, context?: string): void {
|
|
26
|
-
if (this.
|
|
27
|
-
this.log(message, context, console.debug.bind(console));
|
|
26
|
+
if (this.isEnabled('debug')) {
|
|
27
|
+
this.log(message, context, console.debug.bind(console), 'debug');
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Event,
|
|
1
|
+
import { Event, CallbackList } from './event';
|
|
2
2
|
import { Disposable } from './disposable';
|
|
3
3
|
import { MaybePromise } from './prioritizeable';
|
|
4
4
|
|
|
@@ -204,65 +204,3 @@ export namespace WaitUntilEvent {
|
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
|
-
|
|
208
|
-
import { CancellationToken } from './cancellation';
|
|
209
|
-
|
|
210
|
-
export class AsyncEmitter<T extends WaitUntilEvent> extends Emitter<T> {
|
|
211
|
-
|
|
212
|
-
protected deliveryQueue: Promise<void> | undefined;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Fire listeners async one after another.
|
|
216
|
-
*/
|
|
217
|
-
override fire(event: Omit<T, 'waitUntil'>, token: CancellationToken = CancellationToken.None,
|
|
218
|
-
promiseJoin?: (p: Promise<any>, listener: Function) => Promise<any>): Promise<void> {
|
|
219
|
-
const callbacks = this._callbacks;
|
|
220
|
-
if (!callbacks) {
|
|
221
|
-
return Promise.resolve();
|
|
222
|
-
}
|
|
223
|
-
const listeners = [...callbacks];
|
|
224
|
-
if (this.deliveryQueue) {
|
|
225
|
-
return this.deliveryQueue = this.deliveryQueue.then(() => this.deliver(listeners, event, token, promiseJoin));
|
|
226
|
-
}
|
|
227
|
-
return this.deliveryQueue = this.deliver(listeners, event, token, promiseJoin);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
protected async deliver(listeners: Callback[], event: Omit<T, 'waitUntil'>, token: CancellationToken,
|
|
231
|
-
promiseJoin?: (p: Promise<any>, listener: Function) => Promise<any>): Promise<void> {
|
|
232
|
-
for (const listener of listeners) {
|
|
233
|
-
if (token.isCancellationRequested) {
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
const waitables: Promise<void>[] = [];
|
|
237
|
-
const asyncEvent = Object.assign(event, {
|
|
238
|
-
waitUntil: (thenable: Promise<any>) => {
|
|
239
|
-
if (Object.isFrozen(waitables)) {
|
|
240
|
-
throw new Error('waitUntil cannot be called asynchronously.');
|
|
241
|
-
}
|
|
242
|
-
if (promiseJoin) {
|
|
243
|
-
thenable = promiseJoin(thenable, listener);
|
|
244
|
-
}
|
|
245
|
-
waitables.push(thenable);
|
|
246
|
-
}
|
|
247
|
-
}) as T;
|
|
248
|
-
try {
|
|
249
|
-
listener(event);
|
|
250
|
-
// Asynchronous calls to `waitUntil` should fail.
|
|
251
|
-
Object.freeze(waitables);
|
|
252
|
-
} catch (e) {
|
|
253
|
-
console.error(e);
|
|
254
|
-
} finally {
|
|
255
|
-
delete (asyncEvent as any)['waitUntil'];
|
|
256
|
-
}
|
|
257
|
-
if (!waitables.length) {
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
try {
|
|
261
|
-
await Promise.all(waitables);
|
|
262
|
-
} catch (e) {
|
|
263
|
-
console.error(e);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
}
|
|
@@ -110,7 +110,7 @@ export abstract class MimeTypeUtils {
|
|
|
110
110
|
if (!mimeTypes) {
|
|
111
111
|
return [];
|
|
112
112
|
}
|
|
113
|
-
return this.tokenize(mimeTypes).filter(mimeType => !!mimeType).map(this.parseMimeType);
|
|
113
|
+
return this.tokenize(mimeTypes).filter(mimeType => !!mimeType).map(mimeType => this.parseMimeType(mimeType));
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
static tokenize(mimeTypes: string): string[] {
|
|
@@ -57,7 +57,7 @@ export class MimeType {
|
|
|
57
57
|
this.subtype = subtype.toLowerCase();
|
|
58
58
|
if (parameters) {
|
|
59
59
|
const map: Map<string, string> = new Map();
|
|
60
|
-
for (const [key, value] of
|
|
60
|
+
for (const [key, value] of parameters.entries()) {
|
|
61
61
|
this.checkParameters(key, value);
|
|
62
62
|
map.set(key.toLowerCase(), value);
|
|
63
63
|
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { describe, it } from 'bun:test';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
// 通过 common 入口导入:直接深导入 utils/mime-type-util 会因 error 模块的循环依赖拿到未初始化的 CustomError
|
|
4
|
+
import {
|
|
5
|
+
UrlUtil, ByteUtil, isUUID, generateUUUID, Emitter, Event, Disposable, DisposableCollection,
|
|
6
|
+
CancellationTokenSource, CancellationToken, cancelled, isCancelled, checkCancelled,
|
|
7
|
+
MimeTypeUtils, MimeType, WaitUntilEvent, InvalidMimeTypeError, IllegalArgumentError
|
|
8
|
+
} from '../index';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* core 常用工具的约定(阶段 1.E 行为测试)。只测公开 API 的输入输出。
|
|
12
|
+
*/
|
|
13
|
+
describe('core utils:UrlUtil.join', () => {
|
|
14
|
+
it('拼接时合并多余的斜杠,保留协议,第一个片段的开头和最后一个片段的结尾各保留一个', () => {
|
|
15
|
+
expect(UrlUtil.join('http://a.com/', '/api/', '/users')).to.equal('http://a.com/api/users');
|
|
16
|
+
expect(UrlUtil.join('/base/', 'x/')).to.equal('/base/x/');
|
|
17
|
+
expect(UrlUtil.join('http:', 'a.com', 'b')).to.equal('http://a.com/b');
|
|
18
|
+
expect(UrlUtil.join('file:///', 'tmp', 'f')).to.equal('file:///tmp/f');
|
|
19
|
+
expect(UrlUtil.join('a', '', 'b')).to.equal('a/b');
|
|
20
|
+
expect(UrlUtil.join()).to.equal('');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('查询串:多个 ? 合成一个,后面的改成 &;? 前的斜杠去掉', () => {
|
|
24
|
+
expect(UrlUtil.join('http://a.com/', '?x=1', '?y=2')).to.equal('http://a.com?x=1&y=2');
|
|
25
|
+
expect(UrlUtil.join('/p/', '#hash')).to.equal('/p#hash');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('不是字符串时抛 TypeError', () => {
|
|
29
|
+
expect(() => UrlUtil.join(1 as any)).to.throw(TypeError);
|
|
30
|
+
expect(() => UrlUtil.join('a', 2 as any)).to.throw(TypeError);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('core utils:ByteUtil 与 UUID', () => {
|
|
35
|
+
it('decode:字符串原样返回,Buffer/Uint8Array 按 UTF-8 解码,空值为空串', () => {
|
|
36
|
+
expect(ByteUtil.decode('文本')).to.equal('文本');
|
|
37
|
+
expect(ByteUtil.decode(Buffer.from('中文🙂'))).to.equal('中文🙂');
|
|
38
|
+
expect(ByteUtil.decode(new TextEncoder().encode('ok'))).to.equal('ok');
|
|
39
|
+
expect(ByteUtil.decode(undefined as any)).to.equal('');
|
|
40
|
+
expect(() => ByteUtil.decode({} as any)).to.throw(IllegalArgumentError);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('base64 编解码往返', () => {
|
|
44
|
+
const b64 = ByteUtil.encodeBase64('héllo 世界');
|
|
45
|
+
expect(b64).to.equal(Buffer.from('héllo 世界').toString('base64'));
|
|
46
|
+
expect(ByteUtil.decode(ByteUtil.decodeBase64(b64))).to.equal('héllo 世界');
|
|
47
|
+
expect(ByteUtil.encodeBase64(new Uint8Array([0, 255]))).to.equal('AP8=');
|
|
48
|
+
expect(ByteUtil.encodeBase64('')).to.equal('');
|
|
49
|
+
expect(ByteUtil.decodeBase64('')).to.have.length(0);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('generateUUUID 生成 v4 UUID,互不重复;isUUID 校验格式', () => {
|
|
53
|
+
const ids = new Set(Array.from({ length: 200 }, () => generateUUUID()));
|
|
54
|
+
expect(ids.size).to.equal(200);
|
|
55
|
+
for (const id of ids) {
|
|
56
|
+
expect(isUUID(id)).to.equal(true);
|
|
57
|
+
expect(id[14]).to.equal('4');
|
|
58
|
+
}
|
|
59
|
+
expect(isUUID('not-a-uuid')).to.equal(false);
|
|
60
|
+
expect(isUUID('3F2504E0-4F89-11D3-9A0C-0305E82C3301')).to.equal(true);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('core utils:Emitter / Event / Disposable', () => {
|
|
65
|
+
it('fire 通知所有监听器;dispose 后的监听器不再收到;thisArgs 生效', () => {
|
|
66
|
+
const emitter = new Emitter<number>();
|
|
67
|
+
const got: number[] = [];
|
|
68
|
+
const ctx = { factor: 10 };
|
|
69
|
+
const d1 = emitter.event(n => got.push(n));
|
|
70
|
+
emitter.event(function (this: typeof ctx, n: number) { got.push(n * this.factor); }, ctx);
|
|
71
|
+
emitter.fire(1);
|
|
72
|
+
d1.dispose();
|
|
73
|
+
d1.dispose();
|
|
74
|
+
emitter.fire(2);
|
|
75
|
+
expect(got).to.deep.equal([1, 10, 20]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('监听器抛错不影响其他监听器', () => {
|
|
79
|
+
const emitter = new Emitter<string>();
|
|
80
|
+
const got: string[] = [];
|
|
81
|
+
const origError = console.error;
|
|
82
|
+
console.error = () => { };
|
|
83
|
+
try {
|
|
84
|
+
emitter.event(() => { throw new Error('bad'); });
|
|
85
|
+
emitter.event(s => got.push(s));
|
|
86
|
+
emitter.fire('x');
|
|
87
|
+
} finally {
|
|
88
|
+
console.error = origError;
|
|
89
|
+
}
|
|
90
|
+
expect(got).to.deep.equal(['x']);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('onFirstListenerAdd / onLastListenerRemove;disposables 数组会收到订阅句柄', () => {
|
|
94
|
+
const log: string[] = [];
|
|
95
|
+
const emitter = new Emitter<void>({ onFirstListenerAdd: () => log.push('first'), onLastListenerRemove: () => log.push('last') });
|
|
96
|
+
const bucket: Disposable[] = [];
|
|
97
|
+
emitter.event(() => { }, undefined, bucket);
|
|
98
|
+
emitter.event(() => { }, undefined, bucket);
|
|
99
|
+
expect(bucket).to.have.length(2);
|
|
100
|
+
bucket.forEach(d => d.dispose());
|
|
101
|
+
expect(log).to.deep.equal(['first', 'last']);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('emitter.dispose 之后 fire 不再通知', () => {
|
|
105
|
+
const emitter = new Emitter<number>();
|
|
106
|
+
const got: number[] = [];
|
|
107
|
+
emitter.event(n => got.push(n));
|
|
108
|
+
emitter.dispose();
|
|
109
|
+
emitter.fire(1);
|
|
110
|
+
expect(got).to.deep.equal([]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('Event.map 转换事件值;Event.None 订阅无效果', () => {
|
|
114
|
+
const emitter = new Emitter<number>();
|
|
115
|
+
const got: string[] = [];
|
|
116
|
+
Event.map(emitter.event, n => `#${n}`)(s => got.push(s));
|
|
117
|
+
emitter.fire(7);
|
|
118
|
+
expect(got).to.deep.equal(['#7']);
|
|
119
|
+
Event.None(() => { throw new Error('never'); }).dispose();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('DisposableCollection:倒序释放,只触发一次 onDispose;单个元素可单独移除', () => {
|
|
123
|
+
const order: string[] = [];
|
|
124
|
+
const coll = new DisposableCollection(Disposable.create(() => order.push('a')));
|
|
125
|
+
coll.push(Disposable.create(() => order.push('b')));
|
|
126
|
+
const removable = coll.push(Disposable.create(() => order.push('c')));
|
|
127
|
+
let fired = 0;
|
|
128
|
+
coll.onDispose(() => fired++);
|
|
129
|
+
removable.dispose();
|
|
130
|
+
expect(coll.disposed).to.equal(false);
|
|
131
|
+
coll.dispose();
|
|
132
|
+
coll.dispose();
|
|
133
|
+
expect(order).to.deep.equal(['b', 'a']);
|
|
134
|
+
expect(coll.disposed).to.equal(true);
|
|
135
|
+
expect(fired).to.equal(1);
|
|
136
|
+
expect(Disposable.is(coll)).to.equal(true);
|
|
137
|
+
expect(Disposable.is({})).to.equal(false);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('DisposableCollection:元素自己 dispose 时从集合里移除,全部移除后触发 onDispose', () => {
|
|
141
|
+
const a = Disposable.create(() => { });
|
|
142
|
+
const coll = new DisposableCollection();
|
|
143
|
+
let fired = 0;
|
|
144
|
+
coll.onDispose(() => fired++);
|
|
145
|
+
coll.pushAll([a]);
|
|
146
|
+
a.dispose();
|
|
147
|
+
expect(coll.disposed).to.equal(true);
|
|
148
|
+
expect(fired).to.equal(1);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe('core utils:取消', () => {
|
|
153
|
+
it('CancellationTokenSource:cancel 前后的状态与事件', () => {
|
|
154
|
+
const source = new CancellationTokenSource();
|
|
155
|
+
const token = source.token;
|
|
156
|
+
let fired = 0;
|
|
157
|
+
token.onCancellationRequested(() => fired++);
|
|
158
|
+
expect(token.isCancellationRequested).to.equal(false);
|
|
159
|
+
source.cancel();
|
|
160
|
+
source.cancel();
|
|
161
|
+
expect(token.isCancellationRequested).to.equal(true);
|
|
162
|
+
expect(fired).to.equal(1);
|
|
163
|
+
expect(() => checkCancelled(token)).to.throw();
|
|
164
|
+
expect(() => checkCancelled(CancellationToken.None)).not.to.throw();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('先 cancel 再取 token 时直接得到已取消的 token;已取消的 token 订阅后异步收到通知', async () => {
|
|
168
|
+
const source = new CancellationTokenSource();
|
|
169
|
+
source.dispose();
|
|
170
|
+
expect(source.token).to.equal(CancellationToken.Cancelled);
|
|
171
|
+
const fired = await new Promise<boolean>(resolve => {
|
|
172
|
+
source.token.onCancellationRequested(() => resolve(true));
|
|
173
|
+
setTimeout(() => resolve(false), 50);
|
|
174
|
+
});
|
|
175
|
+
expect(fired).to.equal(true);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('cancelled() / isCancelled()', () => {
|
|
179
|
+
expect(isCancelled(cancelled())).to.equal(true);
|
|
180
|
+
expect(isCancelled(new Error('other'))).to.equal(false);
|
|
181
|
+
expect(isCancelled(undefined)).to.equal(false);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe('core utils:MimeType', () => {
|
|
186
|
+
it('解析类型、子类型、后缀;通配', () => {
|
|
187
|
+
const json = MimeTypeUtils.parseMimeType('application/vnd.api+json');
|
|
188
|
+
expect(json.getType()).to.equal('application');
|
|
189
|
+
expect(json.getSubtype()).to.equal('vnd.api+json');
|
|
190
|
+
expect(json.getSubtypeSuffix()).to.equal('json');
|
|
191
|
+
expect(MimeTypeUtils.parseMimeType('*').isWildcardType()).to.equal(true);
|
|
192
|
+
expect(MimeTypeUtils.parseMimeType('text/*').isWildcardSubtype()).to.equal(true);
|
|
193
|
+
expect(MimeTypeUtils.parseMimeType('text/plain').isConcrete()).to.equal(true);
|
|
194
|
+
expect(MimeType.valueOf('image/png').equals(MimeTypeUtils.IMAGE_PNG)).to.equal(true);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('includes / isCompatibleWith / isMoreSpecific', () => {
|
|
198
|
+
const all = MimeTypeUtils.ALL;
|
|
199
|
+
const text = MimeTypeUtils.parseMimeType('text/*');
|
|
200
|
+
const html = MimeTypeUtils.TEXT_HTML;
|
|
201
|
+
expect(all.includes(html)).to.equal(true);
|
|
202
|
+
expect(text.includes(html)).to.equal(true);
|
|
203
|
+
expect(html.includes(text)).to.equal(false);
|
|
204
|
+
expect(html.isCompatibleWith(text)).to.equal(true);
|
|
205
|
+
expect(html.isCompatibleWith(MimeTypeUtils.APPLICATION_JSON)).to.equal(false);
|
|
206
|
+
expect(html.isMoreSpecific(text)).to.equal(true);
|
|
207
|
+
expect(html.isPresentIn([MimeTypeUtils.TEXT_PLAIN, MimeTypeUtils.TEXT_HTML])).to.equal(true);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('保留参数:charset 和其他参数都能取到,toString 带上参数(F9)', () => {
|
|
211
|
+
const t = MimeTypeUtils.parseMimeType('text/html; charset=UTF-8; level=1');
|
|
212
|
+
expect(t.getCharset()).to.equal('UTF-8');
|
|
213
|
+
expect(t.getParameter('level')).to.equal('1');
|
|
214
|
+
expect(t.toString()).to.equal('text/html;charset=UTF-8;level=1');
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('非法输入抛 InvalidMimeTypeError', () => {
|
|
218
|
+
expect(() => MimeTypeUtils.parseMimeType('')).to.throw(InvalidMimeTypeError);
|
|
219
|
+
expect(() => MimeTypeUtils.parseMimeType('noslash')).to.throw(InvalidMimeTypeError);
|
|
220
|
+
expect(() => MimeTypeUtils.parseMimeType('text/')).to.throw(InvalidMimeTypeError);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('tokenize 按逗号切分,引号里的逗号不切', () => {
|
|
224
|
+
expect(MimeTypeUtils.tokenize('a/b, c/d;x="1,2"')).to.deep.equal(['a/b', ' c/d;x="1,2"']);
|
|
225
|
+
expect(MimeTypeUtils.tokenize('')).to.deep.equal([]);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('sortBySpecificity:具体的排在前面', () => {
|
|
229
|
+
const list = [MimeTypeUtils.ALL, MimeTypeUtils.parseMimeType('text/*'), MimeTypeUtils.TEXT_HTML];
|
|
230
|
+
MimeTypeUtils.sortBySpecificity(list);
|
|
231
|
+
expect(list.map(String)).to.deep.equal(['text/html', 'text/*', '*/*']);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('parseMimeTypes 按逗号解析多个类型(F8)', () => {
|
|
235
|
+
expect(MimeTypeUtils.parseMimeTypes('text/html, application/json').map(String)).to.deep.equal(['text/html', 'application/json']);
|
|
236
|
+
expect(MimeTypeUtils.parseMimeTypes('')).to.deep.equal([]);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('generateMultipartBoundaryString:30–40 个合法字符', () => {
|
|
240
|
+
const b = MimeTypeUtils.generateMultipartBoundaryString();
|
|
241
|
+
expect(b.length).to.be.within(30, 40);
|
|
242
|
+
expect(b).to.match(/^[-_0-9a-zA-Z]+$/);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
describe('core utils:WaitUntilEvent', () => {
|
|
247
|
+
interface Ev extends WaitUntilEvent { name: string }
|
|
248
|
+
|
|
249
|
+
it('WaitUntilEvent.fire 等待所有 waitUntil 的 Promise;异步调用 waitUntil 报错', async () => {
|
|
250
|
+
const emitter = new Emitter<Ev>();
|
|
251
|
+
const log: string[] = [];
|
|
252
|
+
let late: Ev | undefined;
|
|
253
|
+
emitter.event(e => e.waitUntil(new Promise<void>(r => setTimeout(() => { log.push('slow'); r(); }, 5))));
|
|
254
|
+
emitter.event(e => { late = e; log.push(e.name); });
|
|
255
|
+
await WaitUntilEvent.fire(emitter, { name: 'go' });
|
|
256
|
+
expect(log).to.deep.equal(['go', 'slow']);
|
|
257
|
+
expect(() => late!.waitUntil(Promise.resolve())).to.throw();
|
|
258
|
+
});
|
|
259
|
+
});
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { describe, it } from 'bun:test';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { AttributeScope, Context } from './context';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 请求上下文的约定,与实现无关(以前是 cls-hooked,现在是 AsyncLocalStorage)。
|
|
7
|
+
*
|
|
8
|
+
* cls-hooked 下这些用例有 4 条失败(2026-11-08 在 Node 24.13 和 Bun 1.3.11 上实测):run 里设置的上下文泄漏给
|
|
9
|
+
* await 它的调用方;Node 下外层 await 内层 run 之后看到内层的上下文;Bun 下并发的 run 之间没有隔离(请求之间串上下文);
|
|
10
|
+
* Context.run 没有返回值。换成 AsyncLocalStorage 之后全部通过。同一组场景在 Node 上的结果见
|
|
11
|
+
* cell-refactor/stage0/context-isolation/。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const tick = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms));
|
|
15
|
+
|
|
16
|
+
/** 在 Context.run 里执行 fn,并等它完成。不依赖 run 的返回值,所以同一组用例也能验证以前没有返回值的实现。 */
|
|
17
|
+
function inRun<T>(fn: () => Promise<T>): Promise<T> {
|
|
18
|
+
return new Promise<T>((resolve, reject) => {
|
|
19
|
+
Context.run(async () => {
|
|
20
|
+
try {
|
|
21
|
+
resolve(await fn());
|
|
22
|
+
} catch (error) {
|
|
23
|
+
reject(error);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function named(name: string): Context {
|
|
30
|
+
const ctx = new Context();
|
|
31
|
+
ctx.name = name;
|
|
32
|
+
return ctx;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe('Context', () => {
|
|
36
|
+
it('run 之外没有当前上下文', () => {
|
|
37
|
+
expect(Context.getCurrent()).to.equal(undefined);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('run 里设置的上下文在 await、setTimeout 和 Promise 链之后仍然可见', async () => {
|
|
41
|
+
const ctx = named('a');
|
|
42
|
+
const seen = await inRun(async () => {
|
|
43
|
+
Context.setCurrent(ctx);
|
|
44
|
+
await tick();
|
|
45
|
+
const afterTimer = await new Promise<Context>(resolve => setTimeout(() => resolve(Context.getCurrent()), 1));
|
|
46
|
+
const afterChain = await Promise.resolve()
|
|
47
|
+
.then(() => tick())
|
|
48
|
+
.then(() => Context.getCurrent());
|
|
49
|
+
return [Context.getCurrent(), afterTimer, afterChain];
|
|
50
|
+
});
|
|
51
|
+
expect(seen).to.deep.equal([ctx, ctx, ctx]);
|
|
52
|
+
expect(seen.every(c => c === ctx)).to.equal(true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('run 结束后上下文不会泄漏给 await 它的调用方', async () => {
|
|
56
|
+
await inRun(async () => {
|
|
57
|
+
Context.setCurrent(named('a'));
|
|
58
|
+
});
|
|
59
|
+
expect(Context.getCurrent()).to.equal(undefined);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('嵌套', () => {
|
|
63
|
+
it('内层设置自己的上下文,不影响外层', async () => {
|
|
64
|
+
const outer = named('outer');
|
|
65
|
+
const inner = named('inner');
|
|
66
|
+
const seen = await inRun(async () => {
|
|
67
|
+
Context.setCurrent(outer);
|
|
68
|
+
const inside = await inRun(async () => {
|
|
69
|
+
Context.setCurrent(inner);
|
|
70
|
+
await tick();
|
|
71
|
+
return Context.getCurrent();
|
|
72
|
+
});
|
|
73
|
+
await tick();
|
|
74
|
+
return { inside, after: Context.getCurrent() };
|
|
75
|
+
});
|
|
76
|
+
expect(seen.inside).to.equal(inner);
|
|
77
|
+
expect(seen.after).to.equal(outer);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// 4.x 兼容语义(cls-hooked 一直如此):4.x 不改行为,AsyncLocalStorage 实现以外层的值为原型创建内层的值来保持它;5.0 再评估。
|
|
81
|
+
it('内层在设置自己的上下文之前继承外层的上下文', async () => {
|
|
82
|
+
const outer = named('outer');
|
|
83
|
+
const inherited = await inRun(async () => {
|
|
84
|
+
Context.setCurrent(outer);
|
|
85
|
+
return inRun(async () => Context.getCurrent());
|
|
86
|
+
});
|
|
87
|
+
expect(inherited).to.equal(outer);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('并发的 run 互相隔离', async () => {
|
|
92
|
+
const contexts = Array.from({ length: 50 }, (_, i) => named(`c${i}`));
|
|
93
|
+
const seen = await Promise.all(
|
|
94
|
+
contexts.map((ctx, i) =>
|
|
95
|
+
inRun(async () => {
|
|
96
|
+
Context.setCurrent(ctx);
|
|
97
|
+
await tick(i % 7);
|
|
98
|
+
const first = Context.getCurrent();
|
|
99
|
+
await tick((i * 3) % 5);
|
|
100
|
+
return [first, Context.getCurrent()];
|
|
101
|
+
}),
|
|
102
|
+
),
|
|
103
|
+
);
|
|
104
|
+
seen.forEach(([first, second], i) => {
|
|
105
|
+
expect(first).to.equal(contexts[i]);
|
|
106
|
+
expect(second).to.equal(contexts[i]);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('run 之外 setCurrent 抛错', () => {
|
|
111
|
+
expect(() => Context.setCurrent(new Context())).to.throw('No context available');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('Context.run 的 Promise 以 fn 的返回值 resolve', async () => {
|
|
115
|
+
expect(await Context.run(async () => 42)).to.equal(42);
|
|
116
|
+
expect(await Context.run(() => 'sync')).to.equal('sync');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('bind 的函数在 run 结束后调用,仍然看到绑定时的上下文', async () => {
|
|
120
|
+
const ctx = named('bound');
|
|
121
|
+
const bound = await inRun(async () => {
|
|
122
|
+
Context.setCurrent(ctx);
|
|
123
|
+
return Context.bind(() => Context.getCurrent());
|
|
124
|
+
});
|
|
125
|
+
expect(bound()).to.equal(ctx);
|
|
126
|
+
expect(await new Promise(resolve => setTimeout(() => resolve(bound()), 1))).to.equal(ctx);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('异常', () => {
|
|
130
|
+
it('run 里捕获的异常不影响当前上下文', async () => {
|
|
131
|
+
const ctx = named('a');
|
|
132
|
+
const seen = await inRun(async () => {
|
|
133
|
+
Context.setCurrent(ctx);
|
|
134
|
+
try {
|
|
135
|
+
await tick();
|
|
136
|
+
throw new Error('boom');
|
|
137
|
+
} catch {
|
|
138
|
+
// 被调用方吞掉
|
|
139
|
+
}
|
|
140
|
+
return Context.getCurrent();
|
|
141
|
+
});
|
|
142
|
+
expect(seen).to.equal(ctx);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('内层 run 的异常传到外层,外层上下文不变', async () => {
|
|
146
|
+
const outer = named('outer');
|
|
147
|
+
const boom = new Error('boom');
|
|
148
|
+
const seen = await inRun(async () => {
|
|
149
|
+
Context.setCurrent(outer);
|
|
150
|
+
let caught: unknown;
|
|
151
|
+
try {
|
|
152
|
+
await inRun(async () => {
|
|
153
|
+
Context.setCurrent(named('inner'));
|
|
154
|
+
await tick();
|
|
155
|
+
throw boom;
|
|
156
|
+
});
|
|
157
|
+
} catch (error) {
|
|
158
|
+
caught = error;
|
|
159
|
+
}
|
|
160
|
+
return { caught, after: Context.getCurrent() };
|
|
161
|
+
});
|
|
162
|
+
expect(seen.caught).to.equal(boom);
|
|
163
|
+
expect(seen.after).to.equal(outer);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('Context.run 返回 Promise,fn 的异常让它 reject', async () => {
|
|
167
|
+
const boom = new Error('boom');
|
|
168
|
+
const result = Context.run(async () => {
|
|
169
|
+
throw boom;
|
|
170
|
+
}) as unknown;
|
|
171
|
+
expect(result).to.be.instanceOf(Promise);
|
|
172
|
+
let caught: unknown;
|
|
173
|
+
await (result as Promise<void>).catch(error => {
|
|
174
|
+
caught = error;
|
|
175
|
+
});
|
|
176
|
+
expect(caught).to.equal(boom);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe('属性', () => {
|
|
181
|
+
it('Request 作用域的属性只在本次 run 里可见,App 作用域跨 run 可见', async () => {
|
|
182
|
+
const key = `attr-${Date.now()}`;
|
|
183
|
+
await inRun(async () => {
|
|
184
|
+
Context.setCurrent(new Context());
|
|
185
|
+
Context.setAttr(key, 'request');
|
|
186
|
+
Context.setAttr(`${key}-app`, 'app', AttributeScope.App);
|
|
187
|
+
expect(Context.getAttr(key, AttributeScope.Request)).to.equal('request');
|
|
188
|
+
});
|
|
189
|
+
const other = await inRun(async () => {
|
|
190
|
+
Context.setCurrent(new Context());
|
|
191
|
+
return [Context.getAttr(key, AttributeScope.Request), Context.getAttr(`${key}-app`, AttributeScope.App)];
|
|
192
|
+
});
|
|
193
|
+
expect(other).to.deep.equal([undefined, 'app']);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('不指定作用域时先找 Request,再找 App', async () => {
|
|
197
|
+
const key = `fallback-${Date.now()}`;
|
|
198
|
+
Context.setAttr(key, 'app', AttributeScope.App);
|
|
199
|
+
const seen = await inRun(async () => {
|
|
200
|
+
Context.setCurrent(new Context());
|
|
201
|
+
const before = Context.getAttr(key);
|
|
202
|
+
Context.setAttr(key, 'request');
|
|
203
|
+
return [before, Context.getAttr(key)];
|
|
204
|
+
});
|
|
205
|
+
expect(seen).to.deep.equal(['app', 'request']);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('AttributeScope.App 只读 App 作用域(App 的枚举值是 0,不能当成“不指定”)', async () => {
|
|
209
|
+
const key = `app-only-${Date.now()}`;
|
|
210
|
+
Context.setAttr(key, 'app', AttributeScope.App);
|
|
211
|
+
const seen = await inRun(async () => {
|
|
212
|
+
Context.setCurrent(new Context());
|
|
213
|
+
Context.setAttr(key, 'request');
|
|
214
|
+
return [Context.getAttr(key, AttributeScope.App), Context.getAttr(key, AttributeScope.Request)];
|
|
215
|
+
});
|
|
216
|
+
expect(seen).to.deep.equal(['app', 'request']);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
});
|