File size: 2,701 Bytes
f0634fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { beforeEach, describe, expect, it } from 'vitest';

import { ScopeActivation } from '#/_base/di/instantiation';
import {
  _clearScopedRegistryForTests,
  getScopedServiceDescriptors,
  registerScopedService,
} from '#/_base/di/scope';
import { createScopedTestHost } from '#/_base/di/test';
import { IFeatureManager } from '#/app/feature/featureManager';
import { FeatureManagerService } from '#/app/feature/featureManagerService';
import { LifecycleScope } from '#/app/scopes';
import { IFeatureAssemblyService } from '#/features/featureAssembly';
import { FeatureAssemblyService } from '#/features/featureAssemblyService';
import {
  _clearFeatureRecipesForTests,
  registerFeature,
} from '#/features/featureRegistry';

import { IDebugEventsService } from '#/features/debugEvents/debugEvents';
import { DebugEventsFeature } from '#/features/debugEvents/debugEventsFeature';

describe('DebugEventsFeature — App-scope introspection service', () => {
  beforeEach(() => {
    _clearScopedRegistryForTests();
    _clearFeatureRecipesForTests();
    registerScopedService(
      LifecycleScope.App,
      IFeatureManager,
      FeatureManagerService,
      ScopeActivation.OnScopeCreated,
      'feature',
    );
    registerScopedService(
      LifecycleScope.App,
      IFeatureAssemblyService,
      FeatureAssemblyService,
      ScopeActivation.OnScopeCreated,
      'features',
    );
    registerFeature(DebugEventsFeature);
  });

  it('contributes IDebugEventsService at App scope outside the static scoped registry', async () => {
    expect(
      getScopedServiceDescriptors(LifecycleScope.App).some(
        (entry) => entry.id.toString() === 'debugEventsService',
      ),
    ).toBe(false);

    const host = createScopedTestHost();
    const manager = host.app.accessor.get(IFeatureManager);
    expect(manager.units().map((unit) => unit.name)).toContain('debugEvents');
    expect(
      manager
        .contributedServices()
        .some((entry) => entry.scope === LifecycleScope.App && entry.id === IDebugEventsService),
    ).toBe(true);

    const result = host.app.accessor.get(IDebugEventsService).subscriptions();
    expect(result).toMatchObject({
      subscriptions: expect.any(Array),
      buses: expect.any(Array),
    });

    await manager.unprovideUnit('debugEvents');
    await host.app.instantiation.cascade.whenIdle();
    await new Promise((resolve) => setTimeout(resolve, 0));
    expect(() => host.app.accessor.get(IDebugEventsService)).toThrow();
    expect(
      manager
        .contributedServices()
        .some((entry) => entry.scope === LifecycleScope.App && entry.id === IDebugEventsService),
    ).toBe(false);
    host.dispose();
  });
});