1+ /**
2+ * Documentation page: https://www.stormkit.io/docs/deployments/status-checks
3+ *
4+ * 1. Visit https://app.stormkit.io
5+ * 2. Go to **Your App** > **Your environment** > **Status Checks**
6+ * 3. Add a new status check with the following command: npm run test:puppeeter
7+ *
8+ * Every time Stormkit will deploy your application, it will run this script
9+ * and publish the deployment only if this test passes.
10+ */
11+
112import puppeteer from "puppeteer" ;
213
314const endpoint = process . env . SK_DEPLOYMENT_URL ;
@@ -10,12 +21,34 @@ if (!endpoint) {
1021 const browser = await puppeteer . launch ( ) ;
1122 const page = await browser . newPage ( ) ;
1223
13- // Set viewport width and height
24+ // Set viewport width and height (no need in reality, just here for an example)
1425 await page . setViewport ( { width : 1280 , height : 720 } ) ;
1526
1627 await page . goto ( endpoint , { waitUntil : "networkidle0" } ) ;
28+
29+ // Should click on the `Click to see` button
30+ await page . locator ( "text/Click to see" ) . click ( ) ;
31+
32+ // Then we should receive an API response with an example data
33+ const apiResponseWrapper = await page . waitForSelector ( ".cm-content" , {
34+ timeout : 5000 ,
35+ } ) ;
36+
37+ await page . waitForSelector ( "text/https://www.stormkit.io/docs/writing-apis" , {
38+ timeout : 5000 ,
39+ } ) ;
40+
41+ const apiResponse = await apiResponseWrapper . evaluate ( ( el ) => el . textContent ) ;
42+
43+ // Finally close the browser
1744 await browser . close ( ) ;
1845
19- console . log ( "Worked!" ) ;
46+ console . log ( "API Response:\n" ) ;
47+
48+ // This should be a JSON response
49+ console . log ( JSON . parse ( apiResponse ) ) ;
50+
51+ console . log ( "\nSuccess 🎉" ) ;
52+
2053 process . exit ( 0 ) ;
2154} ) ( ) ;
0 commit comments