From 39885f6f16c3a259da209f2f02ce43bfd95ddb28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rokas=20Brazd=C5=BEionis?= Date: Sun, 12 Mar 2017 23:51:42 +0200 Subject: [PATCH] Fix unit tests --- test/helpers.ts | 10 --------- .../angular-html-definition-provider.test.ts | 22 ++++++++----------- .../angular-ts-definition-provider.test.ts | 17 ++++++-------- 3 files changed, 16 insertions(+), 33 deletions(-) diff --git a/test/helpers.ts b/test/helpers.ts index 95ec759..876c22a 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -10,13 +10,3 @@ export async function openFileInVscode(filePath: string) { export function workspaceFilePath(filePath: string) { return path.join(vscode.workspace.rootPath, filePath); } - -export function catchAsync(suite: (done: MochaDone) => any) { - return async (done) => { - try { - await suite(done); - } catch (e) { - done(e); - } - } -} diff --git a/test/providers/angular-html-definition-provider.test.ts b/test/providers/angular-html-definition-provider.test.ts index 1182f9d..414a1e0 100644 --- a/test/providers/angular-html-definition-provider.test.ts +++ b/test/providers/angular-html-definition-provider.test.ts @@ -1,17 +1,16 @@ import * as assert from 'assert'; import * as vscode from 'vscode'; import * as path from 'path'; -import { openFileInVscode, workspaceFilePath, catchAsync } from '../helpers'; +import { openFileInVscode, workspaceFilePath } from '../helpers'; suite('AngularHtmlDefinitionProvider', () => { const templateFilePath = workspaceFilePath('foo.component.html'); - suiteSetup(catchAsync(async (done) => { + suiteSetup(async () => { await openFileInVscode(templateFilePath); - done(); - })); + }); - test('should resolve interpolation', catchAsync(async (done) => { + test('should resolve interpolation', async () => { const result = await vscode.commands.executeCommand('vscode.executeDefinitionProvider', vscode.Uri.file(templateFilePath), new vscode.Position(1, 8)); @@ -19,10 +18,9 @@ suite('AngularHtmlDefinitionProvider', () => { assert.equal(result[0].uri.fsPath, workspaceFilePath('foo.component.ts'), 'wrong file resolution'); assert.equal(result[0].range.start.line, 6, 'wrong line position'); assert.equal(result[0].range.start.character, 7, 'wrong character position'); - done(); - })); + }); - test('should resolve one way binded input', catchAsync(async (done) => { + test('should resolve one way binded input', async () => { const result = await vscode.commands.executeCommand('vscode.executeDefinitionProvider', vscode.Uri.file(templateFilePath), new vscode.Position(2, 40)); @@ -30,10 +28,9 @@ suite('AngularHtmlDefinitionProvider', () => { assert.equal(result[0].uri.fsPath, workspaceFilePath('foo.component.ts'), 'wrong file resolution'); assert.equal(result[0].range.start.line, 7, 'wrong line position'); assert.equal(result[0].range.start.character, 10, 'wrong character position'); - done(); - })); + }); - test('should resolve two way binded input', catchAsync(async (done) => { + test('should resolve two way binded input', async () => { const result = await vscode.commands.executeCommand('vscode.executeDefinitionProvider', vscode.Uri.file(templateFilePath), new vscode.Position(2, 62)); @@ -41,6 +38,5 @@ suite('AngularHtmlDefinitionProvider', () => { assert.equal(result[0].uri.fsPath, workspaceFilePath('foo.component.ts'), 'wrong file resolution'); assert.equal(result[0].range.start.line, 8, 'wrong line position'); assert.equal(result[0].range.start.character, 7, 'wrong character position'); - done(); - })); + }); }); diff --git a/test/providers/angular-ts-definition-provider.test.ts b/test/providers/angular-ts-definition-provider.test.ts index faf97f4..5e410c0 100644 --- a/test/providers/angular-ts-definition-provider.test.ts +++ b/test/providers/angular-ts-definition-provider.test.ts @@ -1,17 +1,16 @@ import * as assert from 'assert'; import * as vscode from 'vscode'; import * as path from 'path'; -import { openFileInVscode, workspaceFilePath, catchAsync } from '../helpers'; +import { openFileInVscode, workspaceFilePath } from '../helpers'; suite('AngularTsDefinitionProvider', () => { const componentFilePath = workspaceFilePath('foo.component.ts'); - suiteSetup(catchAsync(async (done) => { + suiteSetup(async () => { await openFileInVscode(componentFilePath); - done(); - })); + }); - test('should go to templateUrl declaration', catchAsync(async (done) => { + test('should go to templateUrl declaration', async () => { const result = await vscode.commands.executeCommand('vscode.executeDefinitionProvider', vscode.Uri.file(componentFilePath), new vscode.Position(2, 22)); @@ -19,10 +18,9 @@ suite('AngularTsDefinitionProvider', () => { assert.equal(result[0].uri.fsPath, workspaceFilePath('foo.component.html'), 'wrong file resolution'); assert.equal(result[0].range.start.line, 0, 'wrong line position'); assert.equal(result[0].range.start.character, 0, 'wrong character position'); - done(); - })); + }); - test('should go to styleUrls declaration', catchAsync(async (done) => { + test('should go to styleUrls declaration', async () => { const result = await vscode.commands.executeCommand('vscode.executeDefinitionProvider', vscode.Uri.file(componentFilePath), new vscode.Position(3, 22)); @@ -30,6 +28,5 @@ suite('AngularTsDefinitionProvider', () => { assert.equal(result[0].uri.fsPath, workspaceFilePath('foo.component.css'), 'wrong file resolution'); assert.equal(result[0].range.start.line, 0, 'wrong line position'); assert.equal(result[0].range.start.character, 0, 'wrong character position'); - done(); - })); + }); });