New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update: More detailed assert message for rule-tester #9769
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7252351
Update: More detailed assert message for rule-tester
starkwang a3f60f0
[squash]add try/finally block
starkwang 2d33618
[squash]append message instead of overwriting it
starkwang f17d679
[squash]add parentheses surrounding error message
starkwang File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @fileoverview Tests for RuleTester without any test runner | ||
* @author Weijia Wang <starkwang@126.com> | ||
*/ | ||
"use strict"; | ||
|
||
/* global describe, it */ | ||
/* eslint-disable no-global-assign*/ | ||
const assert = require("assert"), | ||
RuleTester = require("../../../lib/testers/rule-tester"); | ||
const tmpIt = it; | ||
const tmpDescribe = describe; | ||
|
||
it = null; | ||
describe = null; | ||
|
||
try { | ||
const ruleTester = new RuleTester(); | ||
|
||
assert.throws(() => { | ||
ruleTester.run("no-var", require("../../fixtures/testers/rule-tester/no-var"), { | ||
valid: [ | ||
"bar = baz;" | ||
], | ||
invalid: [ | ||
{ code: "var foo = bar;", output: "invalid output", errors: 1 } | ||
] | ||
}); | ||
}, /' foo = bar;' == 'invalid output'/); | ||
} catch (e) { | ||
throw e; | ||
} finally { | ||
it = tmpIt; | ||
describe = tmpDescribe; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this append to the existing message rather than overwriting it? I think it would be good to retain the
"Output is incorrect"
text to make the source of the error clearer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I forgot to explain here.
The
defaultHandler
is called nestedly somehow (sorry I don't dive into the code but its behaviour shows that), so the thrown error will be caught and err messagewill be appended in multiple times. It will finally become like
That's the reason for overwriting it here.
Another solution is adding a flag like
appended
on error object to avoid multiple appending. But is it worth to do it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. I think that's happening because
defaultHandler
is used for both the "describe" and the "it" methods. So effectively something like this is happening:One solution would be to use the old default handler (which just calls the function in the second argument) as the default for
describe
, and use the handler that appends a diff as the default forit
.