@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.
@@ -1 +1,3 @@
1
- import '../src/parts/Cli/Cli.js'
1
+ #!/usr/bin/env node
2
+
3
+ import '../src/main.js'
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@lvce-editor/test-with-playwright",
3
- "version": "1.7.0",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
- "main": "src/parts/RunAllTests/RunAllTests.js",
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.7.0"
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
@@ -0,0 +1,3 @@
1
+ import * as Main from './parts/Main/Main.js'
2
+
3
+ Main.main()
@@ -1,9 +1 @@
1
- import * as CommandState from '../CommandState/CommandState.js'
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 Callback from '../Callback/Callback.js'
2
- import * as Command from '../Command/Command.js'
1
+ import * as HandleMessage from '../HandleMessage/HandleMessage.js'
3
2
 
4
- export function handleIpc(ipc) {
5
- const handleMessage = async (message) => {
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 = await IpcParentModule.getModule(method)
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 import('../IpcParentWithNodeWorker/IpcParentWithNodeWorker.js')
7
+ return IpcParentWithNodeWorker
7
8
  default:
8
9
  throw new Error('unexpected ipc type')
9
10
  }
@@ -1,35 +1 @@
1
- import * as Callback from '../Callback/Callback.js'
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
- CommandState.registerCommands(CommandMap.commandMap)
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,5 +0,0 @@
1
- export const Exit = 'exit'
2
-
3
- export const Error = 'error'
4
-
5
- export const Message = 'message'
@@ -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
- }
@@ -1,5 +0,0 @@
1
- import _getPort from 'get-port'
2
-
3
- export const getPort = () => {
4
- return _getPort()
5
- }
@@ -1,9 +0,0 @@
1
- import { readdir } from 'fs/promises'
2
-
3
- /**
4
- * @param {string} testSrc
5
- */
6
- export const getTests = async (testSrc) => {
7
- const dirents = await readdir(testSrc)
8
- return dirents
9
- }
@@ -1,7 +0,0 @@
1
- export const state = {
2
- id: 0,
3
- }
4
-
5
- export const create = () => {
6
- return ++state.id
7
- }
@@ -1,6 +0,0 @@
1
- export class IpcError extends Error {
2
- constructor(message) {
3
- super(message)
4
- this.name = 'IpcError'
5
- }
6
- }
@@ -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'