Skip to content

Commit

Permalink
Make tests sequential to try to fix issues in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
tonidero committed Jan 18, 2024
1 parent f1296b9 commit 9337c1e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 48 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,5 @@ jobs:
- task: PublishPipelineArtifact@1
condition: always()
inputs:
targetPath: $(System.DefaultWorkingDirectory)/examples/rcbilling-demo
targetPath: $(System.DefaultWorkingDirectory)/examples/rcbilling-demo/artifacts
artifactName: screenshot.png
Binary file added examples/rcbilling-demo/artifacts/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 49 additions & 47 deletions examples/rcbilling-demo/src/tests/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,60 @@
import { beforeAll, expect, test } from "vitest";
import { beforeAll, describe, expect, test } from "vitest";
import puppeteer, { Browser, ElementHandle, Frame, Page } from "puppeteer";

const _LOCAL_URL = "http://0.0.0.0:3001/";
const _CARD_CLASS = ".card";

beforeAll(() => {
expect(import.meta.env.VITE_RC_API_KEY).not.toBeNull();
expect(import.meta.env.VITE_RC_STRIPE_PK_KEY).not.toBeNull();
expect(import.meta.env.VITE_RC_STRIPE_ACCOUNT_ID).not.toBeNull();
});

test("Get offerings displays packages", async () => {
const { browser, page } = await setupTest();
const packageCards = await getPackageCards(page);
expect(packageCards.length).toEqual(3);
await expectElementContainsText(packageCards[0], "3.00 USD");
await expectElementContainsText(packageCards[1], "9.99 USD");
await expectElementContainsText(packageCards[2], "19.99 USD");
await browser.close();
});
describe.sequential("E2E tests", () => {
beforeAll(() => {
expect(import.meta.env.VITE_RC_API_KEY).not.toBeNull();
expect(import.meta.env.VITE_RC_STRIPE_PK_KEY).not.toBeNull();
expect(import.meta.env.VITE_RC_STRIPE_ACCOUNT_ID).not.toBeNull();
});

test(
"Can purchase a product",
async () => {
test("Get offerings displays packages", async () => {
const { browser, page } = await setupTest();
const userId = `rc_billing_demo_test_${Date.now()}`;
await changeUserId(page, userId);

// Perform purchase
const weeklyPackageCard = (await getPackageCards(page))[1];
await weeklyPackageCard.click();
await enterEmailAndContinue(page, userId);
await waitMilliseconds(2000);
await enterCreditCardDetailsAndContinue(page);
await waitMilliseconds(2000);

// Go back to main page
const rcbRoot = await page.$(".rcb-ui-root");
expect(rcbRoot).not.toBeNull();
await page.screenshot({ path: "screenshot.png" });
// await expectElementContainsText(rcbRoot!, "Purchase Successful");
// const returnHomeButton = await rcbRoot?.$(".intent-secondary");
// expect(returnHomeButton).not.toBeNull();
// await returnHomeButton?.click();
// await page.waitForNavigation();
//
// // Needed since there is an animation after tapping on the button
// // to go back to main page.
// await waitMilliseconds(5000);
// expect(await page.$(`::-p-text(Success!)`)).not.toBeNull();
const packageCards = await getPackageCards(page);
expect(packageCards.length).toEqual(3);
await expectElementContainsText(packageCards[0], "3.00 USD");
await expectElementContainsText(packageCards[1], "9.99 USD");
await expectElementContainsText(packageCards[2], "19.99 USD");
await browser.close();
},
{ timeout: 30000, retry: 3 },
);
});

test(
"Can purchase a product",
async () => {
const { browser, page } = await setupTest();
const userId = `rc_billing_demo_test_${Date.now()}`;
await changeUserId(page, userId);

// Perform purchase
const weeklyPackageCard = (await getPackageCards(page))[1];
await weeklyPackageCard.click();
await enterEmailAndContinue(page, userId);
await waitMilliseconds(2000);
await enterCreditCardDetailsAndContinue(page);
await waitMilliseconds(2000);

// Go back to main page
const rcbRoot = await page.$(".rcb-ui-root");
expect(rcbRoot).not.toBeNull();
await page.screenshot({ path: "artifacts/screenshot.png" });
// await expectElementContainsText(rcbRoot!, "Purchase Successful");
// const returnHomeButton = await rcbRoot?.$(".intent-secondary");
// expect(returnHomeButton).not.toBeNull();
// await returnHomeButton?.click();
// await page.waitForNavigation();
//
// // Needed since there is an animation after tapping on the button
// // to go back to main page.
// await waitMilliseconds(5000);
// expect(await page.$(`::-p-text(Success!)`)).not.toBeNull();
await browser.close();
},
{ timeout: 30000, retry: 3 },
);
});

async function setupTest(): Promise<{ browser: Browser; page: Page }> {
const browser = await puppeteer.launch({
Expand Down

0 comments on commit 9337c1e

Please sign in to comment.