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

re add action to check for console errors #6471

Merged
merged 43 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
60742c1
re add action to check for console errors
Nov 17, 2023
a51f02d
add get sitemap links script
Nov 17, 2023
a77f4d2
update console error scripts
Nov 21, 2023
91b29d7
remove http-server action and using python server instead
Nov 27, 2023
1373951
revert change to pr broken links action
Nov 27, 2023
4c0f64f
use LOCALHOST constant
Dec 7, 2023
2f9d1ba
check console errors
Mar 18, 2024
7b5f536
upgrade node
Mar 18, 2024
8b69a08
upgrade github-script
Mar 18, 2024
ce5c996
update
Mar 18, 2024
f95d8ef
change filetype to .mjs
Mar 18, 2024
8462d68
fix reference
Mar 18, 2024
ac39c68
.
Mar 18, 2024
ca6f708
working
Mar 18, 2024
fe5a0ea
.
Mar 18, 2024
b1b93fa
back to js
Mar 18, 2024
99a9fe0
.
Mar 18, 2024
995664c
catch error
Mar 18, 2024
728f895
catch up main and add catch
Mar 18, 2024
cccc5f3
merge conflicts
Mar 18, 2024
9f6d2b2
.
Mar 18, 2024
81111e8
upgrade checkout script
Mar 18, 2024
4b3907d
upgrade checkout script
Mar 18, 2024
0fa1907
run on prod build, exclude addtl marketing script
Mar 21, 2024
2eb5893
exclude more scripts
Mar 21, 2024
af5cb40
.
Mar 26, 2024
d1e40b9
.
Mar 26, 2024
3e3fa82
remove image
Mar 26, 2024
3c0fb3e
add photo back in
Mar 26, 2024
96605ed
change name of problem image
Mar 27, 2024
12c29e8
change filename
Mar 27, 2024
4d43e60
trying more specific script
Apr 1, 2024
039d35d
catching up to remote
Apr 1, 2024
4e013dd
un-specifiy
Apr 1, 2024
71c675b
Merge branch 'main' into new-console-script
Apr 25, 2024
79f965d
comment resolutions
Apr 25, 2024
7c96cf3
removing check in console event
Apr 25, 2024
7a510ab
removing check in console event
Apr 25, 2024
1ecc4de
removing check in console event
Apr 25, 2024
683818f
back to check if working
Apr 25, 2024
7d50cd4
retrying adjustments
Apr 26, 2024
a6422b7
put it back
Apr 26, 2024
16f9302
move error message
Apr 30, 2024
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
/src/themes @aws-amplify/documentation-team
/src/utils @aws-amplify/documentation-team
/tasks @aws-amplify/documentation-team
.github @aws-amplify/documentation-team

#Protected Content
/src/protected @reesscot @srquinn21 @Milan-Shah @swaminator
38 changes: 38 additions & 0 deletions .github/workflows/check_for_console_errors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CheckConsoleErrors
on:
pull_request:
branches: [main]
types: [opened, synchronize]
permissions:
contents: read
jobs:
CheckConsoleErrors:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2 https://github.com/actions/checkout/commit/b4ffde65f46336ab88eb53be808477a3936bae11
- name: Setup Node.js 20.x
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0 https://github.com/actions/setup-node/commit/e33196f7422957bea03ed53f6fbb155025ffc7b8
with:
node-version: 20.x
- name: Install Dependencies
run: yarn
- name: Run Build
run: yarn build:release
env:
NODE_OPTIONS: --max_old_space_size=4096
- name: Run Server
run: |
python -m http.server 3000 -d ${{ vars.BUILD_DIR }} &
sleep 5
- name: Run Console Errors
id: consoleErrors
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 https://github.com/actions/github-script/commit/d7906e4ad0b1822421a7e6a35d5ca353c962f410
with:
result-encoding: string
script: |
const { consoleErrors } = require('./tasks/console-errors.js');
return await consoleErrors();
- name: Fail if console errors have been found
if: ${{ steps.consoleErrors.outputs.result }}
run: exit 1
2 changes: 1 addition & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@
"privatesaccess",
"menudetaileditors",
"editorgroupaccess",
"publicauthreadonly",
"authreadonly",
"envs",
"Onetoone",
"onetomany",
Expand Down
katiegoines marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ describe('BlockSwitcher', () => {
const blockSwitcher = await screen.findByText(blockAContent);
expect(blockSwitcher).toBeInTheDocument();
});

it('should have more than one Block', async () => {
render(component);
expect(component.props.children.length).toBeGreaterThan(1);
});

it('should show the first Block as default', async () => {
render(component);
const tabs = await screen.getAllByRole('tab');
Expand All @@ -39,7 +39,7 @@ describe('BlockSwitcher', () => {
expect(panels[1]).not.toHaveClass('amplify-tabs__panel--active');
expect(panels[2]).not.toHaveClass('amplify-tabs__panel--active');
});

it('should load all Blocks to the DOM', async () => {
render(component);
const blockA = await screen.findByText(blockAContent);
Expand All @@ -49,7 +49,7 @@ describe('BlockSwitcher', () => {
expect(blockB).toBeInTheDocument();
expect(blockC).toBeInTheDocument();
});

it('should switch tabs upon click', async () => {
render(component);
const tabs = await screen.getAllByRole('tab');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ If you want your data model to be publicly accessible, switch to API_KEY or IAM
1. Using the *Books* data model that you created in the [Create a data model example](/[platform]/tools/console/data/data-model/#Create-a-data-model-example), set the authorization mode to **API Key**.
2. In the **Model** pane on the right, expand the **Anyone** window. Choose **Read** to specify that any signed in user has read access to the data in the *Book* model.

![](/images/console/7_publicauthreadonly.png)
![](/images/console/7_authreadonly.png)
107 changes: 107 additions & 0 deletions tasks/console-errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
const puppeteer = require('puppeteer'); // eslint-disable-line
const { getSitemapUrls } = require('./get-sitemap-links'); // eslint-disable-line

// Here we are excluding shortbread errors because these are domain specific and are expected to fail in a local environment
const excludedErrors = [
{
type: 'Shortbread',
errorText:
"Shortbread failed to set user's cookie preference because the domain name that was passed"
jacoblogan marked this conversation as resolved.
Show resolved Hide resolved
}
];

const excludedScripts = [
'prod.assets.shortbread.aws',
'prod.tools.shortbread.aws',
'prod.tools.shortbread.aws.dev',
'aa0.awsstatic.com',
'alpha.d2c.marketing.aws.dev',
'vs-alpha.aws.amazon.com'
];

const LOCALHOST = 'http://localhost:3000';

const checkPage = async (url) => {
const errorsFound = [];
const browser = await puppeteer.launch({ headless: 'new' });

const page = await browser.newPage();

await page.setRequestInterception(true);

page
.on('pageerror', (message) => {
const errorText = message.message;
const excluded = excludedErrors.some((excludedError) => {
return errorText.includes(excludedError.errorText);
});

if (!excluded) {
errorsFound.push({
page: url,
message: errorText
});
}
})
.on('console', (message) => {
katiegoines marked this conversation as resolved.
Show resolved Hide resolved
if (message.type().toLowerCase() === 'error') {
const errorText = message.text();
const callingScript = message.location().url;
const excludedFromError = excludedErrors.some((excludedError) => {
return errorText.includes(excludedError.errorText);
});
const excludedFromScript = excludedScripts.some((excludedScript) => {
return callingScript.includes(excludedScript);
});
const excluded = excludedFromError || excludedFromScript;

if (!excluded) {
errorsFound.push({
page: url,
message: errorText,
stackTrace: message.stackTrace()
});
}
}
})

.on('request', (interceptedRequest) => {
const excludedFromScript = excludedScripts.some((excludedScript) => {
return interceptedRequest.url().includes(excludedScript);
});
if (excludedFromScript) {
interceptedRequest.abort();
} else interceptedRequest.continue();
});
katiegoines marked this conversation as resolved.
Show resolved Hide resolved

await page.goto(url, { waitUntil: 'domcontentloaded' });

await browser.close();

return errorsFound;
katiegoines marked this conversation as resolved.
Show resolved Hide resolved
};

const consoleErrors = async (domain) => {
const pagesToCheck = await getSitemapUrls(domain);
let errorMessage = '';
for (let i = 0; i < pagesToCheck.length; i++) {
const url = pagesToCheck[i];
console.log(`checking page ${url}`);
const errorsFound = await checkPage(url);
errorsFound.forEach((error) => {
errorMessage += `${error.message} found on ${error.page}\n`;
});
}
console.log(
`--------- Console errors have been found and need to be resolved in order to merge. -------
------- Please note that these errors could be on pages that were not edited in this PR. ---------`
);
Copy link
Member

@timngyn timngyn Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we only print these console logs if there are error messages? I guess we could also put the console.log(errorMessage) in this if check as well

console.log(errorMessage);
return errorMessage;
};

module.exports = {
consoleErrors: async (domain = LOCALHOST) => {
return await consoleErrors(domain);
}
};
42 changes: 42 additions & 0 deletions tasks/get-sitemap-links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const puppeteer = require('puppeteer'); // eslint-disable-line

const DOMAIN = 'https://docs.amplify.aws';
const SITEMAP_URL = 'https://docs.amplify.aws/sitemap.xml';

const getSitemapUrls = async (localDomain) => {
let browser = await puppeteer.launch({ headless: 'new' });

const page = await browser.newPage();

let siteMap = localDomain ? `${localDomain}/sitemap.xml` : SITEMAP_URL;
let response = await page.goto(siteMap);

const siteMapUrls = [];

if (response && response.status() && response.status() === 200) {
const urlTags = await page.evaluateHandle(() => {
return document.getElementsByTagName('loc');
});
const numOfLinks = await page.evaluate((e) => e.length, urlTags);
for (let i = 0; i < numOfLinks; i++) {
let url = await page.evaluate(
(urlTags, i) => urlTags[i].innerHTML,
urlTags,
i
);
if (localDomain) {
// Currently the sitemap is always generated with the prod docs domain so we need to replace this with localhost
url = url.replace(DOMAIN, localDomain);
}
siteMapUrls.push(url);
}
}
browser.close();
return siteMapUrls;
};

module.exports = {
getSitemapUrls: async (domain) => {
return await getSitemapUrls(domain);
}
};
Loading