Skip to content

Commit 1614723

Browse files
committed
cross-env
1 parent 53aa75a commit 1614723

File tree

3 files changed

+59
-7
lines changed

3 files changed

+59
-7
lines changed

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

products/jbrowse-desktop/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
"dir": "src",
1111
"repository": "https://github.com/GMOD/jbrowse-components.git",
1212
"scripts": {
13-
"start": "NODE_ENV=development node scripts/start.js",
13+
"start": "cross-env NODE_ENV=development node scripts/start.js",
1414
"electron": "electron . --no-sandbox",
1515
"electron-ts": "tsc -p tsconfig.electron.json",
1616
"preelectron": "pnpm electron-ts",
1717
"prebuild": "pnpm electron-ts",
1818
"prepack": "pnpm build",
19-
"build": "NODE_ENV=production node scripts/build.js",
19+
"build": "cross-env NODE_ENV=production node scripts/build.js",
2020
"build-electron": "pnpm build && electron-builder build --windows --mac --linux",
2121
"build-electron:win": "pnpm build && electron-builder build --windows",
2222
"build-electron:mac": "pnpm build && electron-builder build --mac",
@@ -105,6 +105,7 @@
105105
},
106106
"devDependencies": {
107107
"@types/selenium-webdriver": "^4.35.5",
108+
"cross-env": "^7.0.3",
108109
"electron": "40.0.0",
109110
"electron-chromedriver": "^40.0.0",
110111
"selenium-webdriver": "^4.39.0"

products/jbrowse-desktop/test/e2e.ts

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { fileURLToPath } from 'url'
22
import { dirname, resolve, join } from 'path'
33
import { spawn, ChildProcess } from 'child_process'
44
import { createRequire } from 'module'
5-
import { Builder, WebDriver, By, until } from 'selenium-webdriver'
5+
import { Builder, WebDriver, By, until, logging } from 'selenium-webdriver'
66

77
const require = createRequire(import.meta.url)
88

@@ -89,20 +89,42 @@ async function createDriver(): Promise<WebDriver> {
8989
)
9090
}
9191

92+
// Enable browser logging to capture console output
93+
const prefs = new logging.Preferences()
94+
prefs.setLevel(logging.Type.BROWSER, logging.Level.ALL)
95+
9296
const driver = await new Builder()
9397
.usingServer(`http://localhost:${CHROMEDRIVER_PORT}`)
9498
.withCapabilities({
9599
'goog:chromeOptions': {
96100
binary: APP_BINARY,
97101
args: chromeArgs,
98102
},
103+
'goog:loggingPrefs': {
104+
browser: 'ALL',
105+
},
99106
})
107+
.setLoggingPrefs(prefs)
100108
.forBrowser('chrome')
101109
.build()
102110

103111
return driver
104112
}
105113

114+
// Flush browser console logs to stdout
115+
async function flushBrowserLogs(driver: WebDriver): Promise<void> {
116+
try {
117+
const logs = await driver.manage().logs().get(logging.Type.BROWSER)
118+
for (const entry of logs) {
119+
const level = entry.level.name
120+
const message = entry.message
121+
console.log(` [Browser ${level}] ${message}`)
122+
}
123+
} catch {
124+
// Ignore errors fetching logs
125+
}
126+
}
127+
106128
// Utility for case-insensitive XPath text search
107129
function textContainsXPath(text: string, elementType = '*') {
108130
const lowerText = text.toLowerCase()
@@ -235,13 +257,17 @@ async function runTest(
235257
const duration = Date.now() - start
236258
results.push({ name, passed: true, duration })
237259
console.log(`\r ✓ ${name} (${duration}ms)`)
260+
await flushBrowserLogs(d)
238261
} catch (e) {
239262
const duration = Date.now() - start
240263
const error = e instanceof Error ? e.message : String(e)
241264
results.push({ name, passed: false, error, duration })
242265
console.log(`\r ✗ ${name}`)
243266
console.log(` Error: ${error}`)
244267

268+
// Flush browser logs on failure for debugging
269+
await flushBrowserLogs(d)
270+
245271
// Capture debug info on failure
246272
try {
247273
const title = await d.getTitle()
@@ -1061,8 +1087,13 @@ async function testWorkspaceCopyView(driver: WebDriver): Promise<void> {
10611087
async function cleanup(): Promise<void> {
10621088
const { execSync } = await import('child_process')
10631089
try {
1064-
execSync('pkill -f chromedriver || true', { stdio: 'ignore' })
1065-
execSync('pkill -f jbrowse-desktop || true', { stdio: 'ignore' })
1090+
if (isWindows) {
1091+
execSync('taskkill /F /IM chromedriver.exe 2>nul', { stdio: 'ignore' })
1092+
execSync('taskkill /F /IM "JBrowse 2.exe" 2>nul', { stdio: 'ignore' })
1093+
} else {
1094+
execSync('pkill -f chromedriver || true', { stdio: 'ignore' })
1095+
execSync('pkill -f jbrowse-desktop || true', { stdio: 'ignore' })
1096+
}
10661097
} catch {
10671098
// Ignore errors
10681099
}
@@ -1140,7 +1171,11 @@ async function main(): Promise<void> {
11401171
// Force kill any remaining jbrowse-desktop processes
11411172
const { execSync } = await import('child_process')
11421173
try {
1143-
execSync('pkill -f jbrowse-desktop || true', { stdio: 'ignore' })
1174+
if (isWindows) {
1175+
execSync('taskkill /F /IM "JBrowse 2.exe" 2>nul', { stdio: 'ignore' })
1176+
} else {
1177+
execSync('pkill -f jbrowse-desktop || true', { stdio: 'ignore' })
1178+
}
11441179
} catch {
11451180
// Ignore errors
11461181
}
@@ -1163,7 +1198,11 @@ main().catch(async e => {
11631198
// Force kill any remaining jbrowse-desktop processes
11641199
const { execSync } = await import('child_process')
11651200
try {
1166-
execSync('pkill -f jbrowse-desktop || true', { stdio: 'ignore' })
1201+
if (isWindows) {
1202+
execSync('taskkill /F /IM "JBrowse 2.exe" 2>nul', { stdio: 'ignore' })
1203+
} else {
1204+
execSync('pkill -f jbrowse-desktop || true', { stdio: 'ignore' })
1205+
}
11671206
} catch {
11681207
// Ignore errors
11691208
}

0 commit comments

Comments
 (0)