@ohos-ports/floss 5.0.1-beta.3 → 5.0.1-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser-runner.js +25 -24
- package/lib/node-runner.js +2 -0
- package/package.json +3 -39
package/lib/browser-runner.js
CHANGED
|
@@ -42,31 +42,32 @@ const DISABLED_FEATURES = [
|
|
|
42
42
|
|
|
43
43
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
44
44
|
|
|
45
|
-
// ───
|
|
45
|
+
// ─── Native system command utilities ────────────────────────────────
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
fs.accessSync("/data/service/hnp/bin/hdc");
|
|
51
|
-
return "/data/service/hnp/bin/hdc";
|
|
52
|
-
} catch {}
|
|
53
|
-
}
|
|
54
|
-
return process.env.HDC_PATH || "hdc";
|
|
55
|
-
}
|
|
47
|
+
const OHOS_AA_PATH = "/system/bin/cli_tool/executable/ohos-aa";
|
|
48
|
+
const OHOS_BM_PATH = "/system/bin/cli_tool/executable/ohos-bm";
|
|
56
49
|
|
|
57
|
-
function
|
|
50
|
+
function execCmd(binPath, args, timeout) {
|
|
58
51
|
const { execFileSync } = require("child_process");
|
|
59
52
|
try {
|
|
60
|
-
return execFileSync(
|
|
53
|
+
return execFileSync(binPath, args, {
|
|
61
54
|
timeout: timeout || 30000,
|
|
62
55
|
encoding: "utf-8",
|
|
63
56
|
stdio: ["pipe", "pipe", "pipe"],
|
|
64
57
|
}).trim();
|
|
65
58
|
} catch (e) {
|
|
66
|
-
throw new Error("
|
|
59
|
+
throw new Error(binPath + " " + args.join(" ") + " failed: " + e.message);
|
|
67
60
|
}
|
|
68
61
|
}
|
|
69
62
|
|
|
63
|
+
function execOhosAa(args, timeout) {
|
|
64
|
+
return execCmd(OHOS_AA_PATH, args, timeout);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function execOhosBm(args, timeout) {
|
|
68
|
+
return execCmd(OHOS_BM_PATH, args, timeout);
|
|
69
|
+
}
|
|
70
|
+
|
|
70
71
|
// ─── Browser launch / close ───────────────────────────────────────────
|
|
71
72
|
|
|
72
73
|
function buildLaunchArgs() {
|
|
@@ -87,25 +88,25 @@ async function launchBrowser() {
|
|
|
87
88
|
// 1. Check if browser is installed
|
|
88
89
|
var installedApps;
|
|
89
90
|
try {
|
|
90
|
-
installedApps =
|
|
91
|
+
installedApps = execOhosBm(["dump", "--all"], 10000);
|
|
91
92
|
} catch (e) {
|
|
92
|
-
throw new Error("Cannot query installed apps via
|
|
93
|
+
throw new Error("Cannot query installed apps via ohos-bm. " + e.message);
|
|
93
94
|
}
|
|
94
95
|
if (!installedApps.includes(BROWSER_PKG)) {
|
|
95
96
|
throw new Error('Browser "' + BROWSER_PKG + '" is not installed on this device.');
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
// 2. Kill existing browser process
|
|
99
|
-
try {
|
|
100
|
+
try { execOhosAa(["force-stop", "--bundlename", BROWSER_PKG], 10000); } catch {}
|
|
100
101
|
await sleep(1000);
|
|
101
102
|
|
|
102
103
|
// 3. Start browser with CDP enabled
|
|
103
104
|
var cmdArgs = buildLaunchArgs();
|
|
104
|
-
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"--ps",
|
|
105
|
+
execOhosAa([
|
|
106
|
+
"start",
|
|
107
|
+
"--bundlename", BROWSER_PKG,
|
|
108
|
+
"--abilityname", BROWSER_ABILITY,
|
|
109
|
+
"--ps", JSON.stringify({ cmdArgs: cmdArgs }),
|
|
109
110
|
], 15000);
|
|
110
111
|
|
|
111
112
|
// 4. Wait for CDP endpoint
|
|
@@ -114,7 +115,7 @@ async function launchBrowser() {
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
async function closeBrowser() {
|
|
117
|
-
try {
|
|
118
|
+
try { execOhosAa(["force-stop", "--bundlename", BROWSER_PKG], 10000); } catch {}
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
// ─── CDP endpoint discovery ──────────────────────────────────────────
|
|
@@ -293,7 +294,7 @@ function resolveFiles(files) {
|
|
|
293
294
|
* Run tests in a real Chromium browser (海泰浏览器) via CDP.
|
|
294
295
|
*
|
|
295
296
|
* This provides full browser capabilities: DOM, Canvas, WebGL, CSS layout.
|
|
296
|
-
* Browser is launched via
|
|
297
|
+
* Browser is launched via ohos-aa, controlled via Chrome DevTools Protocol.
|
|
297
298
|
*
|
|
298
299
|
* @param {Object} opts - Floss options (path, reporter, require, quiet, etc.)
|
|
299
300
|
* @returns {Promise<void>} Resolves on success, rejects on failure
|
|
@@ -305,7 +306,7 @@ function runInBrowser(opts) {
|
|
|
305
306
|
var sessionId = null;
|
|
306
307
|
|
|
307
308
|
try {
|
|
308
|
-
// ── 1. Launch browser via
|
|
309
|
+
// ── 1. Launch browser via ohos-aa ──
|
|
309
310
|
var wsUrl = await launchBrowser();
|
|
310
311
|
browserLaunched = true;
|
|
311
312
|
|
package/lib/node-runner.js
CHANGED
|
@@ -89,6 +89,8 @@ function runInNode(opts) {
|
|
|
89
89
|
}
|
|
90
90
|
// Add resolved files to Mocha
|
|
91
91
|
resolvedFiles.forEach((file) => mochaInst.addFile(file));
|
|
92
|
+
// Set global.options for test files that depend on it (same as renderer.js)
|
|
93
|
+
global.options = opts;
|
|
92
94
|
// Run tests
|
|
93
95
|
mochaInst.run((errorCount) => {
|
|
94
96
|
if (errorCount > 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohos-ports/floss",
|
|
3
|
-
"version": "5.0.1-beta.
|
|
3
|
+
"version": "5.0.1-beta.5",
|
|
4
4
|
"description": "Unit-testing for those hard to reach places",
|
|
5
5
|
"bin": "./lib/floss.js",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -13,29 +13,7 @@
|
|
|
13
13
|
"files": [
|
|
14
14
|
"lib"
|
|
15
15
|
],
|
|
16
|
-
"scripts": {
|
|
17
|
-
"lint": "eslint src/*.ts --fix",
|
|
18
|
-
"types": "tsc -noEmit",
|
|
19
|
-
"copy": "copyfiles -f src/index.html lib",
|
|
20
|
-
"clean": "rimraf lib/*",
|
|
21
|
-
"prebuild": "run-s clean lint copy",
|
|
22
|
-
"build": "tsc",
|
|
23
|
-
"prewatch": "run-s copy",
|
|
24
|
-
"watch": "tsc -w --incremental --tsBuildInfoFile .tsbuildinfo",
|
|
25
|
-
"test": "run-s test:*",
|
|
26
|
-
"test:basic": "node lib/floss.js -p test/basic",
|
|
27
|
-
"test:failure": "node lib/floss.js -p test/failure || true",
|
|
28
|
-
"test:multiple": "node lib/floss.js -p \"test/multiple/*.js\"",
|
|
29
|
-
"test:typescript": "node lib/floss.js -p test/typescript -r ts-node/register",
|
|
30
|
-
"test:coverage": "nyc node lib/floss.js -p test/coverage",
|
|
31
|
-
"test:options": "node lib/floss.js -p test/options -- --foo=bar",
|
|
32
|
-
"test:args": "node lib/floss.js -p test/args -- --autoplay-policy=no-user-gesture-required",
|
|
33
|
-
"preversion": "run-s build test",
|
|
34
|
-
"postpublish": "git push && git push --tags",
|
|
35
|
-
"publish:patch": "npm version patch && npm publish",
|
|
36
|
-
"publish:minor": "npm version minor && npm publish",
|
|
37
|
-
"publish:major": "npm version major && npm publish"
|
|
38
|
-
},
|
|
16
|
+
"scripts": {},
|
|
39
17
|
"repository": {
|
|
40
18
|
"type": "git",
|
|
41
19
|
"url": "git@github.com:pixijs/floss.git"
|
|
@@ -75,19 +53,5 @@
|
|
|
75
53
|
"electron": ">=12 <14",
|
|
76
54
|
"nyc": ">=13"
|
|
77
55
|
},
|
|
78
|
-
"devDependencies": {
|
|
79
|
-
"@pixi/eslint-config": "^2.0.1",
|
|
80
|
-
"@types/glob": "^7.1.3",
|
|
81
|
-
"@types/mocha": "^8.0.0",
|
|
82
|
-
"@types/resolve": "^1.17.1",
|
|
83
|
-
"chai": "^4.2.0",
|
|
84
|
-
"copyfiles": "^2.4.1",
|
|
85
|
-
"electron": "^12.0.0",
|
|
86
|
-
"eslint": "^7.18.0",
|
|
87
|
-
"npm-run-all": "^4.1.5",
|
|
88
|
-
"nyc": "^14.0.0",
|
|
89
|
-
"rimraf": "^3.0.2",
|
|
90
|
-
"ts-node": "^9.1.1",
|
|
91
|
-
"typescript": "^3.9.0"
|
|
92
|
-
}
|
|
56
|
+
"devDependencies": {}
|
|
93
57
|
}
|