Pass desktop export tests
This commit is contained in:
		| @ -1,39 +1,33 @@ | ||||
| import { test, expect } from '@playwright/test' | ||||
| import { join } from 'path' | ||||
| import { test, expect } from './zoo-test' | ||||
| import path from 'path' | ||||
| import { | ||||
|   getUtils, | ||||
|   setupElectron, | ||||
|   tearDown, | ||||
|   executorInputPath, | ||||
|   getPlaywrightDownloadDir, | ||||
| } from './test-utils' | ||||
| import fsp from 'fs/promises' | ||||
|  | ||||
| test.afterEach(async ({ page }, testInfo) => { | ||||
|   await tearDown(page, testInfo) | ||||
| }) | ||||
|  | ||||
| test( | ||||
|   'export works on the first try', | ||||
|   { tag: '@electron' }, | ||||
|   async ({ browserName }, testInfo) => { | ||||
|     const { electronApp, page } = await setupElectron({ | ||||
|       testInfo, | ||||
|       folderSetupFn: async (dir) => { | ||||
|         const bracketDir = join(dir, 'bracket') | ||||
|         await Promise.all([fsp.mkdir(bracketDir, { recursive: true })]) | ||||
|         await Promise.all([ | ||||
|           fsp.copyFile( | ||||
|             executorInputPath('router-template-slate.kcl'), | ||||
|             join(bracketDir, 'other.kcl') | ||||
|           ), | ||||
|           fsp.copyFile( | ||||
|             executorInputPath('focusrite_scarlett_mounting_braket.kcl'), | ||||
|             join(bracketDir, 'main.kcl') | ||||
|           ), | ||||
|         ]) | ||||
|       }, | ||||
|     }) | ||||
|     await page.setViewportSize({ width: 1200, height: 500 }) | ||||
|   async ({ page, context }, testInfo) => { | ||||
|     context.folderSetupFn(async (dir) => { | ||||
|       const bracketDir = path.join(dir, 'bracket') | ||||
|       await Promise.all([fsp.mkdir(bracketDir, { recursive: true })]) | ||||
|       await Promise.all([ | ||||
|         fsp.copyFile( | ||||
|           executorInputPath('router-template-slate.kcl'), | ||||
|           path.join(bracketDir, 'other.kcl') | ||||
|         ), | ||||
|         fsp.copyFile( | ||||
|           executorInputPath('focusrite_scarlett_mounting_braket.kcl'), | ||||
|           path.join(bracketDir, 'main.kcl') | ||||
|         ), | ||||
|       ]) | ||||
|     }), | ||||
|  | ||||
|     await page.setBodyDimensions({ width: 1200, height: 500 }) | ||||
|  | ||||
|     page.on('console', console.log) | ||||
|  | ||||
| @ -93,12 +87,13 @@ test( | ||||
|       await expect(successToastMessage).toBeVisible() | ||||
|       await expect(exportingToastMessage).not.toBeVisible() | ||||
|  | ||||
|       const firstFileFullPath = path.resolve(getPlaywrightDownloadDir(page), exportFileName) | ||||
|       await test.step('Check the export size', async () => { | ||||
|         await expect | ||||
|           .poll( | ||||
|             async () => { | ||||
|               try { | ||||
|                 const outputGltf = await fsp.readFile(exportFileName) | ||||
|                 const outputGltf = await fsp.readFile(firstFileFullPath) | ||||
|                 return outputGltf.byteLength | ||||
|               } catch (e) { | ||||
|                 return 0 | ||||
| @ -107,9 +102,6 @@ test( | ||||
|             { timeout: 15_000 } | ||||
|           ) | ||||
|           .toBeGreaterThan(300_000) | ||||
|  | ||||
|         // clean up exported file | ||||
|         await fsp.rm(exportFileName) | ||||
|       }) | ||||
|     }) | ||||
|  | ||||
| @ -170,12 +162,13 @@ test( | ||||
|           expect(exportingToastMessage).not.toBeVisible(), | ||||
|         ])) | ||||
|  | ||||
|       const secondFileFullPath = path.resolve(getPlaywrightDownloadDir(page), exportFileName) | ||||
|       await test.step('Check the export size', async () => { | ||||
|         await expect | ||||
|           .poll( | ||||
|             async () => { | ||||
|               try { | ||||
|                 const outputGltf = await fsp.readFile(exportFileName) | ||||
|                 const outputGltf = await fsp.readFile(secondFileFullPath) | ||||
|                 return outputGltf.byteLength | ||||
|               } catch (e) { | ||||
|                 return 0 | ||||
| @ -184,13 +177,7 @@ test( | ||||
|             { timeout: 15_000 } | ||||
|           ) | ||||
|           .toBeGreaterThan(100_000) | ||||
|  | ||||
|         // clean up exported file | ||||
|         await fsp.rm(exportFileName) | ||||
|       }) | ||||
|       await electronApp.close() | ||||
|     }) | ||||
|  | ||||
|     await electronApp.close() | ||||
|   } | ||||
| ) | ||||
|  | ||||
| @ -693,13 +693,19 @@ export const makeTemplate: ( | ||||
|   } | ||||
| } | ||||
|  | ||||
| const PLAYWRIGHT_DOWNLOAD_DIR = 'downloads-during-playwright' | ||||
|  | ||||
| export const getPlaywrightDownloadDir = (page: Page) => { | ||||
|   return path.resolve( | ||||
|     page.TEST_SETTINGS_FILE_KEY, | ||||
|     PLAYWRIGHT_DOWNLOAD_DIR | ||||
|   ) | ||||
| } | ||||
|  | ||||
| const moveDownloadedFileTo = async (page: Page, toLocation: string) => { | ||||
|   await fsp.mkdir(path.dirname(toLocation), { recursive: true }) | ||||
|  | ||||
|   const downloadDir = path.resolve( | ||||
|     page.TEST_SETTINGS_FILE_KEY, | ||||
|     'downloads-during-playwright' | ||||
|   ) | ||||
|   const downloadDir = getPlaywrightDownloadDir() | ||||
|  | ||||
|   // Expect there to be at least one file | ||||
|   expect | ||||
|  | ||||
		Reference in New Issue
	
	Block a user