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

Handle custom rules directories correctly when using --test #1195

Merged
merged 1 commit into from
May 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export interface TestResult {
};
}

export function runTest(testDirectory: string): TestResult {
export function runTest(testDirectory: string, rulesDirectory?: string | string[]): TestResult {
const filesToLint = glob.sync(path.join(testDirectory, `**/*${FILE_EXTENSION}`));
const tslintConfig = JSON.parse(fs.readFileSync(path.join(testDirectory, "tslint.json"), "utf8"));
const tslintConfig = Linter.findConfiguration(path.join(testDirectory, "tslint.json"), null);
const results: TestResult = { directory: testDirectory, results: {} };

for (const fileToLint of filesToLint) {
Expand All @@ -54,7 +54,7 @@ export function runTest(testDirectory: string): TestResult {
configuration: tslintConfig,
formatter: "prose",
formattersDirectory: "",
rulesDirectory: "",
rulesDirectory,
};
const linter = new Linter(fileBasename, fileTextWithoutMarkup, lintOptions);
const errorsFromLinter: LintError[] = linter.lint().failures.map((failure) => {
Expand Down
2 changes: 1 addition & 1 deletion src/tslint-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ if (argv.i != null) {
}

if (argv.test != null) {
const results = runTest(argv.test);
const results = runTest(argv.test, argv.r);
const didAllTestsPass = consoleTestResultHandler(results);
process.exit(didAllTestsPass ? 0 : 1);
}
Expand Down
7 changes: 7 additions & 0 deletions test/check-bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ expectOut $? 0 "tslint --test did not exit correctly for a passing test"
./bin/tslint --test test/files/incorrect-rule-test
expectOut $? 1 "tslint --test did not exit correctly for a failing test"

# ensure --test command works correctly with custom rules
./bin/tslint --test test/files/custom-rule-rule-test
expectOut $? 0 "tslint --test did not exit correctly for a passing test with custom rules"

./bin/tslint -r test/files/custom-rules-2 --test test/files/custom-rule-cli-rule-test
expectOut $? 0 "tslint --test did not exit correctly for a passing test with custom rules from the CLI"

if [ $num_failures != 0 ]; then
echo "Failed $num_failures tests"
exit 1
Expand Down
1 change: 1 addition & 0 deletions test/files/custom-rule-cli-rule-test/test.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var test = 5;
5 changes: 5 additions & 0 deletions test/files/custom-rule-cli-rule-test/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-fail": true
}
}
1 change: 1 addition & 0 deletions test/files/custom-rule-rule-test/test.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var test = 5;
6 changes: 6 additions & 0 deletions test/files/custom-rule-rule-test/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"rulesDirectory": "../custom-rules-2",
"rules": {
"no-fail": true
}
}