Skip to content

Commit fff52b3

Browse files
committed
feat: add globalSetup for testing
1 parent 52fe28a commit fff52b3

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
"lines": 40
138138
}
139139
},
140-
"testTimeout": 30000
140+
"testTimeout": 30000,
141+
"globalSetup": "<rootDir>/test/globalSetup.ts"
141142
}
142143
}

test/globalSetup.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This setup runs before our e2e tests
2+
// so that it authenticates us into code-server
3+
// ensuring that we're logged in before we run any tests
4+
import { chromium, Page, Browser, BrowserContext } from "playwright"
5+
6+
module.exports = async () => {
7+
const browser: Browser = await chromium.launch()
8+
const context: BrowserContext = await browser.newContext()
9+
const page: Page = await context.newPage()
10+
11+
await page.goto(process.env.CODE_SERVER_ADDRESS || "http://localhost:8080", { waitUntil: "domcontentloaded" })
12+
// Type in password
13+
await page.fill(".password", process.env.PASSWORD || "password")
14+
// Click the submit button and login
15+
await page.click(".submit")
16+
17+
// Save storage state and store as an env variable
18+
// More info: https://playwright.dev/docs/auth?_highlight=authe#reuse-authentication-state
19+
const storage = await context.storageState()
20+
process.env.STORAGE = JSON.stringify(storage)
21+
22+
await page.close()
23+
await browser.close()
24+
await context.close()
25+
}

0 commit comments

Comments
 (0)