Skip to content

Commit c09793d

Browse files
committed
Merge pull request microsoft#8785 from Microsoft/lint-unit-tests
Lint unit tests via harnessSources in Jakefile.js
2 parents 50529ac + 975ed9c commit c09793d

18 files changed

Lines changed: 924 additions & 916 deletions

Jakefile.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,27 +974,29 @@ var servicesLintTargets = [
974974
return path.join(servicesDirectory, s);
975975
});
976976
var lintTargets = compilerSources
977-
.concat(harnessCoreSources)
977+
.concat(harnessSources)
978978
// Other harness sources
979979
.concat(["instrumenter.ts"].map(function(f) { return path.join(harnessDirectory, f) }))
980980
.concat(serverCoreSources)
981-
.concat(["client.ts"].map(function(f) { return path.join(serverDirectory, f); }))
982981
.concat(tslintRulesFiles)
983982
.concat(servicesLintTargets);
984983

984+
985985
desc("Runs tslint on the compiler sources. Optional arguments are: f[iles]=regex");
986986
task("lint", ["build-rules"], function() {
987987
var lintOptions = getLinterOptions();
988988
var failed = 0;
989989
var fileMatcher = RegExp(process.env.f || process.env.file || process.env.files || "");
990+
var done = {};
990991
for (var i in lintTargets) {
991992
var target = lintTargets[i];
992-
if (fileMatcher.test(target)) {
993+
if (!done[target] && fileMatcher.test(target)) {
993994
var result = lintFile(lintOptions, target);
994995
if (result.failureCount > 0) {
995996
console.log(result.output);
996997
failed += result.failureCount;
997998
}
999+
done[target] = true;
9981000
}
9991001
}
10001002
if (failed > 0) {

tests/cases/unittests/cachingInServerLSHost.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace ts {
77
}
88

99
function createDefaultServerHost(fileMap: Map<File>): server.ServerHost {
10-
let existingDirectories: Map<boolean> = {};
10+
const existingDirectories: Map<boolean> = {};
1111
forEachValue(fileMap, v => {
1212
let dir = getDirectoryPath(v.name);
1313
let previous: string;
@@ -67,7 +67,7 @@ namespace ts {
6767
}
6868

6969
function createProject(rootFile: string, serverHost: server.ServerHost): { project: server.Project, rootScriptInfo: server.ScriptInfo } {
70-
let logger: server.Logger = {
70+
const logger: server.Logger = {
7171
close() { },
7272
isVerbose: () => false,
7373
loggingEnabled: () => false,
@@ -78,9 +78,9 @@ namespace ts {
7878
msg: (s: string, type?: string) => { }
7979
};
8080

81-
let projectService = new server.ProjectService(serverHost, logger);
82-
let rootScriptInfo = projectService.openFile(rootFile, /* openedByClient */true);
83-
let project = projectService.createInferredProject(rootScriptInfo);
81+
const projectService = new server.ProjectService(serverHost, logger);
82+
const rootScriptInfo = projectService.openFile(rootFile, /* openedByClient */true);
83+
const project = projectService.createInferredProject(rootScriptInfo);
8484
project.setProjectOptions({ files: [rootScriptInfo.fileName], compilerOptions: { module: ts.ModuleKind.AMD } });
8585
return {
8686
project,
@@ -90,32 +90,32 @@ namespace ts {
9090

9191
describe("Caching in LSHost", () => {
9292
it("works using legacy resolution logic", () => {
93-
let root: File = {
93+
const root: File = {
9494
name: "c:/d/f0.ts",
9595
content: `import {x} from "f1"`
9696
};
9797

98-
let imported: File = {
98+
const imported: File = {
9999
name: "c:/f1.ts",
100100
content: `foo()`
101101
};
102102

103-
let serverHost = createDefaultServerHost({ [root.name]: root, [imported.name]: imported });
104-
let { project, rootScriptInfo } = createProject(root.name, serverHost);
103+
const serverHost = createDefaultServerHost({ [root.name]: root, [imported.name]: imported });
104+
const { project, rootScriptInfo } = createProject(root.name, serverHost);
105105

106106
// ensure that imported file was found
107107
let diags = project.compilerService.languageService.getSemanticDiagnostics(imported.name);
108108
assert.equal(diags.length, 1);
109109

110-
let originalFileExists = serverHost.fileExists;
110+
const originalFileExists = serverHost.fileExists;
111111
{
112112
// patch fileExists to make sure that disk is not touched
113113
serverHost.fileExists = (fileName): boolean => {
114114
assert.isTrue(false, "fileExists should not be called");
115115
return false;
116116
};
117117

118-
let newContent = `import {x} from "f1"
118+
const newContent = `import {x} from "f1"
119119
var x: string = 1;`;
120120
rootScriptInfo.editContent(0, rootScriptInfo.content.length, newContent);
121121
// trigger synchronization to make sure that import will be fetched from the cache
@@ -133,7 +133,7 @@ namespace ts {
133133
assert.isTrue(fileName.indexOf("/f2.") !== -1);
134134
return originalFileExists.call(serverHost, fileName);
135135
};
136-
let newContent = `import {x} from "f2"`;
136+
const newContent = `import {x} from "f2"`;
137137
rootScriptInfo.editContent(0, rootScriptInfo.content.length, newContent);
138138

139139
try {
@@ -157,15 +157,15 @@ namespace ts {
157157
return originalFileExists.call(serverHost, fileName);
158158
};
159159

160-
let newContent = `import {x} from "f1"`;
160+
const newContent = `import {x} from "f1"`;
161161
rootScriptInfo.editContent(0, rootScriptInfo.content.length, newContent);
162162
project.compilerService.languageService.getSemanticDiagnostics(imported.name);
163163
assert.isTrue(fileExistsCalled);
164164

165165
// setting compiler options discards module resolution cache
166166
fileExistsCalled = false;
167167

168-
let opts = ts.clone(project.projectOptions);
168+
const opts = ts.clone(project.projectOptions);
169169
opts.compilerOptions = ts.clone(opts.compilerOptions);
170170
opts.compilerOptions.target = ts.ScriptTarget.ES5;
171171
project.setProjectOptions(opts);
@@ -176,19 +176,19 @@ namespace ts {
176176
});
177177

178178
it("loads missing files from disk", () => {
179-
let root: File = {
179+
const root: File = {
180180
name: `c:/foo.ts`,
181181
content: `import {x} from "bar"`
182182
};
183183

184-
let imported: File = {
184+
const imported: File = {
185185
name: `c:/bar.d.ts`,
186186
content: `export var y = 1`
187187
};
188188

189-
let fileMap: Map<File> = { [root.name]: root };
190-
let serverHost = createDefaultServerHost(fileMap);
191-
let originalFileExists = serverHost.fileExists;
189+
const fileMap: Map<File> = { [root.name]: root };
190+
const serverHost = createDefaultServerHost(fileMap);
191+
const originalFileExists = serverHost.fileExists;
192192

193193
let fileExistsCalledForBar = false;
194194
serverHost.fileExists = fileName => {
@@ -202,7 +202,7 @@ namespace ts {
202202
return originalFileExists.call(serverHost, fileName);
203203
};
204204

205-
let { project, rootScriptInfo } = createProject(root.name, serverHost);
205+
const { project, rootScriptInfo } = createProject(root.name, serverHost);
206206

207207
let diags = project.compilerService.languageService.getSemanticDiagnostics(root.name);
208208
assert.isTrue(fileExistsCalledForBar, "'fileExists' should be called");
@@ -219,4 +219,4 @@ namespace ts {
219219
assert.isTrue(diags.length === 0);
220220
});
221221
});
222-
}
222+
}

tests/cases/unittests/commandLineParsing.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/// <reference path="..\..\..\src\compiler\commandLineParser.ts" />
33

44
namespace ts {
5-
describe('parseCommandLine', () => {
5+
describe("parseCommandLine", () => {
66

77
function assertParseResult(commandLine: string[], expectedParsedCommandLine: ts.ParsedCommandLine) {
88
const parsed = ts.parseCommandLine(commandLine);
@@ -13,9 +13,9 @@ namespace ts {
1313
const parsedErrors = parsed.errors;
1414
const expectedErrors = expectedParsedCommandLine.errors;
1515
assert.isTrue(parsedErrors.length === expectedErrors.length, `Expected error: ${JSON.stringify(expectedErrors)}. Actual error: ${JSON.stringify(parsedErrors)}.`);
16-
for (let i = 0; i < parsedErrors.length; ++i) {
16+
for (let i = 0; i < parsedErrors.length; i++) {
1717
const parsedError = parsedErrors[i];
18-
const expectedError = expectedErrors[i];
18+
const expectedError = expectedErrors[i];
1919
assert.equal(parsedError.code, expectedError.code);
2020
assert.equal(parsedError.category, expectedError.category);
2121
assert.equal(parsedError.messageText, expectedError.messageText);
@@ -24,9 +24,9 @@ namespace ts {
2424
const parsedFileNames = parsed.fileNames;
2525
const expectedFileNames = expectedParsedCommandLine.fileNames;
2626
assert.isTrue(parsedFileNames.length === expectedFileNames.length, `Expected fileNames: [${JSON.stringify(expectedFileNames)}]. Actual fileNames: [${JSON.stringify(parsedFileNames)}].`);
27-
for (let i = 0; i < parsedFileNames.length; ++i) {
27+
for (let i = 0; i < parsedFileNames.length; i++) {
2828
const parsedFileName = parsedFileNames[i];
29-
const expectedFileName = expectedFileNames[i];
29+
const expectedFileName = expectedFileNames[i];
3030
assert.equal(parsedFileName, expectedFileName);
3131
}
3232
}
@@ -113,7 +113,7 @@ namespace ts {
113113
start: undefined,
114114
length: undefined,
115115
}, {
116-
messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'",
116+
messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'",
117117
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
118118
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
119119

tests/cases/unittests/convertCompilerOptionsFromJson.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
/// <reference path="..\..\..\src\compiler\commandLineParser.ts" />
33

44
namespace ts {
5-
describe('convertCompilerOptionsFromJson', () => {
5+
describe("convertCompilerOptionsFromJson", () => {
66
function assertCompilerOptions(json: any, configFileName: string, expectedResult: { compilerOptions: CompilerOptions, errors: Diagnostic[] }) {
77
const { options: actualCompilerOptions, errors: actualErrors} = convertCompilerOptionsFromJson(json["compilerOptions"], "/apath/", configFileName);
8-
8+
99
const parsedCompilerOptions = JSON.stringify(actualCompilerOptions);
1010
const expectedCompilerOptions = JSON.stringify(expectedResult.compilerOptions);
1111
assert.equal(parsedCompilerOptions, expectedCompilerOptions);
12-
12+
1313
const expectedErrors = expectedResult.errors;
1414
assert.isTrue(expectedResult.errors.length === actualErrors.length, `Expected error: ${JSON.stringify(expectedResult.errors)}. Actual error: ${JSON.stringify(actualErrors)}.`);
15-
for (let i = 0; i < actualErrors.length; ++i) {
15+
for (let i = 0; i < actualErrors.length; i++) {
1616
const actualError = actualErrors[i];
17-
const expectedError = expectedErrors[i];
17+
const expectedError = expectedErrors[i];
1818
assert.equal(actualError.code, expectedError.code);
1919
assert.equal(actualError.category, expectedError.category);
2020
assert.equal(actualError.messageText, expectedError.messageText);
2121
}
2222
}
23-
23+
2424
// tsconfig.json tests
2525
it("Convert correctly format tsconfig.json to compiler-options ", () => {
2626
assertCompilerOptions(
@@ -448,7 +448,7 @@ namespace ts {
448448
}
449449
}, "jsconfig.json",
450450
{
451-
compilerOptions:
451+
compilerOptions:
452452
{
453453
allowJs: true
454454
},
@@ -467,7 +467,7 @@ namespace ts {
467467
it("Convert default jsconfig.json to compiler-options ", () => {
468468
assertCompilerOptions({}, "jsconfig.json",
469469
{
470-
compilerOptions:
470+
compilerOptions:
471471
{
472472
allowJs: true
473473
},

tests/cases/unittests/convertToBase64.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/// <reference path="..\..\..\src\harness\harness.ts" />
22

3-
module ts {
4-
describe('convertToBase64', () => {
3+
namespace ts {
4+
describe("convertToBase64", () => {
55
function runTest(input: string): void {
6-
var actual = ts.convertToBase64(input);
7-
var expected = new Buffer(input).toString("base64");
6+
const actual = ts.convertToBase64(input);
7+
const expected = new Buffer(input).toString("base64");
88
assert.equal(actual, expected, "Encoded string using convertToBase64 does not match buffer.toString('base64')");
99
}
1010

tests/cases/unittests/convertTypingOptionsFromJson.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
/// <reference path="..\..\..\src\compiler\commandLineParser.ts" />
33

44
namespace ts {
5-
describe('convertTypingOptionsFromJson', () => {
5+
describe("convertTypingOptionsFromJson", () => {
66
function assertTypingOptions(json: any, configFileName: string, expectedResult: { typingOptions: TypingOptions, errors: Diagnostic[] }) {
77
const { options: actualTypingOptions, errors: actualErrors } = convertTypingOptionsFromJson(json["typingOptions"], "/apath/", configFileName);
88
const parsedTypingOptions = JSON.stringify(actualTypingOptions);
99
const expectedTypingOptions = JSON.stringify(expectedResult.typingOptions);
1010
assert.equal(parsedTypingOptions, expectedTypingOptions);
11-
11+
1212
const expectedErrors = expectedResult.errors;
1313
assert.isTrue(expectedResult.errors.length === actualErrors.length, `Expected error: ${JSON.stringify(expectedResult.errors)}. Actual error: ${JSON.stringify(actualErrors)}.`);
14-
for (let i = 0; i < actualErrors.length; ++i) {
14+
for (let i = 0; i < actualErrors.length; i++) {
1515
const actualError = actualErrors[i];
16-
const expectedError = expectedErrors[i];
16+
const expectedError = expectedErrors[i];
1717
assert.equal(actualError.code, expectedError.code, `Expected error-code: ${JSON.stringify(expectedError.code)}. Actual error-code: ${JSON.stringify(actualError.code)}.`);
1818
assert.equal(actualError.category, expectedError.category, `Expected error-category: ${JSON.stringify(expectedError.category)}. Actual error-category: ${JSON.stringify(actualError.category)}.`);
1919
}
@@ -41,7 +41,7 @@ namespace ts {
4141
errors: <Diagnostic[]>[]
4242
});
4343
});
44-
44+
4545
it("Convert incorrect format tsconfig.json to typing-options ", () => {
4646
assertTypingOptions(
4747
{

0 commit comments

Comments
 (0)