feat: Add Checkly configuration and Playwright tests (#2351)
* feat: Add Checkly configuration and Playwright tests * test: remove unused test files
This commit is contained in:
@@ -32,15 +32,11 @@ jobs:
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
cache: "pnpm"
|
||||
# for testing we're also gonna setup bun
|
||||
- name: Install bun
|
||||
uses: oven-sh/setup-bun@v1
|
||||
|
||||
- name: Run CI
|
||||
run: |
|
||||
pnpm install
|
||||
pnpm lint
|
||||
pnpm test
|
||||
env:
|
||||
PAYMENTS_ADMIN_SECRET: ${{ secrets.PAYMENTS_ADMIN_SECRET }}
|
||||
NEXT_PUBLIC_PAYMENTS_API: ${{ vars.NEXT_PUBLIC_PAYMENTS_API }}
|
||||
|
||||
@@ -77,3 +77,7 @@ future_app/
|
||||
graphql/generated.ts
|
||||
# Sentry Config File
|
||||
.sentryclirc
|
||||
/test-results/
|
||||
/playwright-report/
|
||||
/blob-report/
|
||||
/playwright/.cache/
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { defineConfig } from "checkly";
|
||||
import { Frequency } from "checkly/constructs";
|
||||
|
||||
export default defineConfig({
|
||||
projectName: "thirdweb.com",
|
||||
logicalId: "thirdweb-www",
|
||||
repoUrl: "https://github.com/thirdweb-dev/dashboard",
|
||||
checks: {
|
||||
activated: true,
|
||||
muted: false,
|
||||
runtimeId: "2023.09",
|
||||
frequency: Frequency.EVERY_24H,
|
||||
locations: ["us-east-1", "eu-west-1"],
|
||||
tags: ["website"],
|
||||
checkMatch: "./**/*.check.ts",
|
||||
ignoreDirectoriesMatch: [],
|
||||
playwrightConfig: {
|
||||
use: {
|
||||
baseURL: process.env.ENVIRONMENT_URL || "https://thirdweb.com",
|
||||
},
|
||||
},
|
||||
browserChecks: {
|
||||
frequency: Frequency.EVERY_24H,
|
||||
testMatch: "./tests/**/*.spec.ts",
|
||||
},
|
||||
},
|
||||
cli: {
|
||||
runLocation: "eu-west-1",
|
||||
},
|
||||
});
|
||||
@@ -1,29 +0,0 @@
|
||||
/**
|
||||
* @jest-environment node
|
||||
*/
|
||||
|
||||
import { prettyPrintCurrency } from "../utils";
|
||||
|
||||
describe("prettyPrintCurrency", () => {
|
||||
it("Given undefined amount", () => {
|
||||
const actual = prettyPrintCurrency({
|
||||
amount: undefined,
|
||||
symbol: "MATIC",
|
||||
});
|
||||
expect(actual).toEqual("0.000000 MATIC");
|
||||
});
|
||||
it("Given string amount", () => {
|
||||
const actual = prettyPrintCurrency({
|
||||
amount: "0.1234",
|
||||
symbol: "MATIC",
|
||||
});
|
||||
expect(actual).toEqual("0.123400 MATIC");
|
||||
});
|
||||
it("Given number amount", () => {
|
||||
const actual = prettyPrintCurrency({
|
||||
amount: 0.12345678,
|
||||
symbol: "MATIC",
|
||||
});
|
||||
expect(actual).toEqual("0.123457 MATIC");
|
||||
});
|
||||
});
|
||||
@@ -1,133 +0,0 @@
|
||||
/**
|
||||
* @jest-environment node
|
||||
*/
|
||||
|
||||
import { ZodError } from "zod";
|
||||
import { apiKeyValidationSchema } from "./validations";
|
||||
|
||||
describe("apiKeyValidationSchema", () => {
|
||||
const validApiKey = {
|
||||
name: "Api Key Name",
|
||||
domains: "example.com",
|
||||
bundleIds: "com.example.app",
|
||||
redirectUrls: "thirdweb://",
|
||||
};
|
||||
|
||||
it("is valid", () => {
|
||||
const result = apiKeyValidationSchema.safeParse(validApiKey);
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
describe("domains", () => {
|
||||
it("is valid with comma separated fqdns", () => {
|
||||
const result = apiKeyValidationSchema.safeParse({
|
||||
...validApiKey,
|
||||
domains: "example.com, foo.bar.com, thirdweb.com",
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it("is valid with comma and new-line separated fqdns", () => {
|
||||
const result = apiKeyValidationSchema.safeParse({
|
||||
...validApiKey,
|
||||
domains: "example.com\nfoo.bar.com, thirdweb.com",
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it("is valid with port", () => {
|
||||
const result = apiKeyValidationSchema.safeParse({
|
||||
...validApiKey,
|
||||
domains: "example.com:3000, foo.bar.com, thirdweb.com:8888",
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it("is valid with localhost", () => {
|
||||
const result = apiKeyValidationSchema.safeParse({
|
||||
...validApiKey,
|
||||
domains: "localhost, localhost:3000, thirdweb.com",
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it("is invalid with invalid fqdn", () => {
|
||||
const result = apiKeyValidationSchema.safeParse({
|
||||
...validApiKey,
|
||||
domains: "google",
|
||||
});
|
||||
const zError = (result as any).error as ZodError;
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
expect(zError.errors[0].message).toBe("Some of the domains are invalid");
|
||||
});
|
||||
});
|
||||
|
||||
describe("bundle ids", () => {
|
||||
it("is valid with comma separated ids", () => {
|
||||
const result = apiKeyValidationSchema.safeParse({
|
||||
...validApiKey,
|
||||
bundleIds: "com.thirdweb.ios, foo.bar.id-123",
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it("is valid with comma and new-line separated fqdns", () => {
|
||||
const result = apiKeyValidationSchema.safeParse({
|
||||
...validApiKey,
|
||||
bundleIds: "com.thirdweb.ios, foo.bar.id-123\napp.bundle.id",
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it("is invalid with invalid fqdn", () => {
|
||||
const result = apiKeyValidationSchema.safeParse({
|
||||
...validApiKey,
|
||||
bundleIds: "invalid_bundle_id",
|
||||
});
|
||||
const zError = (result as any).error as ZodError;
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
expect(zError.errors[0].message).toBe(
|
||||
"Some of the bundle ids are invalid",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("services", () => {
|
||||
it("is valid with contract address", () => {
|
||||
const result = apiKeyValidationSchema.safeParse({
|
||||
...validApiKey,
|
||||
services: [
|
||||
{
|
||||
name: "Service 1",
|
||||
enabled: true,
|
||||
targetAddresses: "0x5a464c28d19848f44199d003bef5ecc87d090f87",
|
||||
actions: [],
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it("is invalid with invalid address", () => {
|
||||
const result = apiKeyValidationSchema.safeParse({
|
||||
...validApiKey,
|
||||
services: [
|
||||
{
|
||||
name: "Service 1",
|
||||
enabled: true,
|
||||
targetAddresses: "0x123",
|
||||
actions: [],
|
||||
},
|
||||
],
|
||||
});
|
||||
const zError = (result as any).error as ZodError;
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
expect(zError.errors[0].message).toBe(
|
||||
"Some of the addresses are invalid",
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
+6
-2
@@ -9,7 +9,6 @@
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
"test": "bun test",
|
||||
"fix": "next lint --fix",
|
||||
"format": "prettier --write .",
|
||||
"gen:theme-typings": "chakra-cli tokens theme/index.ts",
|
||||
@@ -18,7 +17,9 @@
|
||||
"postbuild": "next-sitemap",
|
||||
"build:analyze": "ANALYZE=true pnpm run build",
|
||||
"apollo-codegen": "graphql-codegen",
|
||||
"knip": "knip"
|
||||
"knip": "knip",
|
||||
"playwright": "playwright test",
|
||||
"update-checkly": "npx checkly deploy"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apollo/client": "^3.9.7",
|
||||
@@ -94,8 +95,10 @@
|
||||
"@graphql-codegen/typescript-react-apollo": "^4.3.0",
|
||||
"@next/bundle-analyzer": "^14.1.3",
|
||||
"@next/eslint-plugin-next": "^14.1.3",
|
||||
"@playwright/test": "^1.42.1",
|
||||
"@thirdweb-dev/wallets": "2.4.14",
|
||||
"@types/color": "^3.0.6",
|
||||
"@types/node": "^20.11.28",
|
||||
"@types/papaparse": "^5.3.14",
|
||||
"@types/pluralize": "^0.0.33",
|
||||
"@types/qrcode": "^1.5.5",
|
||||
@@ -106,6 +109,7 @@
|
||||
"@types/swagger-ui-react": "^4.18.3",
|
||||
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
||||
"@typescript-eslint/parser": "^7.2.0",
|
||||
"checkly": "^4.6.2",
|
||||
"dotenv": "^16.4.5",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-next": "^14.1.3",
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import { defineConfig, devices } from "@playwright/test";
|
||||
|
||||
/**
|
||||
* Read environment variables from file.
|
||||
* https://github.com/motdotla/dotenv
|
||||
*/
|
||||
// require('dotenv').config();
|
||||
|
||||
/**
|
||||
* See https://playwright.dev/docs/test-configuration.
|
||||
*/
|
||||
export default defineConfig({
|
||||
testDir: "./tests",
|
||||
/* Run tests in files in parallel */
|
||||
fullyParallel: true,
|
||||
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
||||
forbidOnly: !!process.env.CI,
|
||||
/* Retry on CI only */
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
/* Opt out of parallel tests on CI. */
|
||||
workers: process.env.CI ? 1 : undefined,
|
||||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
||||
reporter: "html",
|
||||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
||||
use: {
|
||||
/* Base URL to use in actions like `await page.goto('/')`. */
|
||||
baseURL: process.env.ENVIRONMENT_URL || "http://127.0.0.1:3000",
|
||||
|
||||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
||||
trace: "on-first-retry",
|
||||
},
|
||||
|
||||
/* Configure projects for major browsers */
|
||||
projects: [
|
||||
{
|
||||
name: "chromium",
|
||||
use: { ...devices["Desktop Chrome"] },
|
||||
},
|
||||
|
||||
{
|
||||
name: "firefox",
|
||||
use: { ...devices["Desktop Firefox"] },
|
||||
},
|
||||
|
||||
{
|
||||
name: "webkit",
|
||||
use: { ...devices["Desktop Safari"] },
|
||||
},
|
||||
|
||||
/* Test against mobile viewports. */
|
||||
// {
|
||||
// name: 'Mobile Chrome',
|
||||
// use: { ...devices['Pixel 5'] },
|
||||
// },
|
||||
// {
|
||||
// name: 'Mobile Safari',
|
||||
// use: { ...devices['iPhone 12'] },
|
||||
// },
|
||||
|
||||
/* Test against branded browsers. */
|
||||
// {
|
||||
// name: 'Microsoft Edge',
|
||||
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
|
||||
// },
|
||||
// {
|
||||
// name: 'Google Chrome',
|
||||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
|
||||
// },
|
||||
],
|
||||
|
||||
/* Run your local dev server before starting the tests */
|
||||
webServer: process.env.CI
|
||||
? undefined
|
||||
: {
|
||||
command: "pnpm run start",
|
||||
url: "http://127.0.0.1:3000",
|
||||
reuseExistingServer: !process.env.CI,
|
||||
},
|
||||
});
|
||||
Generated
+1071
-56
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,14 @@
|
||||
import { test, expect } from "@playwright/test";
|
||||
|
||||
test.beforeEach(async ({ page, baseURL }) => {
|
||||
await page.goto(baseURL || "/");
|
||||
});
|
||||
|
||||
test.describe("Homepage", () => {
|
||||
test("has correct title", async ({ page }) => {
|
||||
// Expect a title to be correct.
|
||||
await expect(page).toHaveTitle(
|
||||
"thirdweb: The complete web3 development platform",
|
||||
);
|
||||
});
|
||||
});
|
||||
+6
-6
@@ -18,20 +18,20 @@
|
||||
"downlevelIteration": true,
|
||||
"paths": {
|
||||
"tw-components": ["tw-components"],
|
||||
"tw-components/*": ["tw-components/*"],
|
||||
"tw-components/*": ["tw-components/*"]
|
||||
},
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next",
|
||||
},
|
||||
],
|
||||
"name": "next"
|
||||
}
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
"additional.d.ts",
|
||||
".next/types/**/*.ts",
|
||||
".next/types/**/*.ts"
|
||||
],
|
||||
"exclude": ["node_modules", ".next", "lib/__generated__"],
|
||||
"exclude": ["node_modules", ".next", "lib/__generated__"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user