-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CM-1017][CM-986] feat: Simplify widget e2e (#2346)
- Loading branch information
1 parent
a48865d
commit d72a01a
Showing
25 changed files
with
589 additions
and
39 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
29 changes: 29 additions & 0 deletions
29
examples/checkout/sdk-load-widgets-with-nextjs/tests/utils/intercept-checkout-config.ts
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,29 @@ | ||
import { Page } from "@playwright/test"; | ||
|
||
export type CheckoutVersionConfig = { | ||
compatibleVersionMarkers: string[]; | ||
}; | ||
|
||
export const interceptCheckoutVersionConfig = async (page: Page, checkoutWidgetsVersion: CheckoutVersionConfig) => { | ||
return page.route('https://checkout-api.sandbox.immutable.com/v1/config', async (route) => { | ||
const response = await route.fetch(); | ||
const json = await response.json(); | ||
|
||
// Modify the compatibleVersionMarkers | ||
json.checkoutWidgetsVersion = checkoutWidgetsVersion; | ||
|
||
// Fulfill the request with the modified JSON | ||
await route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify(json), | ||
}); | ||
|
||
console.log(` | ||
Checkout config successfully intercepted: | ||
Request: ${route.request().url()} | ||
Modified: checkoutWidgetsVersion = ${JSON.stringify(checkoutWidgetsVersion)} | ||
------------------------------ | ||
`); | ||
}); | ||
}; |
13 changes: 13 additions & 0 deletions
13
examples/checkout/sdk-load-widgets-with-nextjs/tests/version.spec.ts
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
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 @@ | ||
NEXT_PUBLIC_PUBLISHABLE_KEY= |
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,4 @@ | ||
{ | ||
"root": true, | ||
"extends": "next/core-web-vitals" | ||
} |
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,39 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
.yarn/install-state.gz | ||
|
||
# testing | ||
/coverage | ||
/tests/utils/local-widgets-js | ||
/playwright-report/ | ||
/test-results | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
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,66 @@ | ||
# Checkout SDK Widgets Auto Updating Testing | ||
|
||
This test covers autoupdating of the Checkout SDK's Widgets. | ||
See https://immutable.atlassian.net/wiki/spaces/PR/pages/2796814550/Checkout+Widgets+Auto-Updating+Docs | ||
|
||
## Getting Started | ||
|
||
Install your dependencies: | ||
|
||
```bash | ||
yarn install | ||
``` | ||
|
||
Copy over the `.env.example` file to `.env` and fill in the required environment variables. | ||
|
||
## Required Environment Variables | ||
|
||
- NEXT_PUBLIC_PUBLISHABLE_KEY // replace with your publishable API key from Hub | ||
|
||
## Running locally | ||
|
||
```bash | ||
yarn dev | ||
``` | ||
|
||
## E2E Testing | ||
|
||
There are tests covering the auto updating of the Checkout Widget. | ||
|
||
Build the app: | ||
|
||
```bash | ||
yarn build | ||
``` | ||
|
||
Run tests with latest compatible remote bundle of the widgets: | ||
|
||
```bash | ||
yarn test:remotewidgets | ||
``` | ||
|
||
To run these tests using a local bundle of the widgets, first build the entire Checkout SDK from the root of `ts-immutable-sdk`: | ||
|
||
```bash | ||
yarn build | ||
``` | ||
|
||
Copy over the created widgets bundle to use for testing: | ||
|
||
```bash | ||
yarn workspace @examples/sdk-load-widgets-with-nextjs prepare:widgets | ||
``` | ||
|
||
Run tests against the local bundle: | ||
|
||
```bash | ||
yarn test | ||
``` | ||
|
||
### Validating Widget Breaking Changes | ||
|
||
We can inject a Checkout Widgets Version Config into the app to validate auto updating. | ||
|
||
```bash | ||
INTERCEPT_CHECKOUT_VERSION_CONFIG=1.58.0 yarn workspace @examples/sdk-load-widgets-with-nextjs test | ||
``` |
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,4 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {}; | ||
|
||
export default nextConfig; |
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,31 @@ | ||
{ | ||
"name": "@tests/checkout-widgets-nextjs", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "next dev", | ||
"build": "next build", | ||
"start": "next start", | ||
"lint": "next lint", | ||
"func-test:ci": "playwright test", | ||
"test:ui": "playwright test --ui", | ||
"test:remotewidgets": "USE_REMOTE_WIDGETS=true playwright test" | ||
}, | ||
"dependencies": { | ||
"@biom3/react": "^0.25.21", | ||
"@ethersproject/providers": "^5.7.2", | ||
"@imtbl/sdk": "latest", | ||
"next": "14.2.7", | ||
"react": "^18", | ||
"react-dom": "^18" | ||
}, | ||
"devDependencies": { | ||
"@playwright/test": "^1.45.3", | ||
"@types/node": "^20", | ||
"@types/react": "^18.3.4", | ||
"@types/react-dom": "^18.3.0", | ||
"eslint": "^8", | ||
"eslint-config-next": "14.2.7", | ||
"typescript": "^5.6.2" | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
tests/func-tests/checkout/widgets-nextjs/playwright.config.ts
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,30 @@ | ||
import { defineConfig, devices } from "@playwright/test"; | ||
|
||
export default defineConfig({ | ||
testDir: "./tests", | ||
fullyParallel: true, | ||
forbidOnly: !!process.env.CI, | ||
retries: process.env.CI ? 2 : 0, | ||
workers: "80%", | ||
reporter: "html", | ||
|
||
use: { | ||
baseURL: "http://localhost:3000", | ||
trace: "on-first-retry", | ||
}, | ||
|
||
projects: [ | ||
{ name: "chromium", use: { ...devices["Desktop Chrome"] } }, | ||
{ name: "firefox", use: { ...devices["Desktop Firefox"] } }, | ||
{ name: "webkit", use: { ...devices["Desktop Safari"] } }, | ||
|
||
{ name: "Mobile Chrome", use: { ...devices["Pixel 5"] } }, | ||
{ name: "Mobile Safari", use: { ...devices["iPhone 12"] } }, | ||
], | ||
|
||
webServer: { | ||
command: "yarn start", | ||
url: "http://localhost:3000", | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}); |
Binary file not shown.
18 changes: 18 additions & 0 deletions
18
tests/func-tests/checkout/widgets-nextjs/src/app/globals.css
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,18 @@ | ||
html, body { | ||
height: 100%; | ||
} | ||
body { | ||
margin: 0; | ||
} | ||
.flex-container { | ||
height: 100%; | ||
padding: 0; | ||
margin: 0; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.mb-1 { | ||
margin-bottom: 1rem; | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/func-tests/checkout/widgets-nextjs/src/app/layout.tsx
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,26 @@ | ||
import type { Metadata } from "next"; | ||
import { Inter } from "next/font/google"; | ||
import "./globals.css"; | ||
import AppWrapper from "./utils/wrapper"; | ||
const inter = Inter({ subsets: ["latin"] }); | ||
|
||
export const metadata: Metadata = { | ||
title: "Checkout SDK - Load and Mount Widgets", | ||
description: "Examples of how mount Checkout SDK Widgets", | ||
}; | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: Readonly<{ | ||
children: React.ReactNode; | ||
}>) { | ||
return ( | ||
<html lang="en"> | ||
<body className={inter.className}> | ||
<AppWrapper> | ||
{children} | ||
</AppWrapper> | ||
</body> | ||
</html> | ||
); | ||
} |
Oops, something went wrong.