-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A stub for integration tests to be run locally; part of #8487 To run tests, you need to: 1. Build IDE package: `./run ide build` 2. set ENSO_TEST_USER and ENSO_TEST_USER_PASSWORD to some working credentials (I used my personal account, but there will be also test user soon) 3. run `corepack pnpm -r --filter enso exec playwright test` The tests are run with a separate projects directory set up in tmpdir, so any local workspace dir is not affected. The only test so far just checks if it's possible to log in and create a new project.
- Loading branch information
Showing
10 changed files
with
142 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** @file Playwright browser testing configuration. */ | ||
import { defineConfig } from '@playwright/test' | ||
|
||
/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/strict-boolean-expressions */ | ||
|
||
export default defineConfig({ | ||
testDir: './tests', | ||
forbidOnly: !!process.env.CI, | ||
workers: 1, | ||
timeout: 60000, | ||
reportSlowTests: { max: 5, threshold: 60000 }, | ||
globalSetup: './tests/setup.ts', | ||
expect: { | ||
timeout: 5000, | ||
toHaveScreenshot: { threshold: 0 }, | ||
}, | ||
use: { | ||
actionTimeout: 5000, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** @file A test for basic flow of the application: open project and see if nodes appear. */ | ||
|
||
/* eslint-disable @typescript-eslint/no-magic-numbers */ | ||
|
||
import { expect } from '@playwright/test' | ||
import { electronTest, loginAsTestUser } from './electronTest' | ||
|
||
electronTest('Create new project', async page => { | ||
await loginAsTestUser(page) | ||
await expect(page.getByRole('button', { name: 'New Project', exact: true })).toBeVisible() | ||
await page.getByRole('button', { name: 'New Project', exact: true }).click() | ||
await expect(page.locator('.GraphNode'), {}).toBeVisible({ timeout: 30000 }) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** @file Commonly used functions for electron tests */ | ||
|
||
import { _electron, expect, type Page, test } from '@playwright/test' | ||
|
||
/** | ||
* Tests run on electron executable. | ||
* | ||
* Similar to playwright's test, but launches electron, and passes Page of the main window. | ||
*/ | ||
export function electronTest(name: string, body: (page: Page) => Promise<void> | void) { | ||
test(name, async () => { | ||
const app = await _electron.launch({ | ||
executablePath: process.env.ENSO_TEST_EXEC_PATH ?? '', | ||
env: { ...process.env, ['ENSO_TEST']: name }, | ||
}) | ||
const page = await app.firstWindow() | ||
await body(page) | ||
await app.close() | ||
}) | ||
} | ||
|
||
/** | ||
* Login as test user. This function asserts that page is the login page, and uses | ||
* credentials from ENSO_TEST_USER and ENSO_TEST_USER_PASSWORD env variables. | ||
*/ | ||
export async function loginAsTestUser(page: Page) { | ||
// Login screen | ||
await expect(page.getByRole('textbox', { name: 'email' })).toBeVisible() | ||
await expect(page.getByRole('textbox', { name: 'password' })).toBeVisible() | ||
if (process.env.ENSO_TEST_USER == null || process.env.ENSO_TEST_USER_PASSWORD == null) { | ||
throw Error( | ||
'Cannot log in; `ENSO_TEST_USER` and `ENSO_TEST_USER_PASSWORD` env variables are not provided', | ||
) | ||
} | ||
await page.keyboard.insertText(process.env.ENSO_TEST_USER) | ||
await page.keyboard.press('Tab') | ||
await page.keyboard.insertText(process.env.ENSO_TEST_USER_PASSWORD) | ||
await page.keyboard.press('Enter') | ||
|
||
// Accept terms screen | ||
await expect(page.getByText('I agree')).toHaveCount(2) | ||
await expect(page.getByRole('button')).toHaveCount(1) | ||
for (const checkbox of await page.getByText('I agree').all()) { | ||
await checkbox.click() | ||
} | ||
await page.getByRole('button').click() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** @file {@link setup} function for all tests. */ | ||
|
||
import * as fs from 'node:fs' | ||
|
||
const POSSIBLE_EXEC_PATHS = [ | ||
'../../../dist/ide/linux-unpacked/enso', | ||
'../../../dist/ide/win-unpacked/Enso.exe', | ||
'../../../dist/ide/mac/Enso.app/Contents/MacOS/Enso', | ||
'../../../dist/ide/mac-arm64/Enso.app/Contents/MacOS/Enso', | ||
] | ||
|
||
/** | ||
* Setup for all tests: checks if and where electron exec is. | ||
* @throws when no Enso package could be found. | ||
*/ | ||
export default function setup() { | ||
const execPath = POSSIBLE_EXEC_PATHS.find(path => { | ||
try { | ||
fs.accessSync(path, fs.constants.X_OK) | ||
return true | ||
} catch (err) { | ||
return false | ||
} | ||
}) | ||
if (execPath != null) { | ||
process.env.ENSO_TEST_EXEC_PATH = execPath | ||
} else { | ||
throw Error('Cannot find Enso package') | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.