Skip to content

Commit

Permalink
fix: assertFailure catch exception throw by assert (#703) (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
someblue authored and mgechev committed Aug 24, 2018
1 parent 7f0fe0e commit 0bac287
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions test/testHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const parseInvalidSource = (source: string, message: string, specialChar = '~',
*
* @param config
*/
export function assertAnnotated(config: AssertConfig) {
export function assertAnnotated(config: AssertConfig): RuleFailure[] | void {
const { message, options, ruleName, source: sourceConfig } = config;

if (message) {
Expand Down Expand Up @@ -230,25 +230,18 @@ export function assertFailure(
fail: IExpectedFailure,
options?: any,
onlyNthFailure = 0
): RuleFailure[] | undefined {
let result: LintResult;

try {
result = lint(ruleName, source, options);
): RuleFailure[] {
const result = lint(ruleName, source, options);

assert(result.failures && result.failures.length > 0, 'no failures');
assert(result.failures && result.failures.length > 0, 'no failures');

const ruleFail = result.failures[onlyNthFailure];
const ruleFail = result.failures[onlyNthFailure];

assert.equal(fail.message, ruleFail.getFailure(), "error messages don't match");
assert.deepEqual(fail.startPosition, ruleFail.getStartPosition().getLineAndCharacter(), "start char doesn't match");
assert.deepEqual(fail.endPosition, ruleFail.getEndPosition().getLineAndCharacter(), "end char doesn't match");
assert.equal(fail.message, ruleFail.getFailure(), "error messages don't match");
assert.deepEqual(fail.startPosition, ruleFail.getStartPosition().getLineAndCharacter(), "start char doesn't match");
assert.deepEqual(fail.endPosition, ruleFail.getEndPosition().getLineAndCharacter(), "end char doesn't match");

return result ? result.failures : undefined;
} catch (e) {
console.log(e.stack);
return undefined;
}
return result.failures;
}

/**
Expand All @@ -261,12 +254,7 @@ export function assertFailure(
* @param options
*/
export function assertFailures(ruleName: string, source: string | SourceFile, fails: IExpectedFailure[], options?: any) {
let result;
try {
result = lint(ruleName, source, options);
} catch (e) {
console.log(e.stack);
}
const result = lint(ruleName, source, options);

assert(result.failures && result.failures.length > 0, 'no failures');
result.failures.forEach((ruleFail, index) => {
Expand Down

0 comments on commit 0bac287

Please sign in to comment.