diff --git a/README.md b/README.md index 70b6bbd648d..20292c0e56a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/runner.ts b/src/runner.ts index 49160371f33..5e767d3e651 100644 --- a/src/runner.ts +++ b/src/runner.ts @@ -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 { @@ -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; } diff --git a/src/test.ts b/src/test.ts index ba657040dc1..9c4887352aa 100644 --- a/src/test.ts +++ b/src/test.ts @@ -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; @@ -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; diff --git a/src/tslint-cli.ts b/src/tslint-cli.ts index 4d4bfd1cc0e..8fbfbb6b87f 100644 --- a/src/tslint-cli.ts +++ b/src/tslint-cli.ts @@ -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