Lf94/tauri to electron (#3315)
* Get electron building something at all * Merge Frank test setup work (#3418) * Working window.electron.getPath * Loading project-specific settings in electron tests * Simplify test until we can get snapshots/traces working in electron tests * test tweaks --------- Co-authored-by: Frank Noirot <frank@kittycad.io> * add test #3375 and #3420 * put kcl files together * move files * can sort projects #3362 * File in the file pane should open with a single click #3385 * pressing delete on home screen should do nothing #3387 * add aria labels to icons * Rename and delete projects, also spam arrow keys when renaming #3364 #3365 #3259 * Fix up paths * Update flake.nix to support Electron * Remove a layer of indirection * Work without a web server * Fix settings#projectDir link on home * Fix login (requires new @kittycad/lib WHICH IS NOT INCLUDED HERE) * Lee: Tests are broken because auth skip needs to happen * get setting override envs passed through * tweak eletron CI * yml tweak * fmt * NUKE tauri shit post merge with main * another test auth tweak * Revert "another test auth tweak" This reverts commitb2254b10af. * try CI again * CI tweaks * SKIP_AUTH true now on playwright * Skipping auth when NODE_ENV=development now * fmt Signed-off-by: Jess Frazelle <github@jessfraz.com> * Use BASE_URL() * fix exists Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix foldername for macos Signed-off-by: Jess Frazelle <github@jessfraz.com> * update for windows Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix version in lower right Signed-off-by: Jess Frazelle <github@jessfraz.com> * cleanup unused imports Signed-off-by: Jess Frazelle <github@jessfraz.com> * progress on is playwright Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix test folders Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix fmt Signed-off-by: Jess Frazelle <github@jessfraz.com> * remove tauri from actions bullshit Signed-off-by: Jess Frazelle <github@jessfraz.com> * remove tauri dir Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixups the coredump async shit Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * node env dev Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix cancellable Signed-off-by: Jess Frazelle <github@jessfraz.com> * cleanup unnessary things Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix Signed-off-by: Jess Frazelle <github@jessfraz.com> * env vars Signed-off-by: Jess Frazelle <github@jessfraz.com> * Bring back fix for NOT using hardcoded main.kcl * env Signed-off-by: Jess Frazelle <github@jessfraz.com> * fmt Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * Revert "updates" This reverts commit da5d9f1043eb94404e8b3f8044088e990e34a4ef. * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * remove tauri clippuy Signed-off-by: Jess Frazelle <github@jessfraz.com> * less retries for now, no debug Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * tsconfig Signed-off-by: Jess Frazelle <github@jessfraz.com> * small tsc fix * update some tsc Signed-off-by: Jess Frazelle <github@jessfraz.com> * tsc env Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix other tsc Signed-off-by: Jess Frazelle <github@jessfraz.com> * small change for routeLoaders * rm old screenshot Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix auth Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix last onew Signed-off-by: Jess Frazelle <github@jessfraz.com> * auth clean up * fix package.json Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix Signed-off-by: Jess Frazelle <github@jessfraz.com> * dissmissed screen on tests * add waits between files being written * put back retried Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix weird programMemory Map issue * put private back * Revert "put private back" This reverts commitd311b978ca. * Revert "fix weird programMemory Map issue" This reverts commit6c387bdf62. * remove serde-wasm-bindgen Signed-off-by: Jess Frazelle <github@jessfraz.com> * add env Signed-off-by: Jess Frazelle <github@jessfraz.com> * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * fix tests * more test tweaks * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * another tweak * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * more test tweaks * more tweaks * increase macos timeout * try fix macos * disable macos playwright tests --------- Signed-off-by: Jess Frazelle <github@jessfraz.com> Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch> Co-authored-by: Frank Noirot <frank@kittycad.io> Co-authored-by: Adam Sunderland <iterion@gmail.com> Co-authored-by: Jess Frazelle <github@jessfraz.com> Co-authored-by: Jess Frazelle <jessfraz@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
		@ -4,19 +4,27 @@ import {
 | 
			
		||||
  Download,
 | 
			
		||||
  TestInfo,
 | 
			
		||||
  BrowserContext,
 | 
			
		||||
  _electron as electron,
 | 
			
		||||
} from '@playwright/test'
 | 
			
		||||
import { EngineCommand } from 'lang/std/artifactGraph'
 | 
			
		||||
import os from 'os'
 | 
			
		||||
import fsp from 'fs/promises'
 | 
			
		||||
import fsSync from 'fs'
 | 
			
		||||
import { join } from 'path'
 | 
			
		||||
import pixelMatch from 'pixelmatch'
 | 
			
		||||
import { PNG } from 'pngjs'
 | 
			
		||||
import { Protocol } from 'playwright-core/types/protocol'
 | 
			
		||||
import type { Models } from '@kittycad/lib'
 | 
			
		||||
import { APP_NAME, COOKIE_NAME } from 'lib/constants'
 | 
			
		||||
import waitOn from 'wait-on'
 | 
			
		||||
import { secrets } from './secrets'
 | 
			
		||||
import { TEST_SETTINGS_KEY, TEST_SETTINGS } from './storageStates'
 | 
			
		||||
import {
 | 
			
		||||
  TEST_SETTINGS_KEY,
 | 
			
		||||
  TEST_SETTINGS,
 | 
			
		||||
  IS_PLAYWRIGHT_KEY,
 | 
			
		||||
} from './storageStates'
 | 
			
		||||
import * as TOML from '@iarna/toml'
 | 
			
		||||
import { SaveSettingsPayload } from 'lib/settings/settingsTypes'
 | 
			
		||||
import { SETTINGS_FILE_NAME } from 'lib/constants'
 | 
			
		||||
 | 
			
		||||
type TestColor = [number, number, number]
 | 
			
		||||
export const TEST_COLORS = {
 | 
			
		||||
@ -44,7 +52,7 @@ async function waitForPageLoadWithRetry(page: Page) {
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    await expect(
 | 
			
		||||
      page.getByRole('button', { name: 'Start Sketch' }),
 | 
			
		||||
      page.getByRole('button', { name: 'sketch Start Sketch' }),
 | 
			
		||||
      errorMessage
 | 
			
		||||
    ).toBeEnabled({
 | 
			
		||||
      timeout: 20_000,
 | 
			
		||||
@ -322,7 +330,7 @@ export async function getUtils(page: Page) {
 | 
			
		||||
    getSegmentBodyCoords: async (locator: string, px = 30) => {
 | 
			
		||||
      const overlay = page.locator(locator)
 | 
			
		||||
      const bbox = await overlay
 | 
			
		||||
        .boundingBox({ timeout: 5000 })
 | 
			
		||||
        .boundingBox({ timeout: 5_000 })
 | 
			
		||||
        .then((box) => ({ ...box, x: box?.x || 0, y: box?.y || 0 }))
 | 
			
		||||
      const angle = Number(await overlay.getAttribute('data-overlay-angle'))
 | 
			
		||||
      const angleXOffset = Math.cos(((angle - 180) * Math.PI) / 180) * px
 | 
			
		||||
@ -339,7 +347,7 @@ export async function getUtils(page: Page) {
 | 
			
		||||
    getBoundingBox: async (locator: string) =>
 | 
			
		||||
      page
 | 
			
		||||
        .locator(locator)
 | 
			
		||||
        .boundingBox()
 | 
			
		||||
        .boundingBox({ timeout: 5_000 })
 | 
			
		||||
        .then((box) => ({ ...box, x: box?.x || 0, y: box?.y || 0 })),
 | 
			
		||||
    codeLocator: page.locator('.cm-content'),
 | 
			
		||||
    normalisedEditorCode: async () => {
 | 
			
		||||
@ -623,24 +631,32 @@ export async function tearDown(page: Page, testInfo: TestInfo) {
 | 
			
		||||
  await page.waitForTimeout(3000)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 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) {
 | 
			
		||||
  // wait for Vite preview server to be up
 | 
			
		||||
  await waitOn({
 | 
			
		||||
    resources: ['tcp:3000'],
 | 
			
		||||
    timeout: 5000,
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  await context.addInitScript(
 | 
			
		||||
    async ({ token, settingsKey, settings }) => {
 | 
			
		||||
    async ({ token, settingsKey, settings, IS_PLAYWRIGHT_KEY }) => {
 | 
			
		||||
      localStorage.setItem('TOKEN_PERSIST_KEY', token)
 | 
			
		||||
      localStorage.setItem('persistCode', ``)
 | 
			
		||||
      localStorage.setItem(settingsKey, settings)
 | 
			
		||||
      localStorage.setItem('playwright', 'true')
 | 
			
		||||
      localStorage.setItem(IS_PLAYWRIGHT_KEY, 'true')
 | 
			
		||||
      console.log('TEST_SETTINGS.projects', settings)
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      token: secrets.token,
 | 
			
		||||
      settingsKey: TEST_SETTINGS_KEY,
 | 
			
		||||
      settings: TOML.stringify({ settings: TEST_SETTINGS }),
 | 
			
		||||
      settings: TOML.stringify({
 | 
			
		||||
        settings: {
 | 
			
		||||
          ...TEST_SETTINGS,
 | 
			
		||||
          app: {
 | 
			
		||||
            ...TEST_SETTINGS.projects,
 | 
			
		||||
            projectDirectory: TEST_SETTINGS.app.projectDirectory,
 | 
			
		||||
            onboardingStatus: 'dismissed',
 | 
			
		||||
            theme: 'dark',
 | 
			
		||||
          },
 | 
			
		||||
        } as Partial<SaveSettingsPayload>,
 | 
			
		||||
      }),
 | 
			
		||||
      IS_PLAYWRIGHT_KEY,
 | 
			
		||||
    }
 | 
			
		||||
  )
 | 
			
		||||
 | 
			
		||||
@ -656,3 +672,54 @@ export async function setup(context: BrowserContext, page: Page) {
 | 
			
		||||
  // kill animations, speeds up tests and reduced flakiness
 | 
			
		||||
  await page.emulateMedia({ reducedMotion: 'reduce' })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export async function setupElectron({
 | 
			
		||||
  testInfo,
 | 
			
		||||
  folderSetupFn,
 | 
			
		||||
}: {
 | 
			
		||||
  testInfo: TestInfo
 | 
			
		||||
  folderSetupFn?: (projectDirName: string) => Promise<void>
 | 
			
		||||
}) {
 | 
			
		||||
  // create or otherwise clear the folder
 | 
			
		||||
  const projectDirName = testInfo.outputPath('electron-test-projects-dir')
 | 
			
		||||
  try {
 | 
			
		||||
    if (fsSync.existsSync(projectDirName)) {
 | 
			
		||||
      await fsp.rm(projectDirName, { recursive: true })
 | 
			
		||||
    }
 | 
			
		||||
  } catch (e) {
 | 
			
		||||
    console.error(e)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  await fsp.mkdir(projectDirName)
 | 
			
		||||
 | 
			
		||||
  const electronApp = await electron.launch({
 | 
			
		||||
    args: ['.', '--no-sandbox'],
 | 
			
		||||
    env: {
 | 
			
		||||
      ...process.env,
 | 
			
		||||
      TEST_SETTINGS_FILE_KEY: projectDirName,
 | 
			
		||||
      IS_PLAYWRIGHT: 'true',
 | 
			
		||||
    },
 | 
			
		||||
  })
 | 
			
		||||
  const context = electronApp.context()
 | 
			
		||||
  const page = await electronApp.firstWindow()
 | 
			
		||||
  context.on('console', console.log)
 | 
			
		||||
  page.on('console', console.log)
 | 
			
		||||
 | 
			
		||||
  const tempSettingsFilePath = join(projectDirName, SETTINGS_FILE_NAME)
 | 
			
		||||
  const settingsOverrides = TOML.stringify({
 | 
			
		||||
    ...TEST_SETTINGS,
 | 
			
		||||
    settings: {
 | 
			
		||||
      app: {
 | 
			
		||||
        ...TEST_SETTINGS.app,
 | 
			
		||||
        projectDirectory: projectDirName,
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
  })
 | 
			
		||||
  await fsp.writeFile(tempSettingsFilePath, settingsOverrides)
 | 
			
		||||
 | 
			
		||||
  await folderSetupFn?.(projectDirName)
 | 
			
		||||
 | 
			
		||||
  await setup(context, page)
 | 
			
		||||
 | 
			
		||||
  return { electronApp, page }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user