Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dzonatan committed Mar 12, 2017
1 parent a510c49 commit 39885f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 33 deletions.
10 changes: 0 additions & 10 deletions test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
22 changes: 9 additions & 13 deletions test/providers/angular-html-definition-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
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.Location[]>('vscode.executeDefinitionProvider',
vscode.Uri.file(templateFilePath), new vscode.Position(1, 8));

assert.notEqual(result[0], undefined, 'file did not resolve');
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.Location[]>('vscode.executeDefinitionProvider',
vscode.Uri.file(templateFilePath), new vscode.Position(2, 40));

assert.notEqual(result[0], undefined, 'file did not resolve');
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.Location[]>('vscode.executeDefinitionProvider',
vscode.Uri.file(templateFilePath), new vscode.Position(2, 62));

assert.notEqual(result[0], undefined, 'file did not resolve');
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();
}));
});
});
17 changes: 7 additions & 10 deletions test/providers/angular-ts-definition-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
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.Location[]>('vscode.executeDefinitionProvider',
vscode.Uri.file(componentFilePath), new vscode.Position(2, 22));

assert.notEqual(result[0], undefined, 'file did not resolve');
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.Location[]>('vscode.executeDefinitionProvider',
vscode.Uri.file(componentFilePath), new vscode.Position(3, 22));

assert.notEqual(result[0], undefined, 'file did not resolve');
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();
}));
});
});

0 comments on commit 39885f6

Please sign in to comment.