Skip to content

Commit

Permalink
Properly coordinate test startup process
Browse files Browse the repository at this point in the history
Add items to vscodeignore
  • Loading branch information
appilon committed Sep 3, 2020
1 parent c4826df commit c363cd7
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 30 deletions.
7 changes: 6 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
.github
.vscode
.vscode-test
.gitignore
.hashibot.hcl
src/
out/*.test.*
out/test/
.eslintignore
.eslintrc.js
tsconfig.json
lsp/
lsp/
testfixture/
7 changes: 5 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { runCommand } from './terraformCommand';
const clients: Map<string, LanguageClient> = new Map();
let extensionPath: string;

export async function activate(context: vscode.ExtensionContext): Promise<void> {
export async function activate(context: vscode.ExtensionContext): Promise<any> {
extensionPath = context.extensionPath;
const commandOutput = vscode.window.createOutputChannel('Terraform');
// get rid of pre-2.0.0 settings
Expand Down Expand Up @@ -81,8 +81,11 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
);

if (enabled()) {
return vscode.commands.executeCommand('terraform.enableLanguageServer');
await vscode.commands.executeCommand('terraform.enableLanguageServer');
}

// export public API
return { pathToBinary };
}

export function deactivate(): Promise<void[]> {
Expand Down
32 changes: 26 additions & 6 deletions src/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ export let editor: vscode.TextEditor;
export let documentEol: string;
export let platformEol: string;

export async function activate(docUri: vscode.Uri): Promise<void> {
// The extensionId is `publisher.name` from package.json
const ext = vscode.extensions.getExtension('hashicorp.terraform');
await ext.activate();
// allow server to initialize
await sleep(5000);
export async function open(docUri: vscode.Uri): Promise<void> {
try {
await activated();
doc = await vscode.workspace.openTextDocument(docUri);
editor = await vscode.window.showTextDocument(doc);
} catch (e) {
Expand All @@ -21,6 +17,30 @@ export async function activate(docUri: vscode.Uri): Promise<void> {
}
}

let _activatedPromise: Promise<void>
async function activated() {
if (!_activatedPromise) {
try {
// The extensionId is `publisher.name` from package.json
const ext = vscode.extensions.getExtension('hashicorp.terraform');
if (!ext.isActive) {
console.log('Activating hashicorp.terraform extension');
await ext.activate();
} else {
console.log('hashicorp.terraform is already active');
}
// make sure language server download is complete
await ext.exports.pathToBinary();
// TODO: implement proper synchronization/status check in LS
// give server(s) some time to startup
_activatedPromise = sleep(3000);
} catch (err) {
_activatedPromise = Promise.reject(err);
}
}
return _activatedPromise;
}

export async function sleep(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import * as path from 'path';
import * as Mocha from 'mocha';
import * as glob from 'glob';

export function run(): Promise<void> {
export async function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
color: true
});
// integration tests require long activation time
mocha.timeout(100000);

const testsRoot = path.resolve(__dirname, '..');
Expand Down
21 changes: 19 additions & 2 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
import * as path from 'path';
import { runTests } from 'vscode-test';
import * as del from 'del';
import { exec } from '../utils';

async function terraformInit() {
const cwd = process.cwd();
process.chdir('testFixture');
const { stdout } = await exec('terraform init -no-color');
console.log(stdout);
process.chdir(cwd);
}

async function main(): Promise<void> {
try {
// initialize terraform before vscode opens
await terraformInit();
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
// this is also the process working dir, even if vscode opens another folder
const extensionDevelopmentPath = path.resolve(__dirname, '../../');

// The path to the extension test runner script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './index');

// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
// start in the fixtures folder to prevent the language server from walking all the
// project root folders, like node_modules
await runTests({ extensionDevelopmentPath, extensionTestsPath, launchArgs: ['testFixture'] });
} catch (err) {
console.error(err);
console.error('Failed to run tests');
process.exit(1);
process.exitCode = 1;
} finally {
await del('testFixture/.terraform', { force: true });
}
}

Expand Down
16 changes: 0 additions & 16 deletions src/test/setup.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/test/symbols.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import * as assert from 'assert';
import { getDocUri, activate } from './helper';
import { getDocUri, open } from './helper';

suite('document symbols', () => {
const docUri = getDocUri('sample.tf');
Expand All @@ -11,7 +11,7 @@ suite('document symbols', () => {
});

async function testSymbols(docUri: vscode.Uri, symbolNames: string[]) {
await activate(docUri);
await open(docUri);
// Executing the command `vscode.executeDocumentSymbolProvider` to simulate triggering completion
const symbols = (await vscode.commands.executeCommand('vscode.executeDocumentSymbolProvider', docUri)) as vscode.SymbolInformation[];

Expand Down

0 comments on commit c363cd7

Please sign in to comment.