Skip to content

Commit

Permalink
MWPW-134706 Reevaluate bacom-blog repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon32 committed Aug 8, 2023
1 parent 9d85bd2 commit 1377b78
Show file tree
Hide file tree
Showing 11 changed files with 2,415 additions and 7,021 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ module.exports = {
ObjectExpression: { multiline: true, minProperties: 6 },
ObjectPattern: { multiline: true, minProperties: 6 },
ImportDeclaration: { multiline: true, minProperties: 6 },
ExportDeclaration: 'never',
ExportDeclaration: { multiline: true, minProperties: 6 },
}],
'no-return-assign': ['error', 'except-parens'],
'no-unused-expressions': 0,
'chai-friendly/no-unused-expressions': 2,
},
Expand Down
1 change: 1 addition & 0 deletions 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<title>404</title>
<meta name="template" content="404"/>
<meta name="404" content="local"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<script src="/scripts/scripts.js" type="module"></script>
<link rel="icon" href="data:,">
Expand Down
2 changes: 1 addition & 1 deletion fstab.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# 2. Google Drive is no longer allowed for production Adobe projects.

mountpoints:
/: https://adobe.sharepoint.com/:f:/r/sites/adobecom/Shared%20Documents/bacom-blog
/: https://adobe.sharepoint.com/:f:/r/sites/BizWeb/Shared%20Documents/website
9,197 changes: 2,219 additions & 6,978 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@adobecom/bacom-blog",
"private": true,
"type": "module",
"version": "1.0.0",
"description": "Website foundation technology.",
"scripts": {
Expand Down Expand Up @@ -32,6 +33,8 @@
"eslint": "8.11.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-chai-friendly": "^0.7.2",
"eslint-plugin-compat": "^4.0.2",
"eslint-plugin-ecmalist": "^1.0.8",
"eslint-plugin-import": "2.25.4",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
Expand Down
5 changes: 2 additions & 3 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const CONFIG = {
};

// Load LCP image immediately
(async function loadLCPImage() {
(function loadLCPImage() {
const lcpImg = document.querySelector('img');
lcpImg?.removeAttribute('loading');
}());
Expand All @@ -136,9 +136,8 @@ const miloLibs = setLibs(LIBS);
}());

(async function loadPage() {
const { loadArea, loadDelayed, setConfig } = await import(`${miloLibs}/utils/utils.js`);
const { loadArea, setConfig } = await import(`${miloLibs}/utils/utils.js`);

setConfig({ ...CONFIG, miloLibs });
await loadArea();
loadDelayed();
}());
33 changes: 15 additions & 18 deletions scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,27 @@
* governing permissions and limitations under the License.
*/

/*
* ------------------------------------------------------------
* Edit below at your own risk
* ------------------------------------------------------------
*/

/**
* The decision engine for where to get Milo's libs from.
*/
export const [setLibs, getLibs] = (() => {
let libs;
return [
(prodLibs) => {
const { hostname } = window.location;
if (!hostname.includes('hlx.page')
&& !hostname.includes('hlx.live')
&& !hostname.includes('localhost')) {
libs = prodLibs;
return libs;
}
const branch = new URLSearchParams(window.location.search).get('milolibs') || 'main';
if (branch === 'local') return 'http://localhost:6456/libs';
if (branch.indexOf('--') > -1) return `https://${branch}.hlx.page/libs`;
return `https://${branch}--milo--adobecom.hlx.page/libs`;
(prodLibs, location) => {
libs = (() => {
const { hostname, search } = location || window.location;
if (!(hostname.includes('.hlx.') || hostname.includes('local'))) return prodLibs;
const branch = new URLSearchParams(search).get('milolibs') || 'main';
if (branch === 'local') return 'http://localhost:6456/libs';
return branch.includes('--') ? `https://${branch}.hlx.live/libs` : `https://${branch}--milo--adobecom.hlx.live/libs`;
})();
return libs;
}, () => libs,
];
})();

/*
* ------------------------------------------------------------
* Edit above at your own risk.
* ------------------------------------------------------------
*/
45 changes: 45 additions & 0 deletions test/scripts/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { expect } from '@esm-bundle/chai';
import { setLibs } from '../../scripts/utils.js';

describe('Libs', () => {
it('Default Libs', () => {
const libs = setLibs('/libs');
expect(libs).to.equal('https://main--milo--adobecom.hlx.live/libs');
});

it('Does not support milolibs query param on prod', () => {
const location = {
hostname: 'business.adobe.com',
search: '?milolibs=foo',
};
const libs = setLibs('/libs', location);
expect(libs).to.equal('/libs');
});

it('Supports milolibs query param', () => {
const location = {
hostname: 'localhost',
search: '?milolibs=foo',
};
const libs = setLibs('/libs', location);
expect(libs).to.equal('https://foo--milo--adobecom.hlx.live/libs');
});

it('Supports local milolibs query param', () => {
const location = {
hostname: 'localhost',
search: '?milolibs=local',
};
const libs = setLibs('/libs', location);
expect(libs).to.equal('http://localhost:6456/libs');
});

it('Supports forked milolibs query param', () => {
const location = {
hostname: 'localhost',
search: '?milolibs=awesome--milo--forkedowner',
};
const libs = setLibs('/libs', location);
expect(libs).to.equal('https://awesome--milo--forkedowner.hlx.live/libs');
});
});
54 changes: 48 additions & 6 deletions tools/sidekick/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,72 @@
"environments": [ "edit" ],
"isPalette": true,
"paletteRect": "top: auto; bottom: 20px; left: 20px; height: 398px; width: 360px;",
"url": "https://main--milo--adobecom.hlx.page/tools/library",
"url": "https://milo.adobe.com/tools/library",
"includePaths": [ "**.docx**" ]
},
{
"id": "translate",
"title": "Translate",
"environments": [ "edit" ],
"url": "https://milo.adobe.com/tools/translation/index.html",
"id": "tools",
"title": "Tools",
"isContainer": true
},
{
"containerId": "tools",
"id": "localize",
"title": "Localize",
"environments": [
"edit"
],
"url": "https://milo.adobe.com/tools/loc/index.html",
"passReferrer": true,
"include_paths": [ "**.xlsx**" ]
"passConfig": true,
"excludePaths": [ "/**" ],
"includePaths": [ "**/:x**" ]
},
{
"containerId": "tools",
"title": "Send to CaaS",
"id": "sendtocaas",
"environments": ["dev","preview", "live", "prod"],
"event": "send-to-caas",
"excludePaths": ["/tools/caas**", "*.json"]
},
{
"containerId": "tools",
"title": "Check Schema",
"id": "checkschema",
"environments": ["prod"],
"event": "check-schema",
"excludePaths": ["/tools**", "*.json"]
},
{
"containerId": "tools",
"title": "Preflight",
"id": "preflight",
"environments": ["dev","preview","live"],
"event": "preflight"
},
{
"containerId": "tools",
"id": "locales",
"title": "Locales",
"environments": [ "edit", "dev", "preview", "live" ],
"isPalette": true,
"passConfig": true,
"passReferrer": true,
"paletteRect": "top: auto; bottom: 25px; left: 75px; height: 388px; width: 360px;",
"url": "https://milo.adobe.com/tools/locale-nav",
"includePaths": [
"**.docx**"
]
},
{
"containerId": "tools",
"title": "Tag Selector",
"id": "tag-selector",
"environments": ["edit"],
"url": "https://milo.adobe.com/tools/tag-selector",
"isPalette": true,
"paletteRect": "top: 150px; left: 7%; height: 675px; width: 85vw;"
}
]
}
79 changes: 79 additions & 0 deletions web-test-runner.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* eslint-disable import/no-extraneous-dependencies */
import { importMapsPlugin } from '@web/dev-server-import-maps';
import { defaultReporter } from '@web/test-runner';

function customReporter() {
return {
async reportTestFileResults({ logger, sessionsForTestFile }) {
sessionsForTestFile.forEach((session) => {
session.testResults.tests.forEach((test) => {
if (!test.passed && !test.skipped) {
logger.log(test);
}
});
});
},
};
}
export default {
coverageConfig: {
exclude: [
'**/mocks/**',
'**/node_modules/**',
'**/test/**',
'**/deps/**',
],
},
plugins: [importMapsPlugin({})],
reporters: [
defaultReporter({ reportTestResults: true, reportTestProgress: true }),
customReporter(),
],
testRunnerHtml: (testFramework) => `
<html>
<head>
<script type='module'>
const oldFetch = window.fetch;
window.fetch = async (resource, options) => {
if (!resource.startsWith('/') && !resource.startsWith('http://localhost')) {
console.error(
'** fetch request for an external resource is disallowed in unit tests, please find a way to mock! https://github.com/orgs/adobecom/discussions/814#discussioncomment-6060759 provides guidance on how to fix the issue.',
resource
);
}
return oldFetch.call(window, resource, options);
};
const oldXHROpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = async function (...args) {
let [method, url, asyn] = args;
if (!resource.startsWith('/') && url.startsWith('http://localhost')) {
console.error(
'** XMLHttpRequest request for an external resource is disallowed in unit tests, please find a way to mock! https://github.com/orgs/adobecom/discussions/814#discussioncomment-6060759 provides guidance on how to fix the issue.',
url
);
}
return oldXHROpen.apply(this, args);
};
const observer = new MutationObserver((mutationsList, observer) => {
for(let mutation of mutationsList) {
if (mutation.type === 'childList') {
for(let node of mutation.addedNodes) {
if(node.nodeName === 'SCRIPT' && node.src && !node.src.startsWith('http://localhost')) {
console.error(
'** An external 3rd script has been added. This is disallowed in unit tests, please find a way to mock! https://github.com/orgs/adobecom/discussions/814#discussioncomment-6060891 provides guidance on how to fix the issue.',
node.src
);
}
}
}
}
});
observer.observe(document.head, { childList: true });
</script>
</head>
<body>
<script type='module' src='${testFramework}'></script>
</body>
</html>`,
};
14 changes: 0 additions & 14 deletions web-test-runner.config.mjs

This file was deleted.

0 comments on commit 1377b78

Please sign in to comment.