Working window.electron.getPath
This commit is contained in:
@ -38,9 +38,11 @@ test('Electron setup', { tag: '@electron' }, async () => {
|
||||
},
|
||||
{
|
||||
settingsKey: TEST_SETTINGS_KEY,
|
||||
settings: TOML.stringify({ settings: {
|
||||
app: { projectDirectory: fullPath },
|
||||
} }),
|
||||
settings: TOML.stringify({
|
||||
settings: {
|
||||
app: { projectDirectory: fullPath },
|
||||
},
|
||||
}),
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -1,9 +1,7 @@
|
||||
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)
|
||||
@ -16,7 +14,7 @@ test(
|
||||
// create or otherwise clear the folder ./electron-test-projects-dir
|
||||
const settingsFileName = `./${testInfo.title
|
||||
.replace(/\s/gi, '-')
|
||||
.replace(/\W/gi, '')}`
|
||||
.replace(/![\w-]/gi, '')}`
|
||||
const projectDirName = settingsFileName + '-dir'
|
||||
try {
|
||||
await fs.rm(projectDirName, { recursive: true })
|
||||
@ -35,21 +33,15 @@ test(
|
||||
const context = electronApp.context()
|
||||
const page = await electronApp.firstWindow()
|
||||
|
||||
await page.goto('http://localhost:3000/')
|
||||
const electronTempDirectory = await page.evaluate(async () => {
|
||||
return await window.electron.getPath(
|
||||
'temp'
|
||||
)
|
||||
return await window.electron.getPath('temp')
|
||||
})
|
||||
const tempSettingsFilePath = join(electronTempDirectory, settingsFileName)
|
||||
const settingsOverrides = tomlStringify({
|
||||
app: {
|
||||
projectDirectory: fullProjectPath,
|
||||
},
|
||||
})
|
||||
const settingsOverrides = `[settings.project]
|
||||
directory = "/Users/frankjohnson/Documents/zoo-modeling-app-projects-2"
|
||||
`
|
||||
|
||||
if (settingsOverrides instanceof Error) {
|
||||
throw settingsOverrides
|
||||
}
|
||||
await fs.writeFile(tempSettingsFilePath + '.toml', settingsOverrides)
|
||||
|
||||
console.log('from within test setup', {
|
||||
|
@ -609,7 +609,11 @@ export async function tearDown(page: Page, testInfo: TestInfo) {
|
||||
|
||||
// settingsOverrides may need to be augmented to take more generic items,
|
||||
// but we'll be strict for now
|
||||
export async function setup(context: BrowserContext, page: Page, overrideDirectory?: string) {
|
||||
export async function setup(
|
||||
context: BrowserContext,
|
||||
page: Page,
|
||||
overrideDirectory?: string
|
||||
) {
|
||||
// wait for Vite preview server to be up
|
||||
await waitOn({
|
||||
resources: ['tcp:3000'],
|
||||
@ -630,7 +634,8 @@ export async function setup(context: BrowserContext, page: Page, overrideDirecto
|
||||
...TEST_SETTINGS,
|
||||
app: {
|
||||
...TEST_SETTINGS.app,
|
||||
projectDirectory: overrideDirectory || TEST_SETTINGS.app.projectDirectory,
|
||||
projectDirectory:
|
||||
overrideDirectory || TEST_SETTINGS.app.projectDirectory,
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
@ -377,7 +377,8 @@ export async function writeProjectSettingsFile(
|
||||
|
||||
const getAppSettingsFilePath = async () => {
|
||||
const isPlaywright = window.localStorage.getItem('playwright') === 'true'
|
||||
const testDirectoryName = window.localStorage.getItem(TEST_SETTINGS_FILE_KEY) ?? ''
|
||||
const testDirectoryName =
|
||||
window.localStorage.getItem(TEST_SETTINGS_FILE_KEY) ?? ''
|
||||
const appConfig = await window.electron.getPath(
|
||||
isPlaywright ? 'temp' : 'appData'
|
||||
)
|
||||
|
Reference in New Issue
Block a user