-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix-iotevents-alpha
- Loading branch information
Showing
90 changed files
with
30,296 additions
and
22,158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
packages/@aws-cdk-testing/framework-integ/test/aws-synthetics/test/canaries/canary.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { URL } from 'url'; | ||
import { synthetics } from '@amzn/synthetics-playwright'; | ||
|
||
const loadBlueprints = async function () { | ||
const urls = [process.env.URL]; | ||
|
||
const browser = await synthetics.launch(); | ||
const browserContext = await browser.newContext(); | ||
let page = await synthetics.newPage(browserContext); | ||
|
||
for (const url of urls) { | ||
await loadUrl(page, url); | ||
} | ||
|
||
// Ensure browser is closed | ||
await synthetics.close(); | ||
}; | ||
|
||
// Reset the page in-between | ||
const resetPage = async function(page) { | ||
try { | ||
// Set page.goto timeout to 30 seconds, adjust as needed | ||
// See https://playwright.dev/docs/api/class-page for page.goto options | ||
await page.goto('about:blank', { waitUntil: 'load', timeout: 30000 }); | ||
} catch (e) { | ||
console.error('Unable to open a blank page. ', e); | ||
} | ||
}; | ||
|
||
const loadUrl = async function (page, url) { | ||
let stepName = null; | ||
let domcontentloaded = false; | ||
|
||
try { | ||
stepName = new URL(url).hostname; | ||
} catch (e) { | ||
const errorString = `Error parsing url: ${url}. ${e}`; | ||
log.error(errorString); | ||
/* If we fail to parse the URL, don't emit a metric with a stepName based on it. | ||
It may not be a legal CloudWatch metric dimension name and we may not have an alarms | ||
setup on the malformed URL stepName. Instead, fail this step which will | ||
show up in the logs and will fail the overall canary and alarm on the overall canary | ||
success rate. | ||
*/ | ||
throw e; | ||
}; | ||
|
||
await synthetics.executeStep(stepName, async function () { | ||
try { | ||
/* You can customize the wait condition here. | ||
'domcontentloaded' - consider operation to be finished when the DOMContentLoaded event is fired. | ||
'load' - consider operation to be finished when the load event is fired. | ||
'networkidle' - DISCOURAGED consider operation to be finished when there are no network connections for at least 500 ms. Don't use this method for testing, rely on web assertions to assess readiness instead. | ||
'commit' - consider operation to be finished when network response is received and the document started loading. | ||
Set page.goto timeout to 30 seconds, adjust as needed | ||
See https://playwright.dev/docs/api/class-page for page.goto options | ||
*/ | ||
const response = await page.goto(url, { waitUntil: 'load', timeout: 30000 }); | ||
if (response) { | ||
domcontentloaded = true; | ||
const status = response.status(); | ||
console.log(`Response status: ${status}`); | ||
|
||
// If the response status code is not a 2xx success code | ||
if (status < 200 || status > 299) { | ||
console.error(`Failed to load url: ${url}, status code: ${status}`); | ||
throw new Error('Failed'); | ||
} | ||
} else { | ||
console.error(`No response returned for url: ${url}`); | ||
throw new Error(logNoResponseString); | ||
} | ||
} catch (e) { | ||
const errorString = `Error navigating to url: ${url}. ${e}`; | ||
console.error(errorString); | ||
throw e; | ||
} | ||
}); | ||
|
||
// Reset page | ||
await resetPage(page); | ||
}; | ||
|
||
export const handler = async (event, context) => { | ||
return await loadBlueprints(); | ||
}; |
87 changes: 87 additions & 0 deletions
87
.../@aws-cdk-testing/framework-integ/test/aws-synthetics/test/canaries/playwright/canary.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { URL } from 'url'; | ||
import { synthetics } from '@amzn/synthetics-playwright'; | ||
|
||
const loadBlueprints = async function () { | ||
const urls = [process.env.URL]; | ||
|
||
const browser = await synthetics.launch(); | ||
const browserContext = await browser.newContext(); | ||
let page = await synthetics.newPage(browserContext); | ||
|
||
for (const url of urls) { | ||
await loadUrl(page, url); | ||
} | ||
|
||
// Ensure browser is closed | ||
await synthetics.close(); | ||
}; | ||
|
||
// Reset the page in-between | ||
const resetPage = async function(page) { | ||
try { | ||
// Set page.goto timeout to 30 seconds, adjust as needed | ||
// See https://playwright.dev/docs/api/class-page for page.goto options | ||
await page.goto('about:blank', { waitUntil: 'load', timeout: 30000 }); | ||
} catch (e) { | ||
console.error('Unable to open a blank page. ', e); | ||
} | ||
}; | ||
|
||
const loadUrl = async function (page, url) { | ||
let stepName = null; | ||
let domcontentloaded = false; | ||
|
||
try { | ||
stepName = new URL(url).hostname; | ||
} catch (e) { | ||
const errorString = `Error parsing url: ${url}. ${e}`; | ||
log.error(errorString); | ||
/* If we fail to parse the URL, don't emit a metric with a stepName based on it. | ||
It may not be a legal CloudWatch metric dimension name and we may not have an alarms | ||
setup on the malformed URL stepName. Instead, fail this step which will | ||
show up in the logs and will fail the overall canary and alarm on the overall canary | ||
success rate. | ||
*/ | ||
throw e; | ||
}; | ||
|
||
await synthetics.executeStep(stepName, async function () { | ||
try { | ||
/* You can customize the wait condition here. | ||
'domcontentloaded' - consider operation to be finished when the DOMContentLoaded event is fired. | ||
'load' - consider operation to be finished when the load event is fired. | ||
'networkidle' - DISCOURAGED consider operation to be finished when there are no network connections for at least 500 ms. Don't use this method for testing, rely on web assertions to assess readiness instead. | ||
'commit' - consider operation to be finished when network response is received and the document started loading. | ||
Set page.goto timeout to 30 seconds, adjust as needed | ||
See https://playwright.dev/docs/api/class-page for page.goto options | ||
*/ | ||
const response = await page.goto(url, { waitUntil: 'load', timeout: 30000 }); | ||
if (response) { | ||
domcontentloaded = true; | ||
const status = response.status(); | ||
console.log(`Response status: ${status}`); | ||
|
||
// If the response status code is not a 2xx success code | ||
if (status < 200 || status > 299) { | ||
console.error(`Failed to load url: ${url}, status code: ${status}`); | ||
throw new Error('Failed'); | ||
} | ||
} else { | ||
console.error(`No response returned for url: ${url}`); | ||
throw new Error(logNoResponseString); | ||
} | ||
} catch (e) { | ||
const errorString = `Error navigating to url: ${url}. ${e}`; | ||
console.error(errorString); | ||
throw e; | ||
} | ||
}); | ||
|
||
// Reset page | ||
await resetPage(page); | ||
}; | ||
|
||
export const handler = async (event, context) => { | ||
return await loadBlueprints(); | ||
}; |
2 changes: 1 addition & 1 deletion
2
...fact-s3-encryption.js.snapshot/IntegCanaryTestDefaultTestDeployAssert3AD5A094.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
...napshot/asset.5178413cfe8db00b2d5dcfa9be417e934c64601d0da3031d88c145c8293bc27f/canary.mjs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.