Skip to content

Commit

Permalink
Slight tauri e2e cleanup (#2659)
Browse files Browse the repository at this point in the history
* WIP: Break the tauri e2e tests apart
Will fix #2658

* Clean up

* Longer before timeout

* Also exclude tauri tests from vitest

* Utils fn back in app.spec.ts

* Remove utils

* Change before back to it

* Remove explicit mocha dep

* Revert other attemps at fixing the browser issues. mocha dep was the issue

* Clean up

* Signin/out sep with auth flows

* Lint

---------

Co-authored-by: Frank Noirot <frank@zoo.dev>
  • Loading branch information
pierremtb and franknoirot committed Jun 18, 2024
1 parent 2386ba2 commit a79e365
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ PS: for the debug panel, the following JSON is useful for snapping the camera

```
yarn install
yarn build:wasm
yarn build:wasm-dev
cp src/wasm-lib/pkg/wasm_lib_bg.wasm public
yarn vite build --mode development
yarn tauri build --debug -b
Expand Down
30 changes: 11 additions & 19 deletions e2e/tauri/specs/auth.e2e.ts → e2e/tauri/specs/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { browser, $, expect } from '@wdio/globals'
import fs from 'fs/promises'
import path from 'path'
import os from 'os'
import { click, setDatasetValue } from '../utils'

const isWin32 = os.platform() === 'win32'
const documentsDir = path.join(os.homedir(), 'Documents')
Expand All @@ -15,25 +16,8 @@ const newProjectDir = path.join(documentsDir, 'a-different-directory')
const tmp = process.env.TEMP || '/tmp'
const userCodeDir = path.join(tmp, 'kittycad_user_code')

async function click(element: WebdriverIO.Element): Promise<void> {
// Workaround for .click(), see https://github.com/tauri-apps/tauri/issues/6541
await element.waitForClickable()
await browser.execute('arguments[0].click();', element)
}

/* Shoutout to @Sheap on Github for a great workaround utility:
* https://github.com/tauri-apps/tauri/issues/6541#issue-1638944060
*/
async function setDatasetValue(
field: WebdriverIO.Element,
property: string,
value: string
) {
await browser.execute(`arguments[0].dataset.${property} = "${value}"`, field)
}

describe('ZMA (Tauri)', () => {
it('opens the auth page and signs in', async () => {
describe('ZMA sign in flow', () => {
before(async () => {
// Clean up filesystem from previous tests
await new Promise((resolve) => setTimeout(resolve, 100))
await fs.rm(defaultProjectDir, { force: true, recursive: true })
Expand All @@ -42,7 +26,9 @@ describe('ZMA (Tauri)', () => {
await fs.rm(userSettingsDir, { force: true, recursive: true })
await fs.mkdir(defaultProjectDir, { recursive: true })
await fs.mkdir(newProjectDir, { recursive: true })
})

it('opens the auth page and signs in', async () => {
const signInButton = await $('[data-testid="sign-in-button"]')
expect(await signInButton.getText()).toEqual('Sign in')

Expand Down Expand Up @@ -82,6 +68,10 @@ describe('ZMA (Tauri)', () => {
const newFileButton = await $('[data-testid="home-new-file"]')
expect(await newFileButton.getText()).toEqual('New project')
})
})

describe('ZMA authorized user flows', () => {
// Note: each flow below is intended to start *and* end from the home page

it('opens the settings page, checks filesystem settings, and closes the settings page', async () => {
const menuButton = await $('[data-testid="user-sidebar-toggle"]')
Expand Down Expand Up @@ -150,7 +140,9 @@ describe('ZMA (Tauri)', () => {
const base = isWin32 ? 'http://tauri.localhost' : 'tauri://localhost'
await browser.execute(`window.location.href = "${base}/home"`)
})
})

describe('ZMA sign out flow', () => {
it('signs out', async () => {
await new Promise((resolve) => setTimeout(resolve, 1000))
const menuButton = await $('[data-testid="user-sidebar-toggle"]')
Expand Down
18 changes: 18 additions & 0 deletions e2e/tauri/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { browser } from '@wdio/globals'

export async function click(element: WebdriverIO.Element): Promise<void> {
// Workaround for .click(), see https://github.com/tauri-apps/tauri/issues/6541
await element.waitForClickable()
await browser.execute('arguments[0].click();', element)
}

/* Shoutout to @Sheap on Github for a great workaround utility:
* https://github.com/tauri-apps/tauri/issues/6541#issue-1638944060
*/
export async function setDatasetValue(
field: WebdriverIO.Element,
property: string,
value: string
) {
await browser.execute(`arguments[0].dataset.${property} = "${value}"`, field)
}
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const config = defineConfig({
coverage: {
provider: 'istanbul', // or 'v8'
},
exclude: [...configDefaults.exclude, '**/e2e/playwright/**/*'],
exclude: [...configDefaults.exclude, '**/e2e/**/*'],
deps: {
optimizer: {
web: {
Expand Down

0 comments on commit a79e365

Please sign in to comment.