Skip to content

Commit 0087dd7

Browse files
ayazhafizKeen Yee Liau
authored andcommitted
test: add test and fix clang-format formatted files
Adds automated Travis CI test to ensure TypeScript files are formatted with `clang-format`. If any files are unformatted, and error message stating "Files not formatted; please run 'yarn format'" is given. Also formats existing files to pass this new test. PR Closes #373
1 parent acc2a70 commit 0087dd7

File tree

15 files changed

+500
-888
lines changed

15 files changed

+500
-888
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ script:
1616
- ./scripts/lint.sh
1717
- ./scripts/build.sh
1818
- ./scripts/test.sh
19+
- ./scripts/format.sh && git diff --diff-filter=ACMRT --exit-code || (echo "Files not formatted; please run 'yarn format'." && exit 1)
1920

2021
after_script:
2122
- ./scripts/cleanup.sh

client/src/extension.ts

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@
77
*/
88

99
import * as path from 'path';
10+
import {ExtensionContext, ProgressLocation, window, workspace} from 'vscode';
11+
import {LanguageClient, LanguageClientOptions, RevealOutputChannelOn, ServerOptions, TransportKind} from 'vscode-languageclient';
1012

11-
import { workspace, ExtensionContext, window, ProgressLocation } from 'vscode';
12-
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, RevealOutputChannelOn } from 'vscode-languageclient';
13-
import { projectLoadingNotification } from './protocol';
13+
import {projectLoadingNotification} from './protocol';
1414

1515
export function activate(context: ExtensionContext) {
16-
1716
// Log file does not yet exist on disk. It is up to the server to create the
1817
// file.
1918
const logFile = path.join(context.logPath, 'nglangsvc.log');
2019

2120
// If the extension is launched in debug mode then the debug server options are used
2221
// Otherwise the run options are used
2322
const serverOptions: ServerOptions = {
24-
run : {
23+
run: {
2524
module: context.asAbsolutePath(path.join('server', 'server.js')),
2625
transport: TransportKind.ipc,
2726
args: [
@@ -39,8 +38,10 @@ export function activate(context: ExtensionContext) {
3938
module: context.asAbsolutePath(path.join('server', 'out', 'server.js')),
4039
transport: TransportKind.ipc,
4140
args: [
42-
'--logFile', logFile,
43-
'--logVerbosity', 'verbose',
41+
'--logFile',
42+
logFile,
43+
'--logVerbosity',
44+
'verbose',
4445
],
4546
options: {
4647
env: {
@@ -80,35 +81,35 @@ export function activate(context: ExtensionContext) {
8081
};
8182

8283
// Create the language client and start the client.
83-
const forceDebug = !!process.env['NG_DEBUG'];
84-
const client = new LanguageClient(
85-
'Angular Language Service', serverOptions, clientOptions, forceDebug);
84+
const forceDebug = !!process.env['NG_DEBUG'];
85+
const client =
86+
new LanguageClient('Angular Language Service', serverOptions, clientOptions, forceDebug);
8687
const disposable = client.start();
8788

8889
// Push the disposable to the context's subscriptions so that the
8990
// client can be deactivated on extension deactivation
9091
context.subscriptions.push(disposable);
9192

92-
client.onReady().then(()=>{
93-
94-
const projectLoadingTasks = new Map<string, { resolve: () => void }>();
93+
client.onReady().then(() => {
94+
const projectLoadingTasks = new Map<string, {resolve: () => void}>();
9595

9696
client.onNotification(projectLoadingNotification.start, (projectName: string) => {
97-
window.withProgress({
98-
location: ProgressLocation.Window,
99-
title: 'Initializing Angular language features',
100-
}, () => new Promise((resolve) => {
101-
projectLoadingTasks.set(projectName, { resolve });
102-
}));
97+
window.withProgress(
98+
{
99+
location: ProgressLocation.Window,
100+
title: 'Initializing Angular language features',
101+
},
102+
() => new Promise((resolve) => {
103+
projectLoadingTasks.set(projectName, {resolve});
104+
}));
103105
});
104-
106+
105107
client.onNotification(projectLoadingNotification.finish, (projectName: string) => {
106-
const task = projectLoadingTasks.get(projectName);
107-
if(task){
108-
task.resolve();
109-
projectLoadingTasks.delete(projectName);
110-
}
108+
const task = projectLoadingTasks.get(projectName);
109+
if (task) {
110+
task.resolve();
111+
projectLoadingTasks.delete(projectName);
112+
}
111113
});
112-
113114
});
114115
}

client/src/protocol.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { NotificationType } from 'vscode-languageclient';
9+
import {NotificationType} from 'vscode-languageclient';
1010

1111
export const projectLoadingNotification = {
12-
start: new NotificationType<string,string>('angular-language-service/projectLoadingStart'),
13-
finish: new NotificationType<string,string>('angular-language-service/projectLoadingFinish')
12+
start: new NotificationType<string, string>('angular-language-service/projectLoadingStart'),
13+
finish: new NotificationType<string, string>('angular-language-service/projectLoadingFinish')
1414
};

integration/e2e/definition.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import * as vscode from 'vscode';
2-
import * as path from 'path';
31
import * as assert from 'assert';
2+
import * as path from 'path';
3+
import * as vscode from 'vscode';
4+
45
import {activate} from './helper';
56

67
const DEFINITION_COMMAND = 'vscode.executeDefinitionProvider';
@@ -20,10 +21,7 @@ describe('Angular LS', () => {
2021
// For a complete list of standard commands, see
2122
// https://code.visualstudio.com/api/references/commands
2223
const definitions = await vscode.commands.executeCommand(
23-
DEFINITION_COMMAND,
24-
docUri,
25-
position
26-
) as vscode.Location[];
24+
DEFINITION_COMMAND, docUri, position) as vscode.Location[];
2725
assert.equal(definitions.length, 1);
2826
const def = definitions[0];
2927
assert.equal(def.uri.fsPath, docPath); // in the same document

integration/e2e/helper.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as vscode from 'vscode';
21
import * as path from 'path';
2+
import * as vscode from 'vscode';
33

44
function sleep(ms: number) {
55
return new Promise(resolve => setTimeout(resolve, ms));
@@ -11,10 +11,8 @@ export async function activate(uri: vscode.Uri) {
1111
try {
1212
const doc = await vscode.workspace.openTextDocument(uri);
1313
const editor = await vscode.window.showTextDocument(doc);
14-
await sleep(2000); // Wait for server activation
15-
}
16-
catch (e) {
14+
await sleep(2000); // Wait for server activation
15+
} catch (e) {
1716
console.error(e);
1817
}
19-
2018
}

integration/e2e/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import * as testRunner from 'vscode/lib/testrunner';
33
// This is the entry point of the test.
44
// The test runner provided by vscode uses Mocha.
55
// Check output in `Debug Console` of the main vscode window.
6-
testRunner.configure({
7-
ui: 'bdd',
8-
useColors: true,
9-
timeout: 100000
10-
});
6+
testRunner.configure({ui: 'bdd', useColors: true, timeout: 100000});
117

128
module.exports = testRunner;

0 commit comments

Comments
 (0)