Skip to content

Commit 4c98923

Browse files
DavertMikclaude
andcommitted
test(CDPBrowser): loud prerequisite warnings and Obscura auto-spawn for local runs
Running the Obscura suite without obscura serve on :9222 silently skipped 299 tests. The before hook now prints exactly what to start and how to install it, auto-spawns the server when an obscura binary is found on PATH or via OBSCURA_PATH, and applies the same visible warning for the PHP test app in both consumers. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 84444a6 commit 4c98923

2 files changed

Lines changed: 50 additions & 6 deletions

File tree

test/helper/CDPBrowser_chrome_test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,18 @@ let I
1919
describe('CDPBrowser (against Chrome)', function () {
2020
this.timeout(35000)
2121

22-
before(async () => {
22+
before(async function () {
2323
global.codecept_dir = path.join(__dirname, '/../data')
24+
const phpUp = await fetch(`${siteUrl}/info`).then(
25+
() => true,
26+
() => false,
27+
)
28+
if (!phpUp) {
29+
const msg = `Test app is not running on ${siteUrl} — ALL CDPBrowser tests will be skipped.\n Start it: php -S 127.0.0.1:8000 -t test/data/app`
30+
console.log(`\n ⚠ ${msg}\n`)
31+
if (!process.env.CI) this.skip()
32+
throw new Error(msg)
33+
}
2434
chrome = spawn(puppeteer.executablePath(), ['--headless=new', '--remote-debugging-port=9333', '--no-sandbox', '--disable-gpu', 'about:blank'], { stdio: 'ignore' })
2535
await new Promise(r => setTimeout(r, 2000))
2636
I = new CDPBrowser({ url: siteUrl, endpoint: 'http://127.0.0.1:9333', waitForAction: 300 })

test/helper/CDPBrowser_obscura_test.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'fs'
22
import path from 'path'
3+
import { execSync } from 'child_process'
34
import { fileURLToPath } from 'url'
45
import { dirname } from 'path'
56
import { expect } from 'chai'
@@ -13,18 +14,51 @@ const __dirname = dirname(__filename)
1314
const siteUrl = TestHelper.siteUrl()
1415
let I
1516

17+
const isUp = url =>
18+
fetch(url).then(
19+
() => true,
20+
() => false,
21+
)
22+
23+
const findObscuraBinary = () => {
24+
if (process.env.OBSCURA_PATH) return process.env.OBSCURA_PATH
25+
try {
26+
return execSync('which obscura', { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim() || null
27+
} catch (e) {
28+
return null
29+
}
30+
}
31+
1632
describe('Obscura helper (against obscura serve on :9222)', function () {
1733
this.timeout(35000)
1834

1935
before(async function () {
2036
global.codecept_dir = path.join(__dirname, '/../data')
21-
try {
22-
await fetch('http://127.0.0.1:9222/json/version')
23-
} catch (e) {
37+
38+
let binaryPath = null
39+
if (!(await isUp('http://127.0.0.1:9222/json/version'))) {
40+
binaryPath = findObscuraBinary()
41+
if (!binaryPath) {
42+
const msg = [
43+
'Obscura is not running on 127.0.0.1:9222 and no obscura binary was found — ALL Obscura tests will be skipped.',
44+
'Start it: obscura serve --port 9222 --allow-private-network',
45+
'Or install: https://github.com/h4ckf0r0day/obscura/releases (put on PATH or set OBSCURA_PATH=/path/to/obscura)',
46+
].join('\n ')
47+
console.log(`\n ⚠ ${msg}\n`)
48+
if (!process.env.CI) this.skip()
49+
throw new Error(msg)
50+
}
51+
console.log(`\n ℹ Obscura not running on :9222 — auto-spawning from ${binaryPath}\n`)
52+
}
53+
54+
if (!(await isUp(`${siteUrl}/info`))) {
55+
const msg = `Test app is not running on ${siteUrl} — ALL Obscura tests will be skipped.\n Start it: php -S 127.0.0.1:8000 -t test/data/app`
56+
console.log(`\n ⚠ ${msg}\n`)
2457
if (!process.env.CI) this.skip()
25-
throw new Error('obscura serve is not running on :9222')
58+
throw new Error(msg)
2659
}
27-
I = new Obscura({ url: siteUrl })
60+
61+
I = new Obscura({ url: siteUrl, ...(binaryPath ? { binaryPath } : {}) })
2862
await I._init()
2963
webApiTests.init({ I, siteUrl })
3064
})

0 commit comments

Comments
 (0)