diff --git a/lib/heal.js b/lib/heal.js index 0d7aca8cf..b6071c456 100644 --- a/lib/heal.js +++ b/lib/heal.js @@ -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; diff --git a/test/unit/heal_test.js b/test/unit/heal_test.js index 849a99078..03121f4f9 100644 --- a/test/unit/heal_test.js +++ b/test/unit/heal_test.js @@ -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';