Skip to content

Commit 2ecc3c5

Browse files
author
colin-grant-work
authored
Reenable Typescript codelens test (#11141)
1 parent f249b3e commit 2ecc3c5

File tree

2 files changed

+27
-39
lines changed

2 files changed

+27
-39
lines changed

examples/api-tests/src/typescript.spec.js

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -576,64 +576,46 @@ DIV {
576576
assert.equal(activeEditor.getControl().getModel().getWordAtPosition({ lineNumber, column }).word, 'DemoClass');
577577
});
578578

579-
// TODO: FIXME! As of 28/01/2022 this test is failing or timing out for unknown reasons.
580-
it.skip('run reference code lens', async function () {
581-
this.timeout(300_000); // 5 min (give time to `tsserver` to initialize and then respond to make this test pass.)
582-
const globalValue = preferences.inspect('javascript.referencesCodeLens.enabled').globalValue;
583-
toTearDown.push({ dispose: () => preferences.set('javascript.referencesCodeLens.enabled', globalValue, PreferenceScope.User) });
579+
it('run reference code lens', async function () {
580+
const preferenceName = 'typescript.referencesCodeLens.enabled';
581+
const globalValue = preferences.inspect(preferenceName).globalValue;
582+
toTearDown.push({ dispose: () => preferences.set(preferenceName, globalValue, PreferenceScope.User) });
583+
await preferences.set(preferenceName, false, PreferenceScope.User);
584584

585585
const editor = await openEditor(demoFileUri);
586586

587-
/** @type any */
587+
/** @type {import('@theia/monaco-editor-core/src/vs/editor/contrib/codelens/browser/codelensController').CodeLensContribution} */
588588
const codeLens = editor.getControl().getContribution('css.editor.codeLens');
589-
const codeLensNode = () => codeLens._lenses[0] && codeLens._lenses[0]._contentWidget && codeLens._lenses[0]._contentWidget._domNode;
589+
const codeLensNode = () => codeLens['_lenses'][0]?.['_contentWidget']?.['_domNode'];
590590
const codeLensNodeVisible = () => {
591591
const n = codeLensNode();
592592
return !!n && n.style.visibility !== 'hidden';
593593
};
594594

595595
assert.isFalse(codeLensNodeVisible());
596596

597-
// [export ]function load(raw) {
598-
const position = { lineNumber: 16, column: 1 };
599-
editor.getControl().getModel().applyEdits([{
600-
range: Range.fromPositions(position, position),
601-
forceMoveMarkers: false,
602-
text: 'export '
603-
}]);
604-
await preferences.set('javascript.referencesCodeLens.enabled', true, PreferenceScope.User);
605-
606-
// Recall `applyEdits` to workaround `vscode` bug, See: https://github.com/eclipse-theia/theia/issues/9714#issuecomment-876582947.
607-
editor.getControl().getModel().applyEdits([{
608-
range: Range.fromPositions(position, position),
609-
forceMoveMarkers: false,
610-
text: ' '
611-
}]);
597+
// |interface DemoInterface {
598+
const position = { lineNumber: 2, column: 1 };
599+
await preferences.set(preferenceName, true, PreferenceScope.User);
612600

613601
editor.getControl().revealPosition(position);
614602
await waitForAnimation(() => codeLensNodeVisible());
615603

616604
assert.isTrue(codeLensNodeVisible());
617605
const node = codeLensNode();
618-
if (node) {
619-
assert.equal(nodeAsString(node), `
606+
assert.isDefined(node);
607+
assert.equal(nodeAsString(node), `
620608
SPAN {
621609
A {
622-
"20 references"
610+
"1 reference"
623611
}
624612
}
625613
`);
626-
const link = node.getElementsByTagName('a').item(0);
627-
if (link) {
628-
link.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
629-
await assertPeekOpened(editor);
630-
await closePeek(editor);
631-
} else {
632-
assert.isDefined(link);
633-
}
634-
} else {
635-
assert.isDefined(node);
636-
}
614+
const link = node.getElementsByTagName('a').item(0);
615+
assert.isDefined(link);
616+
link.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
617+
await assertPeekOpened(editor);
618+
await closePeek(editor);
637619
});
638620

639621
it('editor.action.quickFix', async function () {

examples/api-tests/src/undo-redo-selectAll.spec.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('Undo, Redo and Select All', function () {
3232
const { MonacoEditor } = require('@theia/monaco/lib/browser/monaco-editor');
3333
const { ScmContribution } = require('@theia/scm/lib/browser/scm-contribution');
3434
const { Range } = require('@theia/monaco-editor-core/esm/vs/editor/common/core/range');
35+
const { PreferenceService, PreferenceScope } = require('@theia/core/lib/browser');
3536

3637
const container = window.theia.container;
3738
const editorManager = container.get(EditorManager);
@@ -41,6 +42,8 @@ describe('Undo, Redo and Select All', function () {
4142
const navigatorContribution = container.get(FileNavigatorContribution);
4243
const shell = container.get(ApplicationShell);
4344
const scmContribution = container.get(ScmContribution);
45+
/** @type {PreferenceService} */
46+
const preferenceService = container.get(PreferenceService)
4447

4548
const rootUri = workspaceService.tryGetRoots()[0].resource;
4649
const fileUri = rootUri.resolve('webpack.config.js');
@@ -61,8 +64,10 @@ describe('Undo, Redo and Select All', function () {
6164
resolve(undefined);
6265
});
6366
}
64-
65-
before(() => {
67+
let originalValue = undefined;
68+
before(async () => {
69+
originalValue = preferenceService.inspect('files.autoSave').globalValue;
70+
await preferenceService.set('files.autoSave', false, PreferenceScope.User);
6671
shell.leftPanelHandler.collapse();
6772
});
6873

@@ -79,7 +84,8 @@ describe('Undo, Redo and Select All', function () {
7984
await editorManager.closeAll({ save: false });
8085
});
8186

82-
after(() => {
87+
after(async () => {
88+
await preferenceService.set('files.autoSave', originalValue, PreferenceScope.User);
8389
shell.leftPanelHandler.collapse();
8490
});
8591

0 commit comments

Comments
 (0)