Skip to content

Commit 19c7f6c

Browse files
Pablo Carmonastarpit
authored andcommitted
Abstract startElectron method to a common shareable folder to use in other tests rather than only for plan.ts
1 parent f318b54 commit 19c7f6c

File tree

4 files changed

+78
-49
lines changed

4 files changed

+78
-49
lines changed

tests/common/startElectron.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { _electron as electron } from "playwright"
2+
import { join } from "path"
3+
import { main } from "../../package.json"
4+
import { productName } from "../../plugins/plugin-client-default/config.d/name.json"
5+
6+
function githubActionsOS() {
7+
return process.env.RUNNER_OS.replace(/macOS/, "darwin")
8+
.replace(/Linux/, "linux")
9+
.replace(/Windows/, "win32")
10+
}
11+
12+
function githubActionsArch() {
13+
return process.env.RUNNER_ARCH.replace(/X64/, "x64").replace(/ARM64/, "arm64")
14+
}
15+
16+
function electronProductionPath() {
17+
return process.platform === "linux"
18+
? productName
19+
: process.platform === "win32"
20+
? `${productName}.exe`
21+
: join(productName + ".app", "Contents/MacOS", productName)
22+
}
23+
24+
export default async function startElectron() {
25+
// Launch Electron app; "shell" tells Kui to ignore the command line
26+
// and just launch a plain shell
27+
const executablePath = !process.env.EXECUTABLE_PATH
28+
? undefined
29+
: process.env.EXECUTABLE_PATH !== "github-actions-production"
30+
? process.env.EXECUTABLE_PATH
31+
: join(
32+
process.env.GITHUB_WORKSPACE,
33+
"dist/electron",
34+
`${productName}-${githubActionsOS()}-${githubActionsArch()}`,
35+
electronProductionPath()
36+
)
37+
38+
const app = await electron.launch({ args: [main, "shell"], executablePath })
39+
40+
const page = await (await app).firstWindow()
41+
42+
// clear localStorage
43+
await page.evaluate(() => {
44+
return localStorage.removeItem("debug")
45+
})
46+
47+
await page.click(".repl-block.repl-active .repl-input-element")
48+
49+
return { app, page }
50+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import slash from "slash"
2+
import { join, relative } from "path"
3+
import { test, expect } from "@playwright/test"
4+
5+
import startElectron from "../../common/startElectron"
6+
7+
export default function doDashboard(directory: string) {
8+
test.slow()
9+
test(`codeflare dashboard -f ${directory}`, async () => {
10+
const { app, page } = await startElectron()
11+
12+
await page.keyboard.type(`dashboard -f ${slash(relative(process.cwd(), join(__dirname, "./inputs", directory)))}`)
13+
14+
15+
await page.keyboard.press("Enter")
16+
17+
const splitSelector = ".kui--terminal-split-container"
18+
const splitElement = await page.locator(splitSelector)
19+
await expect(splitElement).toBeVisible()
20+
21+
await app.close()
22+
})
23+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import doDashboard from "../dashboard";
2+
3+
doDashboard("1")

tests/plugin-madwizard/plan/plan.ts

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,59 +18,12 @@ import slash from "slash"
1818
import { join, relative } from "path"
1919

2020
import { test, expect } from "@playwright/test"
21-
import { Page, _electron as electron } from "playwright"
21+
import { Page } from "playwright"
2222

23-
import { main } from "../../../package.json"
24-
import { productName } from "../../../plugins/plugin-client-default/config.d/name.json"
23+
import startElectron from "../../common/startElectron"
2524

2625
import { Tree } from "./Input"
2726

28-
function githubActionsOS() {
29-
return process.env.RUNNER_OS.replace(/macOS/, "darwin")
30-
.replace(/Linux/, "linux")
31-
.replace(/Windows/, "win32")
32-
}
33-
34-
function githubActionsArch() {
35-
return process.env.RUNNER_ARCH.replace(/X64/, "x64").replace(/ARM64/, "arm64")
36-
}
37-
38-
function electronProductionPath() {
39-
return process.platform === "linux"
40-
? productName
41-
: process.platform === "win32"
42-
? `${productName}.exe`
43-
: join(productName + ".app", "Contents/MacOS", productName)
44-
}
45-
46-
async function startElectron() {
47-
// Launch Electron app; "shell" tells Kui to ignore the command line
48-
// and just launch a plain shell
49-
const executablePath = !process.env.EXECUTABLE_PATH
50-
? undefined
51-
: process.env.EXECUTABLE_PATH !== "github-actions-production"
52-
? process.env.EXECUTABLE_PATH
53-
: join(
54-
process.env.GITHUB_WORKSPACE,
55-
"dist/electron",
56-
`${productName}-${githubActionsOS()}-${githubActionsArch()}`,
57-
electronProductionPath()
58-
)
59-
60-
const app = await electron.launch({ args: [main, "shell"], executablePath })
61-
62-
const page = await (await app).firstWindow()
63-
64-
// clear localStorage
65-
await page.evaluate(() => {
66-
return localStorage.removeItem("debug")
67-
})
68-
69-
await page.click(".repl-block.repl-active .repl-input-element")
70-
71-
return { app, page }
72-
}
73-
7427
async function checkNode(page: Page, tree: Tree, containerSelector: string) {
7528
const nodeSelector = `${containerSelector} > .pf-c-tree-view__content > .pf-c-tree-view__node`
7629
await page.isVisible(nodeSelector)

0 commit comments

Comments
 (0)