Simplify test until we can get snapshots/traces working in electron tests

This commit is contained in:
Frank Noirot
2024-08-14 02:24:17 +02:00
parent 8e5c0ed1f2
commit 8785fde3d9
3 changed files with 21 additions and 40 deletions

View File

@ -8,9 +8,12 @@ test.afterEach(async ({ page }, testInfo) => {
test( test(
'When the project folder is empty, user can create new project and open it.', 'When the project folder is empty, user can create new project and open it.',
{ tag: '@electron' }, { tag: '@electron' },
async ({ page: _ }, testInfo) => { async ({ browserName }, testInfo) => {
test.skip(
browserName === 'webkit',
'Skip on Safari because `window.tearDown` does not work'
)
const { electronApp, page } = await setupElectron({ testInfo }) const { electronApp, page } = await setupElectron({ testInfo })
const u = await getUtils(page) const u = await getUtils(page)
await page.goto('http://localhost:3000/') await page.goto('http://localhost:3000/')
@ -39,31 +42,6 @@ test(
timeout: 20_000, timeout: 20_000,
}) })
await page.locator('.cm-content')
.fill(`const sketch001 = startSketchOn('XZ')
|> startProfileAt([-87.4, 282.92], %)
|> line([324.07, 27.199], %, $seg01)
|> line([118.328, -291.754], %)
|> line([-180.04, -202.08], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(200, sketch001)`)
const pointOnModel = { x: 660, y: 250 }
// check the model loaded by checking it's grey
await expect
.poll(() => u.getGreatestPixDiff(pointOnModel, [132, 132, 132]), {
timeout: 10_000,
})
.toBeLessThan(10)
await page.mouse.click(pointOnModel.x, pointOnModel.y)
// check user can interact with model by checking it turns yellow
await expect
.poll(() => u.getGreatestPixDiff(pointOnModel, [176, 180, 132]))
.toBeLessThan(10)
await electronApp.close() await electronApp.close()
} }
) )

View File

@ -625,7 +625,13 @@ export async function setup(
}) })
await context.addInitScript( await context.addInitScript(
async ({ token, settingsKey, settings, appSettingsFileKey, appSettingsFileContent }) => { async ({
token,
settingsKey,
settings,
appSettingsFileKey,
appSettingsFileContent,
}) => {
localStorage.setItem('TOKEN_PERSIST_KEY', token) localStorage.setItem('TOKEN_PERSIST_KEY', token)
localStorage.setItem('persistCode', ``) localStorage.setItem('persistCode', ``)
localStorage.setItem(settingsKey, settings) localStorage.setItem(settingsKey, settings)
@ -635,7 +641,8 @@ export async function setup(
{ {
token: secrets.token, token: secrets.token,
appSettingsFileKey: TEST_SETTINGS_FILE_KEY, appSettingsFileKey: TEST_SETTINGS_FILE_KEY,
appSettingsFileContent: overrideDirectory || TEST_SETTINGS.app.projectDirectory, appSettingsFileContent:
overrideDirectory || TEST_SETTINGS.app.projectDirectory,
settingsKey: TEST_SETTINGS_KEY, settingsKey: TEST_SETTINGS_KEY,
settings: TOML.stringify({ settings: TOML.stringify({
...TEST_SETTINGS, ...TEST_SETTINGS,
@ -651,11 +658,7 @@ export async function setup(
await page.emulateMedia({ reducedMotion: 'reduce' }) await page.emulateMedia({ reducedMotion: 'reduce' })
} }
export async function setupElectron({ export async function setupElectron({ testInfo }: { testInfo: TestInfo }) {
testInfo,
}: {
testInfo: TestInfo
}) {
// create or otherwise clear the folder // create or otherwise clear the folder
const projectDirName = testInfo.outputPath('electron-test-projects-dir') const projectDirName = testInfo.outputPath('electron-test-projects-dir')
try { try {
@ -691,4 +694,4 @@ export async function setupElectron({
await setup(context, page, projectDirName) await setup(context, page, projectDirName)
return { electronApp, page } return { electronApp, page }
} }

View File

@ -374,12 +374,12 @@ export async function writeProjectSettingsFile(
const getAppSettingsFilePath = async () => { const getAppSettingsFilePath = async () => {
const isPlaywright = window.localStorage.getItem('playwright') === 'true' const isPlaywright = window.localStorage.getItem('playwright') === 'true'
const testSettingsPath = window.localStorage.getItem(TEST_SETTINGS_FILE_KEY) ?? '' const testSettingsPath =
window.localStorage.getItem(TEST_SETTINGS_FILE_KEY) ?? ''
const appConfig = await window.electron.getPath('appData') const appConfig = await window.electron.getPath('appData')
const fullPath = isPlaywright ? testSettingsPath : window.electron.path.join( const fullPath = isPlaywright
appConfig, ? testSettingsPath
window.electron.packageJson.name : window.electron.path.join(appConfig, window.electron.packageJson.name)
)
try { try {
await window.electron.stat(fullPath) await window.electron.stat(fullPath)
} catch (e) { } catch (e) {