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
Changes from 1 commit
7252351
a3f60f0
2d33618
f17d679
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* @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; | ||
|
||
const ruleTester = new RuleTester(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd feel better if this logic (from here to the end of the assertion) were wrapped in a try/finally so that the globals are definitely reassigned even if an exception is thrown. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added the try/finally : ) |
||
|
||
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'/); | ||
|
||
it = tmpIt; | ||
describe = tmpDescribe; |
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
.