Skip to content
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

core(stack-packs): sort packs in order we defined them #15039

Merged
merged 2 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/lib/stack-packs.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ function getStackPacks(pageStacks) {
});
}

return packs;
return packs.sort((a, b) => {
const aVal = stackPacksToInclude.findIndex(p => p.packId === a.id);
const bVal = stackPacksToInclude.findIndex(p => p.packId === b.id);
return aVal - bVal;
});
}

export {
Expand Down
23 changes: 22 additions & 1 deletion core/test/lib/stack-packs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import lighthouseStackPacksDep from 'lighthouse-stack-packs';

import {initializeConfig} from '../../config/config.js';
import {stackPacksToInclude} from '../../lib/stack-packs.js';
import {stackPacksToInclude, getStackPacks} from '../../lib/stack-packs.js';

async function getAuditIds() {
const {resolvedConfig} = await initializeConfig('navigation');
Expand All @@ -21,6 +21,27 @@ describe('stack-packs lib', () => {
.map(p => p.id);
expect(result).toEqual([]);
});

it('returns packs from page stacks', () => {
expect(getStackPacks([])).toEqual([]);
expect(getStackPacks([{detector: 'js', id: 'i-dont-know-you'}])).toEqual([]);

const packs = getStackPacks([
{detector: 'js', id: 'wordpress'},
{detector: 'js', id: 'react'},
]);

expect(packs.map(pack => pack.id)).toEqual(['wordpress', 'react']);
});

it('returns packs from page stacks in order defined by us', () => {
const packs = getStackPacks([
{detector: 'js', id: 'react'},
{detector: 'js', id: 'wordpress'},
]);

expect(packs.map(pack => pack.id)).toEqual(['wordpress', 'react']);
});
});

// These tests summarize the contents of the lighthouse-stack-packs package.
Expand Down