ohos-playwright 0.1.0 → 0.1.1
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/package.json +5 -1
- package/src/cli.mjs +21 -5
- package/src/loader.mjs +27 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohos-playwright",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Playwright adapter for OpenHarmony / ArkWeb via hdc + CDP",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "social4hyq",
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
"cdp"
|
|
24
24
|
],
|
|
25
25
|
"type": "module",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "node --test src/loader.test.mjs"
|
|
28
|
+
},
|
|
26
29
|
"engines": {
|
|
27
30
|
"node": ">=24"
|
|
28
31
|
},
|
|
@@ -42,6 +45,7 @@
|
|
|
42
45
|
},
|
|
43
46
|
"files": [
|
|
44
47
|
"src",
|
|
48
|
+
"!src/*.test.mjs",
|
|
45
49
|
"SKILL.md"
|
|
46
50
|
],
|
|
47
51
|
"peerDependencies": {
|
package/src/cli.mjs
CHANGED
|
@@ -3,18 +3,34 @@ import { spawn } from 'node:child_process'
|
|
|
3
3
|
import { existsSync } from 'node:fs'
|
|
4
4
|
import { createRequire } from 'node:module'
|
|
5
5
|
import { dirname, resolve } from 'node:path'
|
|
6
|
-
import { fileURLToPath } from 'node:url'
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
// Resolve @playwright/test from the consumer's project root (process.cwd()),
|
|
8
|
+
// not from this package's own directory (which has no node_modules/ for its
|
|
9
|
+
// peer dependencies when installed via a file: symlink).
|
|
10
|
+
// noop.mjs doesn't need to exist on disk -- createRequire uses it only to
|
|
11
|
+
// anchor the module resolution base path.
|
|
12
|
+
const req = createRequire(resolve(process.cwd(), 'noop.mjs'))
|
|
10
13
|
|
|
11
14
|
// @playwright/test's exports map blocks direct subpath resolution to cli.js,
|
|
12
15
|
// so resolve the main entry and walk up to the package root, then append it.
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
let pwEntry
|
|
17
|
+
try {
|
|
18
|
+
pwEntry = req.resolve('@playwright/test')
|
|
19
|
+
} catch {
|
|
20
|
+
console.error(
|
|
21
|
+
`[ohos-playwright] Cannot find @playwright/test from ${process.cwd()}.\n` +
|
|
22
|
+
'Make sure it is installed in the current project or an ancestor:\n' +
|
|
23
|
+
' npm install -D @playwright/test\n' +
|
|
24
|
+
' pnpm add -D @playwright/test',
|
|
25
|
+
)
|
|
26
|
+
process.exit(1)
|
|
27
|
+
}
|
|
28
|
+
let pkgRoot = dirname(pwEntry)
|
|
15
29
|
while (!existsSync(resolve(pkgRoot, 'package.json'))) pkgRoot = dirname(pkgRoot)
|
|
16
30
|
const playwrightCli = resolve(pkgRoot, 'cli.js')
|
|
17
31
|
|
|
32
|
+
const register = resolve(import.meta.dirname, 'register.mjs')
|
|
33
|
+
|
|
18
34
|
const child = spawn(
|
|
19
35
|
process.execPath,
|
|
20
36
|
['--import', register, playwrightCli, ...process.argv.slice(2)],
|
package/src/loader.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { resolve as resolvePath
|
|
2
|
-
import {
|
|
1
|
+
import { resolve as resolvePath } from 'node:path'
|
|
2
|
+
import { pathToFileURL } from 'node:url'
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
const FIXTURE_URL = pathToFileURL(resolvePath(__dirname, 'fixture.mjs')).href
|
|
4
|
+
const FIXTURE_URL = pathToFileURL(resolvePath(import.meta.dirname, 'fixture.mjs')).href
|
|
6
5
|
|
|
7
6
|
const TARGET = '@playwright/test'
|
|
8
7
|
|
|
@@ -12,12 +11,36 @@ const TARGET = '@playwright/test'
|
|
|
12
11
|
// stay on stock Playwright.
|
|
13
12
|
const TEST_FILE = /\.(spec|test)\.[mc]?[tj]sx?$/
|
|
14
13
|
|
|
14
|
+
// Compute the package root URL from the loader's own location. Used below to
|
|
15
|
+
// detect when the importing module lives inside ohos-playwright, regardless of
|
|
16
|
+
// what the package directory is named or how it was installed (file: symlink,
|
|
17
|
+
// pnpm store hash, etc.). Trailing '/' is critical to avoid matching sibling
|
|
18
|
+
// directories whose names happen to share the same prefix.
|
|
19
|
+
const PACKAGE_ROOT_URL = pathToFileURL(resolvePath(import.meta.dirname, '..') + '/').href
|
|
20
|
+
|
|
21
|
+
// Anchor URL in the consumer project root for ESM resolution fallback.
|
|
22
|
+
// When ohos-playwright is a file: symlink, modules inside it can't resolve
|
|
23
|
+
// peer dependencies from the consumer's node_modules. Overriding parentURL
|
|
24
|
+
// to a file inside the project restores normal resolution.
|
|
25
|
+
// noop.mjs doesn't need to exist on disk.
|
|
26
|
+
// PROJECT_ANCHOR is computed once at module-load time. By the time this
|
|
27
|
+
// module is --import'ed (via register.mjs), process.cwd() is guaranteed to be
|
|
28
|
+
// the directory where the user invoked ohos-playwright test — Node sets cwd
|
|
29
|
+
// before running --import hooks. Do NOT defer this to the resolve hook; the
|
|
30
|
+
// string is needed for synchronous prefix matching in the hot path.
|
|
31
|
+
const PROJECT_ANCHOR = pathToFileURL(resolvePath(process.cwd(), 'noop.mjs')).href
|
|
32
|
+
|
|
15
33
|
export async function resolve(specifier, context, nextResolve) {
|
|
16
34
|
if (specifier === TARGET) {
|
|
17
35
|
const parent = context.parentURL ?? ''
|
|
18
36
|
if (TEST_FILE.test(parent)) {
|
|
37
|
+
// Spec files -> use custom ArkWeb fixture
|
|
19
38
|
return nextResolve(FIXTURE_URL, context)
|
|
20
39
|
}
|
|
40
|
+
if (parent.startsWith(PACKAGE_ROOT_URL)) {
|
|
41
|
+
// Internal modules (fixture.mjs, etc.) -> resolve from consumer project
|
|
42
|
+
return nextResolve(specifier, { ...context, parentURL: PROJECT_ANCHOR })
|
|
43
|
+
}
|
|
21
44
|
}
|
|
22
45
|
return nextResolve(specifier, context)
|
|
23
46
|
}
|