Skip to content

Commit

Permalink
cleanup css order test
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Dec 30, 2021
1 parent 74f3e64 commit 4f4f571
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions website/testCSSOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@ Current solution looks good-enough for now
*/

// TODO temporary, the current order is bad and we should change that
const EXPECTED_MARKER_CLASSES = [
// Some class from Infima, in the order Infima declares them
// this ensures we don't mess-up and re-order css from other libs
// TODO temporary, the current order is bad and we should change/fix that
const EXPECTED_CSS_MARKERS = [
// Note, Infima and site classes are optimized/deduplicated and put at the top
// We don't agree yet on what should be the order for those classes
// See https://github.com/facebook/docusaurus/pull/6222
'.markdown>h2',
'.button--outline.button--active',
':root', // TODO should be first
'.DocSearch-Hit-content-wrapper', // TODO should not be there?
'.DocSearch-Hit-content-wrapper',
'.navbar__title',
'.test-marker-site-custom-css-shared-rule', // TODO should not be there!
'.col[class*=col--]', // TODO should be after paddings
'--ifm-color-scheme:light',
'.test-marker-site-custom-css-shared-rule',
'.col[class*=col--]',
'.padding-vert--xl',
'.footer__link-item', // TODO should be last
'.footer__link-item',
'.pagination__item',
'.pills__item',
'.tabs__item',
Expand All @@ -45,6 +46,8 @@ const EXPECTED_MARKER_CLASSES = [
'.test-marker-site-client-module',
'.test-marker-theme-layout',
'.test-marker-site-index-page',

// lazy loaded lib
'.DocSearch-Modal',
];

Expand All @@ -63,7 +66,7 @@ console.log('Inspecting CSS file for test CSS markers', cssFile);

const cssFileContent = fs.readFileSync(cssFile, 'utf8');

const cssMarkersWithPositions = EXPECTED_MARKER_CLASSES.map((marker) => {
const cssMarkersWithPositions = EXPECTED_CSS_MARKERS.map((marker) => {
const position = cssFileContent.indexOf(marker);
return {marker, position};
});
Expand All @@ -90,16 +93,14 @@ const sortedCSSMarkers = cssMarkersWithPositions
.sort(sortBy('position'))
.map(({marker}) => marker);

if (
JSON.stringify(sortedCSSMarkers) === JSON.stringify(EXPECTED_MARKER_CLASSES)
) {
if (JSON.stringify(sortedCSSMarkers) === JSON.stringify(EXPECTED_CSS_MARKERS)) {
console.log(`Test CSS markers were found in the expected order:
- ${sortedCSSMarkers.join('\n- ')}`);
} else {
throw new Error(`Test CSS markers were found in an incorrect order.
Expected order:
- ${EXPECTED_MARKER_CLASSES.join('\n- ')};
- ${EXPECTED_CSS_MARKERS.join('\n- ')};
Actual order:
- ${sortedCSSMarkers.join('\n- ')};
Expand Down

0 comments on commit 4f4f571

Please sign in to comment.