Skip to content

Commit 084183b

Browse files
committed
chore: improve puppeeter tests
1 parent 304e9cb commit 084183b

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"test": "react-scripts test",
1010
"eject": "react-scripts eject",
1111
"dev:api": "stormkit api",
12-
"e2e": "ts-node scripts/e2e.ts",
13-
"puppeteer": "ts-node scripts/puppeteer.ts"
12+
"test:smoke": "ts-node scripts/smoke.ts",
13+
"test:puppeeter": "ts-node scripts/puppeteer.ts"
1414
},
1515
"eslintConfig": {
1616
"extends": [

scripts/puppeteer.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
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+
112
import puppeteer from "puppeteer";
213

314
const 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

Comments
 (0)