Got context and page loading
This commit is contained in:
@ -2,6 +2,8 @@ import { _electron as electron, test, expect } from '@playwright/test'
|
||||
import { getUtils, setup, tearDown } from './test-utils'
|
||||
import fs from 'fs/promises'
|
||||
import { secrets } from './secrets'
|
||||
import { join } from 'path'
|
||||
import { tomlStringify } from 'lang/wasm'
|
||||
|
||||
test.afterEach(async ({ page }, testInfo) => {
|
||||
await tearDown(page, testInfo)
|
||||
@ -10,31 +12,60 @@ test.afterEach(async ({ page }, testInfo) => {
|
||||
test(
|
||||
'When the project folder is empty, user can create new project and open it.',
|
||||
{ tag: '@electron' },
|
||||
async ({ context }, testInfo) => {
|
||||
async ({ page: browserPage, context: browserContext }, testInfo) => {
|
||||
// create or otherwise clear the folder ./electron-test-projects-dir
|
||||
const fileName = `./${testInfo.titlePath.join('-').replace(/\s/gi, '-')}-dir`
|
||||
const settingsFileName = `./${testInfo.title
|
||||
.replace(/\s/gi, '-')
|
||||
.replace(/\W/gi, '')}`
|
||||
const projectDirName = settingsFileName + '-dir'
|
||||
try {
|
||||
await fs.rm(fileName, { recursive: true })
|
||||
await fs.rm(projectDirName, { recursive: true })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
const projectDirectory = await fs.mkdir(fileName)
|
||||
await fs.mkdir(projectDirName)
|
||||
|
||||
// get full path for ./electron-test-projects-dir
|
||||
const fullPath = await fs.realpath(fileName)
|
||||
const fullProjectPath = await fs.realpath(projectDirName)
|
||||
|
||||
const electronApp = await electron.launch({
|
||||
args: ['.'],
|
||||
})
|
||||
|
||||
const context = electronApp.context()
|
||||
const page = await electronApp.firstWindow()
|
||||
|
||||
const electronTempDirectory = await page.evaluate(async () => {
|
||||
return await window.electron.getPath(
|
||||
'temp'
|
||||
)
|
||||
})
|
||||
const tempSettingsFilePath = join(electronTempDirectory, settingsFileName)
|
||||
const settingsOverrides = tomlStringify({
|
||||
app: {
|
||||
projectDirectory: fullProjectPath,
|
||||
},
|
||||
})
|
||||
|
||||
if (settingsOverrides instanceof Error) {
|
||||
throw settingsOverrides
|
||||
}
|
||||
await fs.writeFile(tempSettingsFilePath + '.toml', settingsOverrides)
|
||||
|
||||
console.log('from within test setup', {
|
||||
settingsFileName,
|
||||
fullPath: fullProjectPath,
|
||||
electronApp,
|
||||
page,
|
||||
settingsFilePath: tempSettingsFilePath + '.toml',
|
||||
})
|
||||
|
||||
await setup(context, page, fullProjectPath)
|
||||
// Set local storage directly using evaluate
|
||||
await setup(context, page, fullPath)
|
||||
|
||||
const u = await getUtils(page)
|
||||
await page.setViewportSize({ width: 1200, height: 500 })
|
||||
await page.goto('http://localhost:3000/')
|
||||
|
||||
page.on('console', console.log)
|
||||
|
||||
|
Reference in New Issue
Block a user