Skip to content

Commit

Permalink
add additional rejection check on links
Browse files Browse the repository at this point in the history
  • Loading branch information
mwood77 committed Feb 11, 2024
1 parent ddf4bf0 commit 29281aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/selenium-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ jobs:
with:
node-version: 19

- uses: abhi1693/setup-browser@v0.3.4
with:
browser: firefox

# Install some selenium dependencies...
- run: |
apt-get update -y &&
Expand All @@ -47,5 +43,13 @@ jobs:
chmod +x /usr/local/bin/geckodriver &&
rm geckodriver-v0.31.0-linux64.tar.gz
# Install and setup Firefox
- run: |
FIREFOX_SETUP=firefox-setup.tar.bz2 &&
wget -O $FIREFOX_SETUP "https://download.mozilla.org/?product=firefox-95.0.1&os=linux64" &&
tar xjf $FIREFOX_SETUP -C /opt/ &&
ln -s /opt/firefox/firefox /usr/bin/firefox &&
rm $FIREFOX_SETUP
- run: npm i selenium-webdriver
- run: npx node .github/workflows/test-ali-links.mjs
11 changes: 9 additions & 2 deletions .github/workflows/test-ali-links.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ const content = async(file) => {

const search = async (item) => {
await driver.get('https://s.click.aliexpress.com/e/_' + item);
return await driver.findElements(By.className('not-found-page'))
let notFound = await driver.findElements(By.className('not-found-page')) // Product not found
let homepage = await driver.findElements(By.className('new-affiliate')) // Link points to homepage
const results = await Promise.all([notFound, homepage])

return results.flat(Infinity);
}

content(bomDocument)
.then(
result => {
const sanitizedMD = result.split('/_')
sanitizedMD.shift(); // remove stuff that doesn't include links
// remove stuff that doesn't include links
sanitizedMD.shift();
sanitizedMD.forEach((el) => {
links.push(el.split(')')[0])
})
Expand All @@ -38,6 +43,8 @@ content(bomDocument)
links.every(async el => {
const result = await search(el);

console.log(result)

if (result.length > 0) {
throw new Error(`product ${el} is a broken link`, content)
}
Expand Down

0 comments on commit 29281aa

Please sign in to comment.