Skip to content

Commit

Permalink
test: ✅ update playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
AruSeito committed Sep 22, 2023
1 parent f37ddd0 commit cfaa894
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 120 deletions.
2 changes: 0 additions & 2 deletions apps/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@
"downloadjs": "^1.4.7",
"editorjs-html": "^3.4.3",
"editorjs-md-parser": "^0.0.3",
"events": "^3.3.0",
"fflate": "^0.8.0",
"framer-motion": "^7.6.12",
"i18next": "^22.4.9",
"i18next-browser-languagedetector": "^7.0.1",
"jshint": "^2.13.6",
"lodash": "^4.17.21",
"lottie-react": "^2.4.0",
"numbro": "^2.3.6",
Expand Down
10 changes: 10 additions & 0 deletions apps/playwright/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules/
/test-results/
/playwright-report/
/playwright/.cache/
/test-results/
/playwright-report/
/playwright/.cache/
.env.local
.env.*.local
/.auth
24 changes: 24 additions & 0 deletions apps/playwright/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "playwright",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "playwright test",
"test:development": "cross-env ILLA_APP_ENV=development playwright test",
"codegen": "playwright codegen https://localhost:3000/bbbbb/dashboard/apps --load-storage=.auth/user.json --ignore-https-errors",
"test:auth": "cross-env ILLA_APP_ENV=development playwright test auth.setup.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@illa-public/illa-net": "workspace:*"
},
"devDependencies": {
"@playwright/test": "^1.38.1",
"@types/node": "^18.14.4",
"cross-env": "^7.0.3",
"dotenv": "^16.3.1"
}
}
60 changes: 60 additions & 0 deletions apps/playwright/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { defineConfig, devices } from "@playwright/test"
import dotenv from "dotenv"

const modeExt = process.env.ILLA_APP_ENV || "development"
dotenv.config({ path: `.env.${modeExt}.local`, override: true })

/**
* 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.ILLA_BUILDER_URL,

/* 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: "setup",
testMatch: /.*\.setup\.ts/,
use: {
contextOptions: {
ignoreHTTPSErrors: true,
},
},
},
{
name: "chromium",
use: {
...devices["Desktop Chrome"],
storageState: ".auth/user.json",
contextOptions: {
ignoreHTTPSErrors: true,
},
},
dependencies: ["setup"],
},
],
})
18 changes: 18 additions & 0 deletions apps/playwright/tests/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { notNeedAuthCloudRequest } from "@illa-public/illa-net"
import { test as setup } from "@playwright/test"

const authFile = ".auth/user.json"

setup("authenticate", async ({ page }) => {
const result = await notNeedAuthCloudRequest({
method: "POST",
url: "/auth/signin",
data: {
email: process.env.USER_EMAIL,
password: process.env.USER_PASSWORD,
},
})
const token = result.headers["illa-token"]
await page.goto(`/${process.env.TEAM_IDENTITY}/dashboard/apps?token=${token}`)
await page.context().storageState({ path: authFile })
})
Loading

0 comments on commit cfaa894

Please sign in to comment.