Skip to content

Commit

Permalink
fix(heal): wrong priority (#4394)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Jun 13, 2024
1 parent e29bc2d commit e34471c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/heal.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ module.exports = heal;
function matchRecipes(recipes, contextName) {
return Object.entries(recipes)
.filter(([, recipe]) => !contextName || !recipe.grep || new RegExp(recipe.grep).test(contextName))
.sort(([, a], [, b]) => b.priority - a.priority)
.sort(([, a], [, b]) => a.priority - b.priority)
.map(([name, recipe]) => {
recipe.name = name;
return recipe;
Expand Down
26 changes: 26 additions & 0 deletions test/unit/heal_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@ describe('heal', () => {
expect(heal.hasCorrespondingRecipes({ name: 'click' })).to.be.true;
});

it('should respect the priority of recipes', async () => {
heal.addRecipe('secondPrior', {
priority: 2,
steps: ['click'],
fn: async () => {
return ({ I }) => {
I.refreshPage();
};
},
});

heal.addRecipe('firstPrior', {
priority: 1,
steps: ['refresh'],
fn: async () => {
return ({ I }) => {
I.refreshPage();
I.refreshPage();
};
},
});

expect((await heal.getCodeSuggestions({}))[0].name).to.equal('firstPrior');
expect((await heal.getCodeSuggestions({}))[1].name).to.equal('secondPrior');
});

it('should have corresponding recipes', () => {
heal.recipes = { test: { steps: ['step1', 'step2'], fn: () => {} } };
heal.contextName = 'TestSuite';
Expand Down

0 comments on commit e34471c

Please sign in to comment.