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, | ||||
|         }, | ||||
|       }), | ||||
|     } | ||||
|  | ||||
| @ -56,4 +56,4 @@ export const KCL_DEFAULT_CONSTANT_PREFIXES = { | ||||
| /** The default KCL length expression */ | ||||
| export const KCL_DEFAULT_LENGTH = `5` | ||||
| /** localStorage key for the playwright test-specific app settings file */ | ||||
| export const TEST_SETTINGS_FILE_KEY = 'playwright-test-settings' | ||||
| export const TEST_SETTINGS_FILE_KEY = 'playwright-test-settings' | ||||
|  | ||||
| @ -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