-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Improve "Error type should be" assertion in rule-tester #6106
Comments
@alberto This is changing message in rule-tester only, so it will only affect developers of the plugins + us. So pretty sure this will be non-breaking. |
@ilyavolodin I do get the correct output from most of the assertions, but this particular one seems to be an issue. Can you check whether you see the before/after or a stack trace when using the example I posted above? |
@nzakas I don't think Chai's Example:
I'm guessing Chai doesn't instrument the code before a run, so it probably only sees whatever the |
@DrewML ah, good call. I forgot we weren't using Chai. I'm 👍 For this. |
Cool - I'll start working on this tonight. Safe to assume we want to do this for all the assertions in that same area? For reference: if (typeof item.errors === "number") {
assert.equal(messages.length, item.errors, util.format("Should have %d error%s but had %d: %s",
item.errors, item.errors === 1 ? "" : "s", messages.length, util.inspect(messages)));
} else {
assert.equal(messages.length, item.errors.length,
util.format("Should have %d error%s but had %d: %s",
item.errors.length, item.errors.length === 1 ? "" : "s", messages.length, util.inspect(messages)));
for (var i = 0, l = item.errors.length; i < l; i++) {
assert.ok(!("fatal" in messages[i]), "A fatal parsing error occurred: " + messages[i].message);
assert.equal(messages[i].ruleId, ruleName, "Error rule name should be the same as the name of the rule being tested");
if (typeof item.errors[i] === "string") {
// Just an error message.
assert.equal(messages[i].message, item.errors[i], "Error message should be " + item.errors[i]);
} else if (typeof item.errors[i] === "object") {
/*
* Error object.
* This may have a message, node type, line, and/or
* column.
*/
if (item.errors[i].message) {
assert.equal(messages[i].message, item.errors[i].message, "Error message should be " + item.errors[i].message);
}
if (item.errors[i].type) {
assert.equal(messages[i].nodeType, item.errors[i].type, "Error type should be " + item.errors[i].type);
}
if (item.errors[i].hasOwnProperty("line")) {
assert.equal(messages[i].line, item.errors[i].line, "Error line should be " + item.errors[i].line);
}
if (item.errors[i].hasOwnProperty("column")) {
assert.equal(messages[i].column, item.errors[i].column, "Error column should be " + item.errors[i].column);
}
} else {
// Only string or object errors are valid.
assert.fail(messages[i], null, "Error should be a string or object.");
}
}
if (item.hasOwnProperty("output")) {
var fixResult = SourceCodeFixer.applyFixes(eslint.getSourceCode(), messages);
assert.equal(fixResult.output, item.output, "Output is incorrect.");
}
} |
Yes, I think so. |
@DrewML Since you have the work done (assuming since u began working on it), would like to send a PR? |
This is fixed as of #7550. |
This issue is very similar to #5917, but it's about a different assertion message.
When using the
type
property in anerrors
object for invalid code, and the test value does not match the expected value, the following message is currently spit to stdout:For debugging purposes, it would be helpful to know what value was provided for the
type
, not just the expected value.You can replicate the existing behavior with the following:
Use this descriptor for
invalid
code in arule-tester
runUse this code in a basic rule
The source of this problem is in
/lib/testers/rule-tester.js
on line 400:Augmenting the assertion message to include the value for
messages[i].nodeType
would make debugging a bit easier.Is there any interest in a PR to improve this?
The text was updated successfully, but these errors were encountered: