Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Changed --test to take multiple directories (#2079)
Browse files Browse the repository at this point in the history
Fixes #2064.
  • Loading branch information
Josh Goldberg authored and nchen63 committed Jan 20, 2017
1 parent 23f5f00 commit 85f539f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,11 @@ tslint accepts the following command-line options:
option is set.
--test:
Runs tslint on the specified directory and checks if tslint's output matches
the expected output in .lint files. Automatically loads the tslint.json file in the
specified directory as the configuration file for the tests. See the
full tslint documentation for more details on how this can be used to test custom rules.
Runs tslint on matched directories and checks if tslint outputs
match the expected output in .lint files. Automatically loads the
tslint.json files in the directories as the configuration file for
the tests. See the full tslint documentation for more details on how
this can be used to test custom rules.
--project:
The location of a tsconfig.json file that will be used to determine which
Expand Down
6 changes: 3 additions & 3 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from "./configuration";
import { FatalError } from "./error";
import * as Linter from "./linter";
import { consoleTestResultHandler, runTest } from "./test";
import { consoleTestResultsHandler, runTests } from "./test";
import { updateNotifierCheck } from "./updateNotifier";

export interface IRunnerOptions {
Expand Down Expand Up @@ -130,8 +130,8 @@ export class Runner {
}

if (this.options.test) {
const results = runTest(this.options.test, this.options.rulesDirectory);
const didAllTestsPass = consoleTestResultHandler(results);
const results = runTests(this.options.test, this.options.rulesDirectory);
const didAllTestsPass = consoleTestResultsHandler(results);
onComplete(didAllTestsPass ? 0 : 1);
return;
}
Expand Down
17 changes: 17 additions & 0 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export interface TestResult {
};
}

export function runTests(pattern: string, rulesDirectory?: string | string[]): TestResult[] {
return glob.sync(`${pattern}/tslint.json`)
.map((directory: string): TestResult => runTest(path.dirname(directory), rulesDirectory));
}

export function runTest(testDirectory: string, rulesDirectory?: string | string[]): TestResult {
// needed to get colors to show up when passing through Grunt
(colors as any).enabled = true;
Expand Down Expand Up @@ -162,6 +167,18 @@ export function runTest(testDirectory: string, rulesDirectory?: string | string[
return results;
}

export function consoleTestResultsHandler(testResults: TestResult[]): boolean {
let didAllTestsPass = true;

for (const testResult of testResults) {
if (!consoleTestResultHandler(testResult)) {
didAllTestsPass = false;
}
}

return didAllTestsPass;
}

export function consoleTestResultHandler(testResult: TestResult): boolean {
let didAllTestsPass = true;

Expand Down
9 changes: 5 additions & 4 deletions src/tslint-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,11 @@ tslint accepts the following commandline options:
option is set.
--test:
Runs tslint on the specified directory and checks if tslint's output matches
the expected output in .lint files. Automatically loads the tslint.json file in the
specified directory as the configuration file for the tests. See the
full tslint documentation for more details on how this can be used to test custom rules.
Runs tslint on matched directories and checks if tslint outputs
match the expected output in .lint files. Automatically loads the
tslint.json files in the directories as the configuration file for
the tests. See the full tslint documentation for more details on how
this can be used to test custom rules.
--project:
The location of a tsconfig.json file that will be used to determine which
Expand Down

0 comments on commit 85f539f

Please sign in to comment.