Skip to content

Commit a80340e

Browse files
committed
logs for app node
1 parent fc5bf4d commit a80340e

File tree

1 file changed

+94
-16
lines changed

1 file changed

+94
-16
lines changed

win/env-setup-run.ps1

Lines changed: 94 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -398,49 +398,126 @@ $platformYamlIos
398398
function Setup-Mobile-NodeJS {
399399
param([bool]$UseLocal, [int]$ParallelsPerPlatform, [string]$LogFile)
400400

401-
$REPO = "now-webdriverio-appium-app-browserstack"
401+
$REPO = "now-webdriverio-appium-app-browserstack"
402402
$TARGET = Join-Path $GLOBAL_DIR $REPO
403403

404+
Log-Section "🐛 DEBUG: Setup-Mobile-NodeJS (App / NodeJS)" $GLOBAL_LOG
405+
Log-Line "ℹ️ Repo name: $REPO" $GLOBAL_LOG
406+
Log-Line "ℹ️ Target clone directory: $TARGET" $GLOBAL_LOG
407+
404408
New-Item -ItemType Directory -Path $GLOBAL_DIR -Force | Out-Null
405409
if (Test-Path $TARGET) {
410+
Log-Line "ℹ️ Cleaning existing target directory: $TARGET" $GLOBAL_LOG
406411
Remove-Item -Path $TARGET -Recurse -Force
407412
}
408413

409414
Log-Line "ℹ️ Cloning repository: $REPO" $GLOBAL_LOG
410415
Invoke-GitClone -Url "https://github.com/BrowserStackCE/$REPO.git" -Target $TARGET -LogFile (Get-RunLogFile)
411416

412417
$testDir = Join-Path $TARGET "test"
418+
Log-Line "ℹ️ Test directory (working directory for npm): $testDir" $GLOBAL_LOG
419+
413420
Push-Location $testDir
414421
try {
415-
Log-Line "⚙️ Running 'npm install'" $GLOBAL_LOG
416-
Log-Line "ℹ️ Installing dependencies" $GLOBAL_LOG
417-
[void](Invoke-External -Exe "cmd.exe" -Arguments @("/c","npm","install") -LogFile $LogFile -WorkingDirectory $testDir)
422+
# ---- Node / npm environment diagnostics ----
423+
Log-Section "🔍 NodeJS Environment Diagnostics" $GLOBAL_LOG
424+
425+
$nodeCmd = Get-Command node -ErrorAction SilentlyContinue
426+
$npmCmd = Get-Command npm -ErrorAction SilentlyContinue
427+
428+
if ($nodeCmd) {
429+
Log-Line "ℹ️ node.exe path: $($nodeCmd.Source)" $GLOBAL_LOG
430+
} else {
431+
Log-Line "⚠️ node.exe not found in PATH" $GLOBAL_LOG
432+
}
433+
434+
if ($npmCmd) {
435+
Log-Line "ℹ️ npm.cmd path: $($npmCmd.Source)" $GLOBAL_LOG
436+
} else {
437+
Log-Line "⚠️ npm not found in PATH" $GLOBAL_LOG
438+
}
439+
440+
Log-Line "ℹ️ Running 'node --version' for debug" $GLOBAL_LOG
441+
[void](Invoke-External -Exe "node" -Arguments @("--version") -LogFile $LogFile -WorkingDirectory $testDir)
442+
443+
Log-Line "ℹ️ Running 'npm --version' for debug" $GLOBAL_LOG
444+
[void](Invoke-External -Exe "npm" -Arguments @("--version") -LogFile $LogFile -WorkingDirectory $testDir)
445+
446+
# ---- npm install ----
447+
Log-Section "📦 npm install (mobile / nodejs)" $GLOBAL_LOG
448+
Log-Line "⚙️ About to run: cmd.exe /c npm install" $GLOBAL_LOG
449+
Log-Line "ℹ️ Working directory: $testDir" $GLOBAL_LOG
450+
$npmInstallStart = Get-Date
451+
$npmInstallExit = Invoke-External -Exe "cmd.exe" -Arguments @("/c","npm","install") -LogFile $LogFile -WorkingDirectory $testDir
452+
$npmInstallEnd = Get-Date
453+
$npmInstallDuration = [int]($npmInstallEnd - $npmInstallStart).TotalSeconds
454+
455+
Log-Line "ℹ️ npm install exit code: $npmInstallExit (duration: ${npmInstallDuration}s)" $GLOBAL_LOG
456+
if ($npmInstallExit -ne 0) {
457+
Log-Line "❌ npm install failed with exit code $npmInstallExit. See $LogFile for details." $GLOBAL_LOG
458+
throw "npm install failed (exit $npmInstallExit)"
459+
}
460+
418461
Log-Line "✅ Dependencies installed" $GLOBAL_LOG
419462

420-
# Generate capabilities JSON and set as environment variable (like Mac)
463+
# ---- Capabilities / env setup ----
464+
Log-Section "⚙️ Generating capabilities & setting environment variables" $GLOBAL_LOG
421465
$capsJson = Generate-Mobile-Caps-Json-String -MaxTotalParallels $ParallelsPerPlatform
422466

423-
$env:BROWSERSTACK_USERNAME = $BROWSERSTACK_USERNAME
424-
$env:BROWSERSTACK_ACCESS_KEY = $BROWSERSTACK_ACCESS_KEY
425-
$env:BSTACK_PARALLELS = $ParallelsPerPlatform
426-
$env:BSTACK_CAPS_JSON = $capsJson
427-
$env:BROWSERSTACK_APP = $APP_URL
428-
$env:BROWSERSTACK_BUILD_NAME = "now-windows-app-nodejs-wdio"
429-
$env:BROWSERSTACK_PROJECT_NAME = "NOW-Mobile-Test"
430-
$env:BROWSERSTACK_LOCAL = "true"
467+
$env:BROWSERSTACK_USERNAME = $BROWSERSTACK_USERNAME
468+
$env:BROWSERSTACK_ACCESS_KEY = $BROWSERSTACK_ACCESS_KEY
469+
$env:BSTACK_PARALLELS = $ParallelsPerPlatform
470+
$env:BSTACK_CAPS_JSON = $capsJson
471+
$env:BROWSERSTACK_APP = $APP_URL
472+
$env:BROWSERSTACK_BUILD_NAME = "now-windows-app-nodejs-wdio"
473+
$env:BROWSERSTACK_PROJECT_NAME = "NOW-Mobile-Test"
474+
$env:BROWSERSTACK_LOCAL = "true"
431475

432476
# Validate Environment Variables
433-
Log-Section "Validate Environment Variables" $GLOBAL_LOG
477+
Log-Section "🧾 Validate Environment Variables (Mobile / NodeJS)" $GLOBAL_LOG
434478
Log-Line "ℹ️ BrowserStack Username: $BROWSERSTACK_USERNAME" $GLOBAL_LOG
435479
Log-Line "ℹ️ BrowserStack Build: $($env:BROWSERSTACK_BUILD_NAME)" $GLOBAL_LOG
436480
Log-Line "ℹ️ BrowserStack Project: $($env:BROWSERSTACK_PROJECT_NAME)" $GLOBAL_LOG
437481
Log-Line "ℹ️ Native App Endpoint: $APP_URL" $GLOBAL_LOG
438482
Log-Line "ℹ️ BrowserStack Local Flag: $($env:BROWSERSTACK_LOCAL)" $GLOBAL_LOG
439483
Log-Line "ℹ️ Parallels per platform: $ParallelsPerPlatform" $GLOBAL_LOG
440-
Log-Line "ℹ️ Platforms: $capsJson" $GLOBAL_LOG
484+
Log-Line "ℹ️ Platforms JSON (caps): $capsJson" $GLOBAL_LOG
485+
486+
# For additional safety, dump the relevant npm script from package.json
487+
$pkgPath = Join-Path $testDir "package.json"
488+
if (Test-Path $pkgPath) {
489+
try {
490+
$pkgRaw = Get-Content $pkgPath -Raw | ConvertFrom-Json
491+
if ($pkgRaw.scripts.test) {
492+
Log-Line "ℹ️ package.json 'test' script: $($pkgRaw.scripts.test)" $GLOBAL_LOG
493+
} else {
494+
Log-Line "⚠️ package.json has no 'test' script defined" $GLOBAL_LOG
495+
}
496+
} catch {
497+
Log-Line "⚠️ Failed to parse package.json for logging: $($_.Exception.Message)" $GLOBAL_LOG
498+
}
499+
} else {
500+
Log-Line "⚠️ package.json not found at $pkgPath" $GLOBAL_LOG
501+
}
441502

503+
# ---- npm run test ----
442504
Print-TestsRunningSection -Command "npm run test"
443-
[void](Invoke-External -Exe "cmd.exe" -Arguments @("/c","npm","run","test") -LogFile $LogFile -WorkingDirectory $testDir)
505+
Log-Line "ℹ️ About to run tests: cmd.exe /c npm run test" $GLOBAL_LOG
506+
Log-Line "ℹ️ Working directory for tests: $testDir" $GLOBAL_LOG
507+
508+
$testStart = Get-Date
509+
$testExit = Invoke-External -Exe "cmd.exe" -Arguments @("/c","npm","run","test") -LogFile $LogFile -WorkingDirectory $testDir
510+
$testEnd = Get-Date
511+
$testDuration = [int]($testEnd - $testStart).TotalSeconds
512+
513+
Log-Line "ℹ️ npm run test exit code: $testExit (duration: ${testDuration}s)" $GLOBAL_LOG
514+
515+
if ($testExit -eq 0) {
516+
Log-Line "✅ npm run test exited cleanly (exit code 0)" $GLOBAL_LOG
517+
} else {
518+
Log-Line "❌ npm run test exited with non-zero code $testExit. Check $LogFile for details." $GLOBAL_LOG
519+
}
520+
444521
Log-Line "ℹ️ Run Test command completed." $GLOBAL_LOG
445522

446523
} finally {
@@ -449,6 +526,7 @@ function Setup-Mobile-NodeJS {
449526
}
450527
}
451528

529+
452530
# ===== Helper Functions =====
453531
function Report-BStackLocalStatus {
454532
param([bool]$LocalFlag)

0 commit comments

Comments
 (0)