Skip to content

Commit 335ad54

Browse files
authored
fix menubar test leak (microsoft#251639)
1 parent 3a2ee21 commit 335ad54

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/vs/base/browser/dom.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,7 @@ export class ModifierKeyEmitter extends event.Emitter<IModifierKeyStatus> {
18331833

18341834
private readonly _subscriptions = new DisposableStore();
18351835
private _keyStatus: IModifierKeyStatus;
1836-
private static instance: ModifierKeyEmitter;
1836+
private static instance: ModifierKeyEmitter | undefined;
18371837

18381838
private constructor() {
18391839
super();
@@ -1970,6 +1970,13 @@ export class ModifierKeyEmitter extends event.Emitter<IModifierKeyStatus> {
19701970
return ModifierKeyEmitter.instance;
19711971
}
19721972

1973+
static disposeInstance() {
1974+
if (ModifierKeyEmitter.instance) {
1975+
ModifierKeyEmitter.instance.dispose();
1976+
ModifierKeyEmitter.instance = undefined;
1977+
}
1978+
}
1979+
19731980
override dispose() {
19741981
super.dispose();
19751982
this._subscriptions.dispose();

src/vs/base/test/browser/ui/menu/menubar.test.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import assert from 'assert';
7-
import { $ } from '../../../../browser/dom.js';
7+
import { $, ModifierKeyEmitter } from '../../../../browser/dom.js';
88
import { unthemedMenuStyles } from '../../../../browser/ui/menu/menu.js';
99
import { MenuBar } from '../../../../browser/ui/menu/menubar.js';
1010
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../common/utils.js';
@@ -65,20 +65,33 @@ suite('Menubar', () => {
6565
ensureNoDisposablesAreLeakedInTestSuite();
6666
const container = $('.container');
6767

68-
const menubar = new MenuBar(container, {
69-
enableMnemonics: true,
70-
visibility: 'visible'
71-
}, unthemedMenuStyles);
68+
const withMenuMenubar = (callback: (menubar: MenuBar) => void) => {
69+
const menubar = new MenuBar(container, {
70+
enableMnemonics: true,
71+
visibility: 'visible'
72+
}, unthemedMenuStyles);
73+
74+
callback(menubar);
75+
76+
menubar.dispose();
77+
ModifierKeyEmitter.disposeInstance();
78+
};
7279

7380
test('English File menu renders mnemonics', function () {
74-
validateMenuBarItem(menubar, container, '&File', 'File', 'F');
81+
withMenuMenubar(menubar => {
82+
validateMenuBarItem(menubar, container, '&File', 'File', 'F');
83+
});
7584
});
7685

7786
test('Russian File menu renders mnemonics', function () {
78-
validateMenuBarItem(menubar, container, '&Файл', 'Файл', 'Ф');
87+
withMenuMenubar(menubar => {
88+
validateMenuBarItem(menubar, container, '&Файл', 'Файл', 'Ф');
89+
});
7990
});
8091

8192
test('Chinese File menu renders mnemonics', function () {
82-
validateMenuBarItem(menubar, container, '文件(&F)', '文件', 'F');
93+
withMenuMenubar(menubar => {
94+
validateMenuBarItem(menubar, container, '文件(&F)', '文件', 'F');
95+
});
8396
});
8497
});

0 commit comments

Comments
 (0)