Skip to content

Commit

Permalink
Chore: fix the timing to define rules for tests (#8082)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea authored and vitorbal committed Feb 16, 2017
1 parent c7e64f3 commit 55ac302
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/testers/rule-tester.js
Expand Up @@ -147,6 +147,12 @@ function RuleTester(testerConfig) {
lodash.cloneDeep(defaultConfig),
testerConfig
);

/**
* Rule definitions to define before tests.
* @type {Object}
*/
this.rules = {};
}

/**
Expand Down Expand Up @@ -239,7 +245,7 @@ RuleTester.prototype = {
* @returns {void}
*/
defineRule(name, rule) {
eslint.defineRule(name, rule);
this.rules[name] = rule;
},

/**
Expand Down Expand Up @@ -508,6 +514,7 @@ RuleTester.prototype = {
RuleTester.describe("valid", () => {
test.valid.forEach(valid => {
RuleTester.it(valid.code || valid, () => {
eslint.defineRules(this.rules);
testValidTemplate(ruleName, valid);
});
});
Expand All @@ -516,6 +523,7 @@ RuleTester.prototype = {
RuleTester.describe("invalid", () => {
test.invalid.forEach(invalid => {
RuleTester.it(invalid.code, () => {
eslint.defineRules(this.rules);
testInvalidTemplate(ruleName, invalid);
});
});
Expand Down

0 comments on commit 55ac302

Please sign in to comment.