Skip to content

Commit

Permalink
playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nbonamy committed Dec 4, 2024
1 parent 70e7962 commit dbe3e5e
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build/build_number.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
437
444
2 changes: 1 addition & 1 deletion forge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const config: ForgeConfig = {
[FuseV1Options.RunAsNode]: false,
[FuseV1Options.EnableCookieEncryption]: true,
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
[FuseV1Options.EnableNodeCliInspectArguments]: false,
[FuseV1Options.EnableNodeCliInspectArguments]: true,
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: false,
[FuseV1Options.OnlyLoadAppFromAsar]: true,
}),
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint": "eslint '**/*.ts' ; vue-tsc --noEmit",
"test": "vitest --exclude './tests/e2e/**'",
"testui": "vitest --ui --exclude './tests/e2e/**' --coverage.enabled=true",
"teste2e": "vitest --ui ./tests/e2e/**"
"teste2e": "vitest ./tests/e2e/**"
},
"devDependencies": {
"@electron-forge/cli": "^7.4.0",
Expand Down Expand Up @@ -52,6 +52,7 @@
"dotenv": "^16.4.5",
"electron": "32.2.0",
"electron-devtools-installer": "^3.2.0",
"electron-playwright-helpers": "^1.7.1",
"eslint": "^9.12.0",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import": "^2.31.0",
Expand Down
8 changes: 5 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const trayIconManager = new TrayIconManager(app, autoUpdater, quitApp);
app.whenReady().then(() => {

// check if run from app folder
if (process.platform === 'darwin' && !process.env.DEBUG && !app.isInApplicationsFolder()) {
if (process.platform === 'darwin' && !process.env.DEBUG && !process.env.TEST && !app.isInApplicationsFolder()) {
dialog.showMessageBox({
type: 'error',
message: 'You need to run Witsy from the Applications folder. Move the app icon there and try again.',
Expand Down Expand Up @@ -154,7 +154,7 @@ app.whenReady().then(() => {
registerShortcuts();

// create the main window
if (!settings.general.hideOnStartup/* || process.env.DEBUG*/) {
if (!settings.general.hideOnStartup || process.env.TEST) {
log.info('Creating initial main window');
window.openMainWindow();
} else {
Expand All @@ -176,7 +176,9 @@ app.whenReady().then(() => {
docRepo = new DocumentRepository(app);

// we want prompt anywhere to be as fast as possible
window.preparePromptAnywhere();
if (!process.env.TEST) {
window.preparePromptAnywhere();
}

});

Expand Down
27 changes: 27 additions & 0 deletions tests/e2e/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { _electron as electron } from 'playwright'
import { findLatestBuild, parseElectronApp, } from 'electron-playwright-helpers'

export const launchApp = async () : Promise<{ electronApp, window }> => {
const latestBuild = findLatestBuild()
const appInfo = parseElectronApp(latestBuild)
process.env.CI = 'e2e'
const electronApp = await electron.launch({
executablePath: appInfo.executable,
args: [appInfo.main],
env: { ...process.env, TEST: '1' }
})
electronApp.on('window', async (page) => {
// capture errors
page.on('pageerror', (error) => {
console.error(error)
})
// capture console messages
page.on('console', (msg) => {
console.log(msg.text())
})
})
const window = await electronApp.firstWindow()
await window.waitForSelector('.main')
return { electronApp, window }

}
9 changes: 3 additions & 6 deletions tests/e2e/main.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { ElectronApplication, Page, _electron as electron } from 'playwright'
import { ElectronApplication, Page } from 'playwright'
import { beforeAll, afterAll, expect, test } from 'vitest'
import { launchApp } from './e2e'

let electronApp: ElectronApplication
let window: Page

beforeAll(async () => {
electronApp = await electron.launch({
args: ['.vite/build/main.js'],
env: { ...process.env, TEST: '1' }
})
window = await electronApp.firstWindow()
({ electronApp, window } = await launchApp())
})

afterAll(async () => {
Expand Down
24 changes: 24 additions & 0 deletions tests/e2e/prompt.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ElectronApplication, Page } from 'playwright'
import { beforeAll, afterAll, expect, test } from 'vitest'
import { launchApp } from './e2e'

let electronApp: ElectronApplication
let window: Page

beforeAll(async () => {
({ electronApp, window } = await launchApp())
})

afterAll(async () => {
await electronApp.close()
})

test('Prompt', async () => {
await window.fill('.prompt .input textarea', 'Hello World')
await window.click('.prompt .icon.send')
await window.waitForSelector('.content .messages')
expect(window.isVisible('.content .messages')).resolves.toBeTruthy()
expect(window.isVisible('.content .messages .message')).resolves.toBeTruthy()
expect(window.locator('.content .messages .message').all()).resolves.toHaveLength(2)
await window.waitForSelector('.prompt .icon.send')
})

0 comments on commit dbe3e5e

Please sign in to comment.