@lvce-editor/test-with-playwright 1.7.0 → 2.1.0
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/bin/test-with-playwright.js +3 -1
- package/package.json +7 -3
- package/src/main.js +3 -0
- package/src/parts/Command/Command.js +1 -9
- package/src/parts/HandleIpc/HandleIpc.js +3 -13
- package/src/parts/HandleMessage/HandleMessage.js +26 -0
- package/src/parts/IpcParent/IpcParent.js +1 -1
- package/src/parts/IpcParentModule/IpcParentModule.js +2 -1
- package/src/parts/JsonRpc/JsonRpc.js +1 -35
- package/src/parts/{Cli/Cli.js → Main/Main.js} +3 -5
- package/src/parts/Assert/Assert.js +0 -1
- package/src/parts/Callback/Callback.js +0 -39
- package/src/parts/CommandState/CommandState.js +0 -17
- package/src/parts/FirstNodeWorkerEventType/FirstNodeWorkerEventType.js +0 -5
- package/src/parts/GetFirstNodeWorkerEvent/GetFirstNodeWorkerEvent.js +0 -28
- package/src/parts/GetPort/GetPort.js +0 -5
- package/src/parts/GetTests/GetTests.js +0 -9
- package/src/parts/Id/Id.js +0 -7
- package/src/parts/IpcError/IpcError.js +0 -6
- package/src/parts/IpcParentWithNodeWorker/IpcParentWithNodeWorker.js +0 -41
- package/src/parts/JsonRpcVersion/JsonRpcVersion.js +0 -1
- package/src/parts/Signal/Signal.js +0 -1
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/test-with-playwright",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "src/
|
|
5
|
+
"main": "src/main.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": "bin/test-with-playwright.js",
|
|
8
8
|
"repository": {
|
|
@@ -14,8 +14,12 @@
|
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@lvce-editor/assert": "^1.3.0",
|
|
17
|
+
"@lvce-editor/command": "^1.2.0",
|
|
18
|
+
"@lvce-editor/ipc": "^11.1.0",
|
|
19
|
+
"@lvce-editor/json-rpc": "^5.0.0",
|
|
20
|
+
"@lvce-editor/verror": "^1.6.0",
|
|
17
21
|
"minimist": "^1.2.8",
|
|
18
|
-
"@lvce-editor/test-with-playwright-worker": "1.
|
|
22
|
+
"@lvce-editor/test-with-playwright-worker": "2.1.0"
|
|
19
23
|
},
|
|
20
24
|
"devDependencies": {
|
|
21
25
|
"@types/jest": "^29.5.12",
|
package/src/main.js
ADDED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export const execute = (command, ...args) => {
|
|
4
|
-
const fn = CommandState.getCommand(command)
|
|
5
|
-
if (!fn) {
|
|
6
|
-
throw new Error(`Command not found ${command}`)
|
|
7
|
-
}
|
|
8
|
-
return fn(...args)
|
|
9
|
-
}
|
|
1
|
+
export * from '@lvce-editor/command'
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as Command from '../Command/Command.js'
|
|
1
|
+
import * as HandleMessage from '../HandleMessage/HandleMessage.js'
|
|
3
2
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
if ('result' in message || 'error' in message) {
|
|
7
|
-
Callback.resolve(message.id, message)
|
|
8
|
-
return
|
|
9
|
-
}
|
|
10
|
-
if ('method' in message) {
|
|
11
|
-
await Command.execute(message.method, ...message.params)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
ipc.on('message', handleMessage)
|
|
3
|
+
export const handleIpc = (ipc) => {
|
|
4
|
+
ipc.addEventListener('message', HandleMessage.handleMessage)
|
|
15
5
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as Command from '../Command/Command.js'
|
|
2
|
+
import * as JsonRpc from '../JsonRpc/JsonRpc.js'
|
|
3
|
+
|
|
4
|
+
const prepare = (error) => {
|
|
5
|
+
return error
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const requiresSocket = (method) => {
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const logError = (error) => {
|
|
13
|
+
console.error(error)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const handleMessage = (event) => {
|
|
17
|
+
return JsonRpc.handleJsonRpcMessage(
|
|
18
|
+
event.target,
|
|
19
|
+
event.data,
|
|
20
|
+
Command.execute,
|
|
21
|
+
JsonRpc.resolve,
|
|
22
|
+
prepare,
|
|
23
|
+
logError,
|
|
24
|
+
requiresSocket,
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as IpcParentModule from '../IpcParentModule/IpcParentModule.js'
|
|
2
2
|
|
|
3
3
|
export const create = async ({ method, ...options }) => {
|
|
4
|
-
const module =
|
|
4
|
+
const module = IpcParentModule.getModule(method)
|
|
5
5
|
// @ts-ignore
|
|
6
6
|
const rawIpc = await module.create(options)
|
|
7
7
|
const ipc = module.wrap(rawIpc)
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as IpcParentType from '../IpcParentType/IpcParentType.js'
|
|
2
|
+
import { IpcParentWithNodeWorker } from '@lvce-editor/ipc'
|
|
2
3
|
|
|
3
4
|
export const getModule = (method) => {
|
|
4
5
|
switch (method) {
|
|
5
6
|
case IpcParentType.NodeWorker:
|
|
6
|
-
return
|
|
7
|
+
return IpcParentWithNodeWorker
|
|
7
8
|
default:
|
|
8
9
|
throw new Error('unexpected ipc type')
|
|
9
10
|
}
|
|
@@ -1,35 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import * as JsonRpcVersion from '../JsonRpcVersion/JsonRpcVersion.js'
|
|
3
|
-
|
|
4
|
-
export const send = (transport, method, ...params) => {
|
|
5
|
-
transport.send({
|
|
6
|
-
jsonrpc: JsonRpcVersion.Two,
|
|
7
|
-
method,
|
|
8
|
-
params,
|
|
9
|
-
})
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const invoke = (ipc, method, ...params) => {
|
|
13
|
-
const { id, promise } = Callback.registerPromise()
|
|
14
|
-
ipc.send({
|
|
15
|
-
jsonrpc: JsonRpcVersion.Two,
|
|
16
|
-
method,
|
|
17
|
-
params,
|
|
18
|
-
id,
|
|
19
|
-
})
|
|
20
|
-
return promise
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const invokeAndTransfer = (ipc, handle, method, ...params) => {
|
|
24
|
-
const { id, promise } = Callback.registerPromise()
|
|
25
|
-
ipc.sendAndTransfer(
|
|
26
|
-
{
|
|
27
|
-
jsonrpc: JsonRpcVersion.Two,
|
|
28
|
-
method,
|
|
29
|
-
params,
|
|
30
|
-
id,
|
|
31
|
-
},
|
|
32
|
-
handle
|
|
33
|
-
)
|
|
34
|
-
return promise
|
|
35
|
-
}
|
|
1
|
+
export * from '@lvce-editor/json-rpc'
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
+
import * as Command from '../Command/Command.js'
|
|
2
|
+
import * as CommandMap from '../CommandMap/CommandMap.js'
|
|
1
3
|
import * as HandleCliArgs from '../HandleCliArgs/HandleCliArgs.js'
|
|
2
4
|
import * as Process from '../Process/Process.js'
|
|
3
5
|
import * as ProcessListeners from '../ProcessListeners/ProcessListeners.js'
|
|
4
|
-
import * as CommandState from '../CommandState/CommandState.js'
|
|
5
|
-
import * as CommandMap from '../CommandMap/CommandMap.js'
|
|
6
6
|
|
|
7
7
|
export const main = () => {
|
|
8
8
|
Process.on('uncaughtExceptionMonitor', ProcessListeners.handleUncaughtExceptionMonitor)
|
|
9
|
-
|
|
9
|
+
Command.register(CommandMap.commandMap)
|
|
10
10
|
HandleCliArgs.handleCliArgs({ argv: Process.argv, env: Process.env })
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
main()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@lvce-editor/assert'
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import * as Id from '../Id/Id.js'
|
|
2
|
-
|
|
3
|
-
export const state = {
|
|
4
|
-
callbacks: Object.create(null),
|
|
5
|
-
onceListeners: new Set(),
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const registerPromise = () => {
|
|
9
|
-
const id = Id.create()
|
|
10
|
-
const promise = new Promise((resolve, reject) => {
|
|
11
|
-
state.callbacks[id] = { resolve, reject }
|
|
12
|
-
})
|
|
13
|
-
return { id, promise }
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// TODO merge resolve and resolveEmpty
|
|
17
|
-
export const resolve = (id, args) => {
|
|
18
|
-
const { callbacks } = state
|
|
19
|
-
if (!(id in callbacks)) {
|
|
20
|
-
console.warn(`callback ${id} may already be disposed`)
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
callbacks[id].resolve(args)
|
|
24
|
-
delete callbacks[id]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const reject = (id, error) => {
|
|
28
|
-
const { callbacks } = state
|
|
29
|
-
if (!(id in callbacks)) {
|
|
30
|
-
console.warn(`callback (rejected) ${id} may already be disposed`)
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
callbacks[id].reject(error)
|
|
34
|
-
delete callbacks[id]
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const isAllEmpty = () => {
|
|
38
|
-
return Object.keys(state.callbacks).length === 0 && state.onceListeners.size === 0
|
|
39
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export const state = {
|
|
2
|
-
commands: Object.create(null),
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export const registerCommand = (key, fn) => {
|
|
6
|
-
state.commands[key] = fn
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const registerCommands = (commandMap) => {
|
|
10
|
-
for (const [key, value] of Object.entries(commandMap)) {
|
|
11
|
-
registerCommand(key, value)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const getCommand = (key) => {
|
|
16
|
-
return state.commands[key]
|
|
17
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import * as FirstNodeWorkerEventType from '../FirstNodeWorkerEventType/FirstNodeWorkerEventType.js'
|
|
2
|
-
|
|
3
|
-
export const getFirstNodeWorkerEvent = async (worker) => {
|
|
4
|
-
const { type, event } = await new Promise((resolve, reject) => {
|
|
5
|
-
const cleanup = (value) => {
|
|
6
|
-
worker.off('message', handleMessage)
|
|
7
|
-
worker.off('exit', handleExit)
|
|
8
|
-
worker.off('error', handleError)
|
|
9
|
-
resolve(value)
|
|
10
|
-
}
|
|
11
|
-
const handleMessage = (event) => {
|
|
12
|
-
cleanup({
|
|
13
|
-
type: FirstNodeWorkerEventType.Message,
|
|
14
|
-
event,
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
const handleExit = (event) => {
|
|
18
|
-
cleanup({ type: FirstNodeWorkerEventType.Exit, event })
|
|
19
|
-
}
|
|
20
|
-
const handleError = (event) => {
|
|
21
|
-
cleanup({ type: FirstNodeWorkerEventType.Error, event })
|
|
22
|
-
}
|
|
23
|
-
worker.on('message', handleMessage)
|
|
24
|
-
worker.on('exit', handleExit)
|
|
25
|
-
worker.on('error', handleError)
|
|
26
|
-
})
|
|
27
|
-
return { type, event }
|
|
28
|
-
}
|
package/src/parts/Id/Id.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Worker } from 'node:worker_threads'
|
|
2
|
-
import * as Assert from '../Assert/Assert.js'
|
|
3
|
-
import * as FirstNodeWorkerEventType from '../FirstNodeWorkerEventType/FirstNodeWorkerEventType.js'
|
|
4
|
-
import * as GetFirstNodeWorkerEvent from '../GetFirstNodeWorkerEvent/GetFirstNodeWorkerEvent.js'
|
|
5
|
-
import { IpcError } from '../IpcError/IpcError.js'
|
|
6
|
-
|
|
7
|
-
export const create = async ({ path, argv, env, execArgv }) => {
|
|
8
|
-
Assert.string(path)
|
|
9
|
-
const actualArgv = ['--ipc-type=node-worker', ...argv]
|
|
10
|
-
const worker = new Worker(path, {
|
|
11
|
-
argv: actualArgv,
|
|
12
|
-
env,
|
|
13
|
-
execArgv,
|
|
14
|
-
})
|
|
15
|
-
const { type, event } = await GetFirstNodeWorkerEvent.getFirstNodeWorkerEvent(worker)
|
|
16
|
-
if (type === FirstNodeWorkerEventType.Error) {
|
|
17
|
-
throw event
|
|
18
|
-
}
|
|
19
|
-
if (type === FirstNodeWorkerEventType.Exit) {
|
|
20
|
-
throw new IpcError('worker exited unexpectedly')
|
|
21
|
-
}
|
|
22
|
-
return worker
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const wrap = (worker) => {
|
|
26
|
-
return {
|
|
27
|
-
worker,
|
|
28
|
-
on(event, listener) {
|
|
29
|
-
this.worker.on(event, listener)
|
|
30
|
-
},
|
|
31
|
-
send(message) {
|
|
32
|
-
this.worker.postMessage(message)
|
|
33
|
-
},
|
|
34
|
-
sendAndTransfer(message, transfer) {
|
|
35
|
-
this.worker.postMessage(message, transfer)
|
|
36
|
-
},
|
|
37
|
-
dispose() {
|
|
38
|
-
this.worker.terminate()
|
|
39
|
-
},
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const Two = '2.0'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const SIGINT = 'SIGINT'
|