Skip to content

Commit

Permalink
Enable CodeAction tests (#844)
Browse files Browse the repository at this point in the history
Enable the CodeAction tests that were commented out until the changes in hashicorp/terraform-ls#680 was released.
  • Loading branch information
jpogran authored Nov 10, 2021
1 parent eef3e59 commit 295f119
Showing 1 changed file with 45 additions and 47 deletions.
92 changes: 45 additions & 47 deletions src/test/integration/codeAction.test.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
// import * as vscode from 'vscode';
// import * as assert from 'assert';
// import { expect } from 'chai';
// import { getDocUri, open } from '../helper';
// import { config } from '../../vscodeUtils';

// Enable when https://github.com/hashicorp/terraform-ls/pull/680 is merged
// suite('code actions', () => {
// teardown(async () => {
// await vscode.commands.executeCommand('workbench.action.closeAllEditors');
// });

// test('supported actions', async () => {
// await vscode.workspace
// .getConfiguration('terraform')
// .update('languageServer', { external: true }, vscode.ConfigurationTarget.Workspace);
// await vscode.workspace
// .getConfiguration('editor')
// .update('codeActionsOnSave', { "source.formatAll.terraform": true }, vscode.ConfigurationTarget.Workspace);

// const docUri = getDocUri('actions.tf');
// await open(docUri);

// const supported = [
// new vscode.CodeAction('Format Document', vscode.CodeActionKind.Source.append('formatAll').append('terraform')),
// ];

// for (let index = 0; index < supported.length; index++) {
// const wanted = supported[index];
// const requested = wanted.kind.value.toString();

// const actions: vscode.CodeAction[] = await vscode.commands.executeCommand<vscode.CodeAction[]>(
// 'vscode.executeCodeActionProvider',
// docUri,
// new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)),
// requested,
// );

// assert.ok(actions);
// expect(actions).not.to.be.undefined;

// assert.strictEqual(actions.length, 1);
// assert.strictEqual(actions[0].title, wanted.title);
// assert.strictEqual(actions[0].kind.value, wanted.kind.value);
// }
// });
// });
import * as vscode from 'vscode';
import * as assert from 'assert';
import { expect } from 'chai';
import { getDocUri, open } from '../helper';

suite('code actions', () => {
teardown(async () => {
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
});

test('supported actions', async () => {
await vscode.workspace
.getConfiguration('terraform')
.update('languageServer', { external: true }, vscode.ConfigurationTarget.Workspace);
await vscode.workspace
.getConfiguration('editor')
.update('codeActionsOnSave', { "source.formatAll.terraform": true }, vscode.ConfigurationTarget.Workspace);

const docUri = getDocUri('actions.tf');
await open(docUri);

const supported = [
new vscode.CodeAction('Format Document', vscode.CodeActionKind.Source.append('formatAll').append('terraform')),
];

for (let index = 0; index < supported.length; index++) {
const wanted = supported[index];
const requested = wanted.kind.value.toString();

const actions: vscode.CodeAction[] = await vscode.commands.executeCommand<vscode.CodeAction[]>(
'vscode.executeCodeActionProvider',
docUri,
new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)),
requested,
);

assert.ok(actions);
expect(actions).not.to.be.undefined;

assert.strictEqual(actions.length, 1);
assert.strictEqual(actions[0].title, wanted.title);
assert.strictEqual(actions[0].kind.value, wanted.kind.value);
}
});
});

0 comments on commit 295f119

Please sign in to comment.