Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 057a767

Browse files
committed
Simplify tests; add skipped visualize test
1 parent d5c3142 commit 057a767

File tree

4 files changed

+28
-48
lines changed

4 files changed

+28
-48
lines changed

package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@
4141
"command": "syntaxTree.restart",
4242
"title": "Syntax Tree: Restart"
4343
},
44-
{
45-
"command": "syntaxTree.clearOutputChannel",
46-
"title": "Syntax Tree: Clear Output Channel"
47-
},
4844
{
4945
"command": "syntaxTree.showOutputChannel",
5046
"title": "Syntax Tree: Show Output Channel"

src/extension.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import Visualize from "./Visualize";
1010
const promiseExec = promisify(exec);
1111

1212
// This object will get initialized once the language client is ready. It will
13-
// get set back to null when the extension is deactivated.
14-
let languageClient: LanguageClient | null = null;
13+
// get set back to null when the extension is deactivated. It is exported for
14+
// easier testing.
15+
export let languageClient: LanguageClient | null = null;
1516

1617
// This is the expected top-level export that is called by VSCode when the
1718
// extension is activated.
@@ -39,7 +40,6 @@ export async function activate(context: ExtensionContext) {
3940
commands.registerCommand("syntaxTree.stop", stopLanguageServer),
4041
commands.registerCommand("syntaxTree.restart", restartLanguageServer),
4142
commands.registerCommand("syntaxTree.visualize", () => visualizer?.visualize()),
42-
commands.registerCommand("syntaxTree.clearOutputChannel", () => outputChannel.clear()),
4343
commands.registerCommand("syntaxTree.showOutputChannel", () => outputChannel.show()),
4444
workspace.onDidChangeConfiguration(event => {
4545
if (event.affectsConfiguration("syntaxTree")) {

src/test/suite/automation.ts

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,12 @@ import * as assert from 'assert';
22
import * as path from 'path';
33
import { TextEncoder } from 'util';
44

5-
import { Range, Uri, commands, window, workspace } from 'vscode';
5+
import { Uri, commands, window, workspace } from 'vscode';
66

77
import { WORKSPACE_DIR } from './setup';
88

99
export async function reset() {
1010
await commands.executeCommand('workbench.action.closeAllEditors');
11-
await clearOutputChannel();
12-
13-
// Ensure output panel is closed
14-
await commands.executeCommand('workbench.panel.output.focus');
15-
await commands.executeCommand('workbench.action.output.toggleOutput');
16-
17-
// Ensure something neutral is focused
18-
await commands.executeCommand('workbench.explorer.fileView.focus');
1911
}
2012

2113
export async function createEditor(content: string, filename = 'test.rb') {
@@ -27,6 +19,10 @@ export async function createEditor(content: string, filename = 'test.rb') {
2719
return window.activeTextEditor;
2820
}
2921

22+
export function findNewestEditor() {
23+
return window.visibleTextEditors[window.visibleTextEditors.length - 1];
24+
}
25+
3026
export function formatDocument() {
3127
return commands.executeCommand('editor.action.formatDocument', 'ruby-syntax-tree.vscode-syntax-tree');
3228
}
@@ -35,30 +31,14 @@ export function restart() {
3531
return commands.executeCommand('syntaxTree.restart');
3632
}
3733

38-
export function clearOutputChannel() {
39-
return commands.executeCommand('syntaxTree.showOutputChannel');
40-
}
41-
42-
export function showOutputChannel(timeout = 15000) {
43-
// TODO: make use of await commands.executeCommand('workbench.panel.output.focus'); ??
44-
return new Promise<string>((c, e) => {
45-
const failSauce = new Error(`No active editor change within ${timeout}ms`)
46-
const timer = setTimeout(() => e(failSauce), timeout);
47-
const disposable = window.onDidChangeActiveTextEditor(e => {
48-
if (e) {
49-
clearTimeout(timer);
50-
disposable.dispose();
51-
c(e.document.getText())
52-
}
53-
})
54-
commands.executeCommand('syntaxTree.showOutputChannel');
55-
})
56-
}
57-
5834
export function start() {
5935
return commands.executeCommand('syntaxTree.start');
6036
}
6137

6238
export function stop() {
6339
return commands.executeCommand('syntaxTree.stop');
6440
}
41+
42+
export function visualize() {
43+
return commands.executeCommand('syntaxTree.visualize');
44+
}

src/test/suite/index.test.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as assert from 'assert';
22
import { before, beforeEach } from 'mocha';
3+
import { State } from 'vscode-languageclient';
34

45
import * as auto from './automation';
5-
6-
// can directly import extension if needed
7-
// import * as myExtension from '../../extension';
6+
import * as extension from '../../extension';
87

98
const UNFORMATTED = `class Foo; def bar; puts 'baz'; end; end`;
109

@@ -21,33 +20,38 @@ suite('Syntax Tree', () => {
2120
suite('lifecycle commands', () => {
2221
test('start', async () => {
2322
await auto.start();
24-
const text = await auto.showOutputChannel();
25-
assert.match(text, /^Starting language server/);
23+
assert.notEqual(extension.languageClient, null)
24+
assert.equal(extension.languageClient?.state, State.Running)
2625
});
2726

2827
test('stop', async () => {
2928
await auto.start();
3029
await auto.stop();
31-
const text = await auto.showOutputChannel();
32-
assert.match(text, /^Stopping language server/m);
30+
assert.equal(extension.languageClient, null)
3331
})
3432

3533
test('restart', async () => {
3634
await auto.restart();
37-
const text = await auto.showOutputChannel();
38-
assert.match(text, /^Restarting language server/m);
39-
assert.match(text, /^Stopping language server/m);
40-
assert.match(text, /^Starting language server/);
35+
assert.notEqual(extension.languageClient, null)
36+
assert.equal(extension.languageClient?.state, State.Running)
4137
})
4238
});
4339

4440
suite('functional commands', () => {
4541
before(auto.start);
4642

47-
test('Format Document', async () => {
43+
test('format', async () => {
4844
const editor = await auto.createEditor(UNFORMATTED);
4945
await auto.formatDocument();
5046
assert.equal(editor.document.getText(), FORMATTED);
5147
});
48+
49+
// TODO: why does this test fail w/ assertions from prior test?!?!
50+
test.skip('visualize', async () => {
51+
await auto.createEditor(UNFORMATTED);
52+
await auto.visualize();
53+
const editor = auto.findNewestEditor();
54+
assert.match(editor.document.getText(), /^\(program/);
55+
})
5256
})
5357
});

0 commit comments

Comments
 (0)