@lvce-editor/test-worker 1.14.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.
Files changed (2) hide show
  1. package/dist/testWorkerMain.js +1242 -1271
  2. package/package.json +1 -1
@@ -1,44 +1,66 @@
1
- const commands = Object.create(null);
2
- const registerCommand = (key, fn) => {
3
- commands[key] = fn;
4
- };
5
- const register = commandMap => {
6
- for (const [key, value] of Object.entries(commandMap)) {
7
- registerCommand(key, value);
1
+ const normalizeLine = line => {
2
+ if (line.startsWith('Error: ')) {
3
+ return line.slice('Error: '.length);
8
4
  }
9
- };
10
- const getCommand = key => {
11
- return commands[key];
12
- };
13
- const execute$3 = (command, ...args) => {
14
- const fn = getCommand(command);
15
- if (!fn) {
16
- throw new Error(`command not found ${command}`);
5
+ if (line.startsWith('VError: ')) {
6
+ return line.slice('VError: '.length);
17
7
  }
18
- return fn(...args);
8
+ return line;
19
9
  };
20
-
21
- const state$3 = {
22
- /**
23
- * @type {any}
24
- */
25
- ipc: undefined
10
+ const getCombinedMessage = (error, message) => {
11
+ const stringifiedError = normalizeLine(`${error}`);
12
+ if (message) {
13
+ return `${message}: ${stringifiedError}`;
14
+ }
15
+ return stringifiedError;
26
16
  };
27
- const get$1 = () => {
28
- return state$3.ipc;
17
+ const NewLine$2 = '\n';
18
+ const getNewLineIndex$1 = (string, startIndex = undefined) => {
19
+ return string.indexOf(NewLine$2, startIndex);
29
20
  };
30
- const set$1 = ipc => {
31
- state$3.ipc = ipc;
21
+ const mergeStacks = (parent, child) => {
22
+ if (!child) {
23
+ return parent;
24
+ }
25
+ const parentNewLineIndex = getNewLineIndex$1(parent);
26
+ const childNewLineIndex = getNewLineIndex$1(child);
27
+ if (childNewLineIndex === -1) {
28
+ return parent;
29
+ }
30
+ const parentFirstLine = parent.slice(0, parentNewLineIndex);
31
+ const childRest = child.slice(childNewLineIndex);
32
+ const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
33
+ if (parentFirstLine.includes(childFirstLine)) {
34
+ return parentFirstLine + childRest;
35
+ }
36
+ return child;
32
37
  };
38
+ class VError extends Error {
39
+ constructor(error, message) {
40
+ const combinedMessage = getCombinedMessage(error, message);
41
+ super(combinedMessage);
42
+ this.name = 'VError';
43
+ if (error instanceof Error) {
44
+ this.stack = mergeStacks(this.stack, error.stack);
45
+ }
46
+ if (error.codeFrame) {
47
+ // @ts-ignore
48
+ this.codeFrame = error.codeFrame;
49
+ }
50
+ if (error.code) {
51
+ // @ts-ignore
52
+ this.code = error.code;
53
+ }
54
+ }
55
+ }
33
56
 
34
- const Two = '2.0';
35
- let AssertionError$1 = class AssertionError extends Error {
57
+ class AssertionError extends Error {
36
58
  constructor(message) {
37
59
  super(message);
38
60
  this.name = 'AssertionError';
39
61
  }
40
- };
41
- const getType$1 = value => {
62
+ }
63
+ const getType = value => {
42
64
  switch (typeof value) {
43
65
  case 'number':
44
66
  return 'number';
@@ -60,501 +82,867 @@ const getType$1 = value => {
60
82
  return 'unknown';
61
83
  }
62
84
  };
63
- const number = value => {
64
- const type = getType$1(value);
65
- if (type !== 'number') {
66
- throw new AssertionError$1('expected value to be of type number');
85
+ const object = value => {
86
+ const type = getType(value);
87
+ if (type !== 'object') {
88
+ throw new AssertionError('expected value to be of type object');
67
89
  }
68
90
  };
69
- const state$1 = {
70
- callbacks: Object.create(null)
91
+ const string = value => {
92
+ const type = getType(value);
93
+ if (type !== 'string') {
94
+ throw new AssertionError('expected value to be of type string');
95
+ }
71
96
  };
72
- const set = (id, fn) => {
73
- state$1.callbacks[id] = fn;
97
+
98
+ const walkValue = (value, transferrables, isTransferrable) => {
99
+ if (!value) {
100
+ return;
101
+ }
102
+ if (isTransferrable(value)) {
103
+ transferrables.push(value);
104
+ return;
105
+ }
106
+ if (Array.isArray(value)) {
107
+ for (const item of value) {
108
+ walkValue(item, transferrables, isTransferrable);
109
+ }
110
+ return;
111
+ }
112
+ if (typeof value === 'object') {
113
+ for (const property of Object.values(value)) {
114
+ walkValue(property, transferrables, isTransferrable);
115
+ }
116
+ return;
117
+ }
74
118
  };
75
- const get = id => {
76
- return state$1.callbacks[id];
119
+ const isMessagePort = value => {
120
+ return value && value instanceof MessagePort;
77
121
  };
78
- const remove = id => {
79
- delete state$1.callbacks[id];
122
+ const isMessagePortMain = value => {
123
+ return value && value.constructor && value.constructor.name === 'MessagePortMain';
80
124
  };
81
- const state$2 = {
82
- id: 0
125
+ const isOffscreenCanvas = value => {
126
+ return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
83
127
  };
84
- const create$3 = () => {
85
- return ++state$2.id;
128
+ const isInstanceOf = (value, constructorName) => {
129
+ return value?.constructor?.name === constructorName;
86
130
  };
87
- const warn = (...args) => {
88
- console.warn(...args);
131
+ const isSocket = value => {
132
+ return isInstanceOf(value, 'Socket');
89
133
  };
90
- const withResolvers$1 = () => {
91
- /**
92
- * @type {any}
93
- */
94
- let _resolve;
95
- const promise = new Promise(resolve => {
96
- _resolve = resolve;
97
- });
98
- return {
99
- resolve: _resolve,
100
- promise
101
- };
134
+ const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
135
+ const isTransferrable = value => {
136
+ for (const fn of transferrables) {
137
+ if (fn(value)) {
138
+ return true;
139
+ }
140
+ }
141
+ return false;
102
142
  };
103
- const registerPromise = () => {
104
- const id = create$3();
105
- const {
106
- resolve,
107
- promise
108
- } = withResolvers$1();
109
- set(id, resolve);
110
- return {
111
- id,
112
- promise
143
+ const getTransferrables = value => {
144
+ const transferrables = [];
145
+ walkValue(value, transferrables, isTransferrable);
146
+ return transferrables;
147
+ };
148
+ const attachEvents = that => {
149
+ const handleMessage = (...args) => {
150
+ const data = that.getData(...args);
151
+ that.dispatchEvent(new MessageEvent('message', {
152
+ data
153
+ }));
113
154
  };
155
+ that.onMessage(handleMessage);
156
+ const handleClose = event => {
157
+ that.dispatchEvent(new Event('close'));
158
+ };
159
+ that.onClose(handleClose);
114
160
  };
115
- const resolve = (id, args) => {
116
- number(id);
117
- const fn = get(id);
118
- if (!fn) {
119
- console.log(args);
120
- warn(`callback ${id} may already be disposed`);
121
- return;
161
+ class Ipc extends EventTarget {
162
+ constructor(rawIpc) {
163
+ super();
164
+ this._rawIpc = rawIpc;
165
+ attachEvents(this);
122
166
  }
123
- fn(args);
124
- remove(id);
167
+ }
168
+ const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
169
+ const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
170
+ const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
171
+ const NewLine$1 = '\n';
172
+ const joinLines$1 = lines => {
173
+ return lines.join(NewLine$1);
125
174
  };
126
- const create$2 = (method, params) => {
127
- const {
128
- id,
129
- promise
130
- } = registerPromise();
131
- const message = {
132
- jsonrpc: Two,
133
- method,
134
- params,
135
- id
136
- };
175
+ const splitLines$1 = lines => {
176
+ return lines.split(NewLine$1);
177
+ };
178
+ const isModuleNotFoundMessage = line => {
179
+ return line.includes('[ERR_MODULE_NOT_FOUND]');
180
+ };
181
+ const getModuleNotFoundError = stderr => {
182
+ const lines = splitLines$1(stderr);
183
+ const messageIndex = lines.findIndex(isModuleNotFoundMessage);
184
+ const message = lines[messageIndex];
137
185
  return {
138
186
  message,
139
- promise
187
+ code: ERR_MODULE_NOT_FOUND
140
188
  };
141
189
  };
142
- class JsonRpcError extends Error {
143
- constructor(message) {
144
- super(message);
145
- this.name = 'JsonRpcError';
146
- }
147
- }
148
- const NewLine$3 = '\n';
149
- const DomException = 'DOMException';
150
- const ReferenceError$1 = 'ReferenceError';
151
- const SyntaxError$1 = 'SyntaxError';
152
- const TypeError$1 = 'TypeError';
153
- const getErrorConstructor = (message, type) => {
154
- if (type) {
155
- switch (type) {
156
- case DomException:
157
- return DOMException;
158
- case TypeError$1:
159
- return TypeError;
160
- case SyntaxError$1:
161
- return SyntaxError;
162
- case ReferenceError$1:
163
- return ReferenceError;
164
- default:
165
- return Error;
166
- }
167
- }
168
- if (message.startsWith('TypeError: ')) {
169
- return TypeError;
170
- }
171
- if (message.startsWith('SyntaxError: ')) {
172
- return SyntaxError;
173
- }
174
- if (message.startsWith('ReferenceError: ')) {
175
- return ReferenceError;
176
- }
177
- return Error;
190
+ const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
191
+ const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
192
+ const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
193
+ const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
194
+ const RE_AT = /^\s+at/;
195
+ const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
196
+ const isUnhelpfulNativeModuleError = stderr => {
197
+ return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
178
198
  };
179
- const constructError = (message, type, name) => {
180
- const ErrorConstructor = getErrorConstructor(message, type);
181
- if (ErrorConstructor === DOMException && name) {
182
- return new ErrorConstructor(message, name);
183
- }
184
- if (ErrorConstructor === Error) {
185
- const error = new Error(message);
186
- if (name && name !== 'VError') {
187
- error.name = name;
188
- }
189
- return error;
190
- }
191
- return new ErrorConstructor(message);
199
+ const isMessageCodeBlockStartIndex = line => {
200
+ return RE_MESSAGE_CODE_BLOCK_START.test(line);
192
201
  };
193
- const getNewLineIndex$2 = (string, startIndex = undefined) => {
194
- return string.indexOf(NewLine$3, startIndex);
202
+ const isMessageCodeBlockEndIndex = line => {
203
+ return RE_MESSAGE_CODE_BLOCK_END.test(line);
195
204
  };
196
- const getParentStack = error => {
197
- let parentStack = error.stack || error.data || error.message || '';
198
- if (parentStack.startsWith(' at')) {
199
- parentStack = error.message + NewLine$3 + parentStack;
200
- }
201
- return parentStack;
202
- };
203
- const joinLines$1 = lines => {
204
- return lines.join(NewLine$3);
205
+ const getMessageCodeBlock = stderr => {
206
+ const lines = splitLines$1(stderr);
207
+ const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
208
+ const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
209
+ const relevantLines = lines.slice(startIndex, endIndex);
210
+ const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
211
+ return relevantMessage;
205
212
  };
206
- const MethodNotFound = -32601;
207
- const Custom = -32001;
208
- const splitLines$1 = lines => {
209
- return lines.split(NewLine$3);
213
+ const getNativeModuleErrorMessage = stderr => {
214
+ const message = getMessageCodeBlock(stderr);
215
+ return {
216
+ message: `Incompatible native node module: ${message}`,
217
+ code: E_INCOMPATIBLE_NATIVE_MODULE
218
+ };
210
219
  };
211
- const restoreJsonRpcError = error => {
212
- if (error && error instanceof Error) {
213
- return error;
214
- }
215
- const currentStack = joinLines$1(splitLines$1(new Error().stack || '').slice(1));
216
- if (error && error.code && error.code === MethodNotFound) {
217
- const restoredError = new JsonRpcError(error.message);
218
- const parentStack = getParentStack(error);
219
- restoredError.stack = parentStack + NewLine$3 + currentStack;
220
- return restoredError;
221
- }
222
- if (error && error.message) {
223
- const restoredError = constructError(error.message, error.type, error.name);
224
- if (error.data) {
225
- if (error.data.stack && error.data.type && error.message) {
226
- restoredError.stack = error.data.type + ': ' + error.message + NewLine$3 + error.data.stack + NewLine$3 + currentStack;
227
- } else if (error.data.stack) {
228
- restoredError.stack = error.data.stack;
229
- }
230
- if (error.data.codeFrame) {
231
- // @ts-ignore
232
- restoredError.codeFrame = error.data.codeFrame;
233
- }
234
- if (error.data.code) {
235
- // @ts-ignore
236
- restoredError.code = error.data.code;
237
- }
238
- if (error.data.type) {
239
- // @ts-ignore
240
- restoredError.name = error.data.type;
241
- }
242
- } else {
243
- if (error.stack) {
244
- const lowerStack = restoredError.stack || '';
245
- // @ts-ignore
246
- const indexNewLine = getNewLineIndex$2(lowerStack);
247
- const parentStack = getParentStack(error);
248
- // @ts-ignore
249
- restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
250
- }
251
- if (error.codeFrame) {
252
- // @ts-ignore
253
- restoredError.codeFrame = error.codeFrame;
254
- }
255
- }
256
- return restoredError;
257
- }
258
- if (typeof error === 'string') {
259
- return new Error(`JsonRpc Error: ${error}`);
220
+ const isModulesSyntaxError = stderr => {
221
+ if (!stderr) {
222
+ return false;
260
223
  }
261
- return new Error(`JsonRpc Error: ${error}`);
224
+ return stderr.includes('SyntaxError: Cannot use import statement outside a module');
262
225
  };
263
- const unwrapJsonRpcResult = responseMessage => {
264
- if ('error' in responseMessage) {
265
- const restoredError = restoreJsonRpcError(responseMessage.error);
266
- throw restoredError;
267
- }
268
- if ('result' in responseMessage) {
269
- return responseMessage.result;
270
- }
271
- throw new JsonRpcError('unexpected response message');
226
+ const getModuleSyntaxError = () => {
227
+ return {
228
+ message: `ES Modules are not supported in electron`,
229
+ code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
230
+ };
272
231
  };
273
- const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
274
- const getType$2 = prettyError => {
275
- if (prettyError && prettyError.type) {
276
- return prettyError.type;
277
- }
278
- if (prettyError && prettyError.constructor && prettyError.constructor.name) {
279
- return prettyError.constructor.name;
232
+ const isModuleNotFoundError = stderr => {
233
+ if (!stderr) {
234
+ return false;
280
235
  }
281
- return undefined;
236
+ return stderr.includes('ERR_MODULE_NOT_FOUND');
282
237
  };
283
- const getErrorProperty = (error, prettyError) => {
284
- if (error && error.code === E_COMMAND_NOT_FOUND) {
238
+ const isNormalStackLine = line => {
239
+ return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
240
+ };
241
+ const getDetails = lines => {
242
+ const index = lines.findIndex(isNormalStackLine);
243
+ if (index === -1) {
285
244
  return {
286
- code: MethodNotFound,
287
- message: error.message,
288
- data: error.stack
245
+ actualMessage: joinLines$1(lines),
246
+ rest: []
289
247
  };
290
248
  }
291
- return {
292
- code: Custom,
293
- message: prettyError.message,
294
- data: {
295
- stack: prettyError.stack,
296
- codeFrame: prettyError.codeFrame,
297
- type: getType$2(prettyError),
298
- code: prettyError.code,
299
- name: prettyError.name
249
+ let lastIndex = index - 1;
250
+ while (++lastIndex < lines.length) {
251
+ if (!isNormalStackLine(lines[lastIndex])) {
252
+ break;
300
253
  }
301
- };
302
- };
303
- const create$1 = (message, error) => {
254
+ }
304
255
  return {
305
- jsonrpc: Two,
306
- id: message.id,
307
- error
256
+ actualMessage: lines[index - 1],
257
+ rest: lines.slice(index, lastIndex)
308
258
  };
309
259
  };
310
- const getErrorResponse = (message, error, preparePrettyError, logError) => {
311
- const prettyError = preparePrettyError(error);
312
- logError(error, prettyError);
313
- const errorProperty = getErrorProperty(error, prettyError);
314
- return create$1(message, errorProperty);
315
- };
316
- const create$4 = (message, result) => {
260
+ const getHelpfulChildProcessError = (stdout, stderr) => {
261
+ if (isUnhelpfulNativeModuleError(stderr)) {
262
+ return getNativeModuleErrorMessage(stderr);
263
+ }
264
+ if (isModulesSyntaxError(stderr)) {
265
+ return getModuleSyntaxError();
266
+ }
267
+ if (isModuleNotFoundError(stderr)) {
268
+ return getModuleNotFoundError(stderr);
269
+ }
270
+ const lines = splitLines$1(stderr);
271
+ const {
272
+ actualMessage,
273
+ rest
274
+ } = getDetails(lines);
317
275
  return {
318
- jsonrpc: Two,
319
- id: message.id,
320
- result: result ?? null
276
+ message: `${actualMessage}`,
277
+ code: '',
278
+ stack: rest
321
279
  };
322
280
  };
323
- const getSuccessResponse = (message, result) => {
324
- const resultProperty = result ?? null;
325
- return create$4(message, resultProperty);
326
- };
327
- const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
328
- try {
329
- const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
330
- return getSuccessResponse(message, result);
331
- } catch (error) {
332
- return getErrorResponse(message, error, preparePrettyError, logError);
281
+ class IpcError extends VError {
282
+ // @ts-ignore
283
+ constructor(betterMessage, stdout = '', stderr = '') {
284
+ if (stdout || stderr) {
285
+ // @ts-ignore
286
+ const {
287
+ message,
288
+ code,
289
+ stack
290
+ } = getHelpfulChildProcessError(stdout, stderr);
291
+ const cause = new Error(message);
292
+ // @ts-ignore
293
+ cause.code = code;
294
+ cause.stack = stack;
295
+ super(cause, betterMessage);
296
+ } else {
297
+ super(betterMessage);
298
+ }
299
+ // @ts-ignore
300
+ this.name = 'IpcError';
301
+ // @ts-ignore
302
+ this.stdout = stdout;
303
+ // @ts-ignore
304
+ this.stderr = stderr;
333
305
  }
306
+ }
307
+ const readyMessage = 'ready';
308
+ const getData$2 = event => {
309
+ return event.data;
334
310
  };
335
- const defaultPreparePrettyError = error => {
336
- return error;
337
- };
338
- const defaultLogError = () => {
339
- // ignore
311
+ const listen$6 = () => {
312
+ // @ts-ignore
313
+ if (typeof WorkerGlobalScope === 'undefined') {
314
+ throw new TypeError('module is not in web worker scope');
315
+ }
316
+ return globalThis;
340
317
  };
341
- const defaultRequiresSocket = () => {
342
- return false;
318
+ const signal$6 = global => {
319
+ global.postMessage(readyMessage);
343
320
  };
344
- const defaultResolve = resolve;
345
- const handleJsonRpcMessage = async (...args) => {
346
- let message;
347
- let ipc;
348
- let execute;
349
- let preparePrettyError;
350
- let logError;
351
- let resolve;
352
- let requiresSocket;
353
- if (args.length === 1) {
354
- const arg = args[0];
355
- message = arg.message;
356
- ipc = arg.ipc;
357
- execute = arg.execute;
358
- preparePrettyError = arg.preparePrettyError || defaultPreparePrettyError;
359
- logError = arg.logError || defaultLogError;
360
- requiresSocket = arg.requiresSocket || defaultRequiresSocket;
361
- resolve = arg.resolve || defaultResolve;
362
- } else {
363
- ipc = args[0];
364
- message = args[1];
365
- execute = args[2];
366
- resolve = args[3];
367
- preparePrettyError = args[4];
368
- logError = args[5];
369
- requiresSocket = args[6];
321
+ class IpcChildWithModuleWorker extends Ipc {
322
+ getData(event) {
323
+ return getData$2(event);
370
324
  }
371
- if ('id' in message) {
372
- if ('method' in message) {
373
- const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
374
- try {
375
- ipc.send(response);
376
- } catch (error) {
377
- const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
378
- ipc.send(errorResponse);
379
- }
380
- return;
381
- }
382
- resolve(message.id, message);
383
- return;
325
+ send(message) {
326
+ // @ts-ignore
327
+ this._rawIpc.postMessage(message);
384
328
  }
385
- if ('method' in message) {
386
- await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
387
- return;
329
+ sendAndTransfer(message) {
330
+ const transfer = getTransferrables(message);
331
+ // @ts-ignore
332
+ this._rawIpc.postMessage(message, transfer);
388
333
  }
389
- throw new JsonRpcError('unexpected message');
334
+ dispose() {
335
+ // ignore
336
+ }
337
+ onClose(callback) {
338
+ // ignore
339
+ }
340
+ onMessage(callback) {
341
+ this._rawIpc.addEventListener('message', callback);
342
+ }
343
+ }
344
+ const wrap$d = global => {
345
+ return new IpcChildWithModuleWorker(global);
390
346
  };
391
- const invoke$1 = async (ipc, method, ...params) => {
392
- const {
393
- message,
347
+ const withResolvers = () => {
348
+ let _resolve;
349
+ const promise = new Promise(resolve => {
350
+ _resolve = resolve;
351
+ });
352
+ return {
353
+ resolve: _resolve,
394
354
  promise
395
- } = create$2(method, params);
396
- ipc.send(message);
397
- const responseMessage = await promise;
398
- const result = unwrapJsonRpcResult(responseMessage);
399
- return result;
355
+ };
400
356
  };
401
- const invokeAndTransfer$1 = async (ipc, method, ...params) => {
357
+ const waitForFirstMessage = async port => {
402
358
  const {
403
- message,
359
+ resolve,
404
360
  promise
405
- } = create$2(method, params);
406
- ipc.sendAndTransfer(message);
407
- const responseMessage = await promise;
408
- const result = unwrapJsonRpcResult(responseMessage);
409
- return result;
410
- };
411
-
412
- const invoke = (method, ...params) => {
413
- const ipc = get$1();
414
- return invoke$1(ipc, method, ...params);
361
+ } = withResolvers();
362
+ port.addEventListener('message', resolve, {
363
+ once: true
364
+ });
365
+ const event = await promise;
366
+ // @ts-ignore
367
+ return event.data;
415
368
  };
416
- const invokeAndTransfer = (method, ...params) => {
417
- const ipc = get$1();
418
- return invokeAndTransfer$1(ipc, method, ...params);
369
+ const listen$5 = async () => {
370
+ const parentIpcRaw = listen$6();
371
+ signal$6(parentIpcRaw);
372
+ const parentIpc = wrap$d(parentIpcRaw);
373
+ const firstMessage = await waitForFirstMessage(parentIpc);
374
+ if (firstMessage.method !== 'initialize') {
375
+ throw new IpcError('unexpected first message');
376
+ }
377
+ const type = firstMessage.params[0];
378
+ if (type === 'message-port') {
379
+ parentIpc.send({
380
+ jsonrpc: '2.0',
381
+ id: firstMessage.id,
382
+ result: null
383
+ });
384
+ parentIpc.dispose();
385
+ const port = firstMessage.params[1];
386
+ return port;
387
+ }
388
+ return globalThis;
419
389
  };
420
- const listen$2 = ipc => {
421
- set$1(ipc);
390
+ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
391
+ constructor(port) {
392
+ super(port);
393
+ }
394
+ getData(event) {
395
+ return getData$2(event);
396
+ }
397
+ send(message) {
398
+ this._rawIpc.postMessage(message);
399
+ }
400
+ sendAndTransfer(message) {
401
+ const transfer = getTransferrables(message);
402
+ this._rawIpc.postMessage(message, transfer);
403
+ }
404
+ dispose() {
405
+ if (this._rawIpc.close) {
406
+ this._rawIpc.close();
407
+ }
408
+ }
409
+ onClose(callback) {
410
+ // ignore
411
+ }
412
+ onMessage(callback) {
413
+ this._rawIpc.addEventListener('message', callback);
414
+ this._rawIpc.start();
415
+ }
416
+ }
417
+ const wrap$c = port => {
418
+ return new IpcChildWithModuleWorkerAndMessagePort(port);
422
419
  };
423
-
424
- const Rpc = {
420
+ const IpcChildWithModuleWorkerAndMessagePort$1 = {
425
421
  __proto__: null,
426
- invoke,
427
- invokeAndTransfer,
428
- listen: listen$2
422
+ listen: listen$5,
423
+ wrap: wrap$c
429
424
  };
430
425
 
431
- const Fail = 'fail';
432
- const Pass = 'pass';
433
-
434
- const now = () => {
435
- return performance.now();
426
+ const Two = '2.0';
427
+ const create$4 = (method, params) => {
428
+ return {
429
+ jsonrpc: Two,
430
+ method,
431
+ params
432
+ };
436
433
  };
437
-
438
- const normalizeLine$1 = line => {
439
- if (line.startsWith('Error: ')) {
440
- return line.slice(`Error: `.length);
441
- }
442
- if (line.startsWith('VError: ')) {
443
- return line.slice(`VError: `.length);
444
- }
445
- return line;
434
+ const callbacks = Object.create(null);
435
+ const set = (id, fn) => {
436
+ callbacks[id] = fn;
446
437
  };
447
- const getCombinedMessage$1 = (error, message) => {
448
- const stringifiedError = normalizeLine$1(`${error}`);
449
- if (message) {
450
- return `${message}: ${stringifiedError}`;
438
+ const get = id => {
439
+ return callbacks[id];
440
+ };
441
+ const remove = id => {
442
+ delete callbacks[id];
443
+ };
444
+ let id = 0;
445
+ const create$3 = () => {
446
+ return ++id;
447
+ };
448
+ const warn = (...args) => {
449
+ console.warn(...args);
450
+ };
451
+ const registerPromise = () => {
452
+ const id = create$3();
453
+ const {
454
+ resolve,
455
+ promise
456
+ } = Promise.withResolvers();
457
+ set(id, resolve);
458
+ return {
459
+ id,
460
+ promise
461
+ };
462
+ };
463
+ const resolve = (id, response) => {
464
+ const fn = get(id);
465
+ if (!fn) {
466
+ console.log(response);
467
+ warn(`callback ${id} may already be disposed`);
468
+ return;
451
469
  }
452
- return stringifiedError;
470
+ fn(response);
471
+ remove(id);
453
472
  };
454
- const NewLine$2 = '\n';
455
- const getNewLineIndex$1 = (string, startIndex = undefined) => {
456
- return string.indexOf(NewLine$2, startIndex);
473
+ const create$2 = (method, params) => {
474
+ const {
475
+ id,
476
+ promise
477
+ } = registerPromise();
478
+ const message = {
479
+ jsonrpc: Two,
480
+ method,
481
+ params,
482
+ id
483
+ };
484
+ return {
485
+ message,
486
+ promise
487
+ };
457
488
  };
458
- const mergeStacks$1 = (parent, child) => {
459
- if (!child) {
460
- return parent;
489
+ class JsonRpcError extends Error {
490
+ constructor(message) {
491
+ super(message);
492
+ this.name = 'JsonRpcError';
461
493
  }
462
- const parentNewLineIndex = getNewLineIndex$1(parent);
463
- const childNewLineIndex = getNewLineIndex$1(child);
464
- if (childNewLineIndex === -1) {
465
- return parent;
494
+ }
495
+ const NewLine = '\n';
496
+ const DomException = 'DOMException';
497
+ const ReferenceError$1 = 'ReferenceError';
498
+ const SyntaxError$1 = 'SyntaxError';
499
+ const TypeError$1 = 'TypeError';
500
+ const getErrorConstructor = (message, type) => {
501
+ if (type) {
502
+ switch (type) {
503
+ case DomException:
504
+ return DOMException;
505
+ case TypeError$1:
506
+ return TypeError;
507
+ case SyntaxError$1:
508
+ return SyntaxError;
509
+ case ReferenceError$1:
510
+ return ReferenceError;
511
+ default:
512
+ return Error;
513
+ }
466
514
  }
467
- const parentFirstLine = parent.slice(0, parentNewLineIndex);
468
- const childRest = child.slice(childNewLineIndex);
469
- const childFirstLine = normalizeLine$1(child.slice(0, childNewLineIndex));
470
- if (parentFirstLine.includes(childFirstLine)) {
471
- return parentFirstLine + childRest;
515
+ if (message.startsWith('TypeError: ')) {
516
+ return TypeError;
472
517
  }
473
- return child;
474
- };
475
- let VError$1 = class VError extends Error {
476
- constructor(error, message) {
477
- const combinedMessage = getCombinedMessage$1(error, message);
478
- super(combinedMessage);
479
- this.name = 'VError';
480
- if (error instanceof Error) {
481
- this.stack = mergeStacks$1(this.stack, error.stack);
482
- }
483
- if (error.codeFrame) {
484
- // @ts-ignore
485
- this.codeFrame = error.codeFrame;
486
- }
487
- if (error.code) {
488
- // @ts-ignore
489
- this.code = error.code;
490
- }
518
+ if (message.startsWith('SyntaxError: ')) {
519
+ return SyntaxError;
491
520
  }
492
- };
493
-
494
- const printError = error => {
495
- if (error && error.constructor.name === 'AssertionError') {
496
- console.error(error.message);
497
- } else {
498
- console.error(error);
521
+ if (message.startsWith('ReferenceError: ')) {
522
+ return ReferenceError;
499
523
  }
524
+ return Error;
500
525
  };
501
- const stringifyError = error => {
502
- if (!error) {
503
- return `${error}`;
526
+ const constructError = (message, type, name) => {
527
+ const ErrorConstructor = getErrorConstructor(message, type);
528
+ if (ErrorConstructor === DOMException && name) {
529
+ return new ErrorConstructor(message, name);
504
530
  }
505
- if (error && error.message && error.constructor.name && error.constructor.name !== 'Error' && error.constructor.name !== 'VError') {
506
- return `${error}`;
531
+ if (ErrorConstructor === Error) {
532
+ const error = new Error(message);
533
+ if (name && name !== 'VError') {
534
+ error.name = name;
535
+ }
536
+ return error;
507
537
  }
508
- return `${error.message}`;
538
+ return new ErrorConstructor(message);
509
539
  };
510
- const formatDuration = duration => {
511
- return duration.toFixed(2) + 'ms';
540
+ const getNewLineIndex = (string, startIndex = undefined) => {
541
+ return string.indexOf(NewLine, startIndex);
512
542
  };
513
- const executeTest = async (name, fn, globals = {}) => {
514
- let _error;
515
- let _start;
516
- let _end;
517
- let _duration;
518
- let _formattedDuration;
519
- try {
520
- _start = now();
521
- await fn(globals);
522
- _end = now();
523
- _duration = _end - _start;
524
- _formattedDuration = formatDuration(_duration);
525
- console.info(`PASS ${name} in ${_formattedDuration}`);
526
- } catch (error) {
527
- if (error &&
528
- // @ts-ignore
529
- error.message.startsWith('Failed to load command TestFrameWork.')) {
530
- console.error(error);
531
- return;
532
- }
533
- // @ts-ignore
534
- _error = stringifyError(error);
535
- if (!(error instanceof VError$1)) {
536
- error = new VError$1(error, `Test failed: ${name}`);
537
- }
538
- // @ts-ignore
539
- printError(error);
540
- }
541
- let state;
542
- let background;
543
- let text;
544
- if (_error) {
545
- state = Fail;
546
- background = 'red';
547
- text = `test failed: ${_error}`;
548
- } else {
549
- background = 'green';
550
- text = `test passed in ${_formattedDuration}`;
551
- state = Pass;
543
+ const getParentStack = error => {
544
+ let parentStack = error.stack || error.data || error.message || '';
545
+ if (parentStack.startsWith(' at')) {
546
+ parentStack = error.message + NewLine + parentStack;
552
547
  }
553
- await invoke('TestFrameWork.showOverlay', state, background, text);
548
+ return parentStack;
554
549
  };
555
-
556
- const importScript = async url => {
557
- try {
550
+ const joinLines = lines => {
551
+ return lines.join(NewLine);
552
+ };
553
+ const MethodNotFound = -32601;
554
+ const Custom = -32001;
555
+ const splitLines = lines => {
556
+ return lines.split(NewLine);
557
+ };
558
+ const restoreJsonRpcError = error => {
559
+ if (error && error instanceof Error) {
560
+ return error;
561
+ }
562
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
563
+ if (error && error.code && error.code === MethodNotFound) {
564
+ const restoredError = new JsonRpcError(error.message);
565
+ const parentStack = getParentStack(error);
566
+ restoredError.stack = parentStack + NewLine + currentStack;
567
+ return restoredError;
568
+ }
569
+ if (error && error.message) {
570
+ const restoredError = constructError(error.message, error.type, error.name);
571
+ if (error.data) {
572
+ if (error.data.stack && error.data.type && error.message) {
573
+ restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
574
+ } else if (error.data.stack) {
575
+ restoredError.stack = error.data.stack;
576
+ }
577
+ if (error.data.codeFrame) {
578
+ // @ts-ignore
579
+ restoredError.codeFrame = error.data.codeFrame;
580
+ }
581
+ if (error.data.code) {
582
+ // @ts-ignore
583
+ restoredError.code = error.data.code;
584
+ }
585
+ if (error.data.type) {
586
+ // @ts-ignore
587
+ restoredError.name = error.data.type;
588
+ }
589
+ } else {
590
+ if (error.stack) {
591
+ const lowerStack = restoredError.stack || '';
592
+ // @ts-ignore
593
+ const indexNewLine = getNewLineIndex(lowerStack);
594
+ const parentStack = getParentStack(error);
595
+ // @ts-ignore
596
+ restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
597
+ }
598
+ if (error.codeFrame) {
599
+ // @ts-ignore
600
+ restoredError.codeFrame = error.codeFrame;
601
+ }
602
+ }
603
+ return restoredError;
604
+ }
605
+ if (typeof error === 'string') {
606
+ return new Error(`JsonRpc Error: ${error}`);
607
+ }
608
+ return new Error(`JsonRpc Error: ${error}`);
609
+ };
610
+ const unwrapJsonRpcResult = responseMessage => {
611
+ if ('error' in responseMessage) {
612
+ const restoredError = restoreJsonRpcError(responseMessage.error);
613
+ throw restoredError;
614
+ }
615
+ if ('result' in responseMessage) {
616
+ return responseMessage.result;
617
+ }
618
+ throw new JsonRpcError('unexpected response message');
619
+ };
620
+ const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
621
+ const getErrorType = prettyError => {
622
+ if (prettyError && prettyError.type) {
623
+ return prettyError.type;
624
+ }
625
+ if (prettyError && prettyError.constructor && prettyError.constructor.name) {
626
+ return prettyError.constructor.name;
627
+ }
628
+ return undefined;
629
+ };
630
+ const getErrorProperty = (error, prettyError) => {
631
+ if (error && error.code === E_COMMAND_NOT_FOUND) {
632
+ return {
633
+ code: MethodNotFound,
634
+ message: error.message,
635
+ data: error.stack
636
+ };
637
+ }
638
+ return {
639
+ code: Custom,
640
+ message: prettyError.message,
641
+ data: {
642
+ stack: prettyError.stack,
643
+ codeFrame: prettyError.codeFrame,
644
+ type: getErrorType(prettyError),
645
+ code: prettyError.code,
646
+ name: prettyError.name
647
+ }
648
+ };
649
+ };
650
+ const create$1$1 = (message, error) => {
651
+ return {
652
+ jsonrpc: Two,
653
+ id: message.id,
654
+ error
655
+ };
656
+ };
657
+ const getErrorResponse = (message, error, preparePrettyError, logError) => {
658
+ const prettyError = preparePrettyError(error);
659
+ logError(error, prettyError);
660
+ const errorProperty = getErrorProperty(error, prettyError);
661
+ return create$1$1(message, errorProperty);
662
+ };
663
+ const create$5 = (message, result) => {
664
+ return {
665
+ jsonrpc: Two,
666
+ id: message.id,
667
+ result: result ?? null
668
+ };
669
+ };
670
+ const getSuccessResponse = (message, result) => {
671
+ const resultProperty = result ?? null;
672
+ return create$5(message, resultProperty);
673
+ };
674
+ const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
675
+ try {
676
+ const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
677
+ return getSuccessResponse(message, result);
678
+ } catch (error) {
679
+ return getErrorResponse(message, error, preparePrettyError, logError);
680
+ }
681
+ };
682
+ const defaultPreparePrettyError = error => {
683
+ return error;
684
+ };
685
+ const defaultLogError = () => {
686
+ // ignore
687
+ };
688
+ const defaultRequiresSocket = () => {
689
+ return false;
690
+ };
691
+ const defaultResolve = resolve;
692
+
693
+ // TODO maybe remove this in v6 or v7, only accept options object to simplify the code
694
+ const normalizeParams = args => {
695
+ if (args.length === 1) {
696
+ const options = args[0];
697
+ return {
698
+ ipc: options.ipc,
699
+ message: options.message,
700
+ execute: options.execute,
701
+ resolve: options.resolve || defaultResolve,
702
+ preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
703
+ logError: options.logError || defaultLogError,
704
+ requiresSocket: options.requiresSocket || defaultRequiresSocket
705
+ };
706
+ }
707
+ return {
708
+ ipc: args[0],
709
+ message: args[1],
710
+ execute: args[2],
711
+ resolve: args[3],
712
+ preparePrettyError: args[4],
713
+ logError: args[5],
714
+ requiresSocket: args[6]
715
+ };
716
+ };
717
+ const handleJsonRpcMessage = async (...args) => {
718
+ const options = normalizeParams(args);
719
+ const {
720
+ message,
721
+ ipc,
722
+ execute,
723
+ resolve,
724
+ preparePrettyError,
725
+ logError,
726
+ requiresSocket
727
+ } = options;
728
+ if ('id' in message) {
729
+ if ('method' in message) {
730
+ const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
731
+ try {
732
+ ipc.send(response);
733
+ } catch (error) {
734
+ const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
735
+ ipc.send(errorResponse);
736
+ }
737
+ return;
738
+ }
739
+ resolve(message.id, message);
740
+ return;
741
+ }
742
+ if ('method' in message) {
743
+ await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
744
+ return;
745
+ }
746
+ throw new JsonRpcError('unexpected message');
747
+ };
748
+ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
749
+ const {
750
+ message,
751
+ promise
752
+ } = create$2(method, params);
753
+ if (useSendAndTransfer && ipc.sendAndTransfer) {
754
+ ipc.sendAndTransfer(message);
755
+ } else {
756
+ ipc.send(message);
757
+ }
758
+ const responseMessage = await promise;
759
+ return unwrapJsonRpcResult(responseMessage);
760
+ };
761
+ const send = (transport, method, ...params) => {
762
+ const message = create$4(method, params);
763
+ transport.send(message);
764
+ };
765
+ const invoke$1 = (ipc, method, ...params) => {
766
+ return invokeHelper(ipc, method, params, false);
767
+ };
768
+ const invokeAndTransfer$1 = (ipc, method, ...params) => {
769
+ return invokeHelper(ipc, method, params, true);
770
+ };
771
+
772
+ const commands = Object.create(null);
773
+ const register = commandMap => {
774
+ Object.assign(commands, commandMap);
775
+ };
776
+ const getCommand = key => {
777
+ return commands[key];
778
+ };
779
+ const execute$3 = (command, ...args) => {
780
+ const fn = getCommand(command);
781
+ if (!fn) {
782
+ throw new Error(`command not found ${command}`);
783
+ }
784
+ return fn(...args);
785
+ };
786
+
787
+ const createRpc = ipc => {
788
+ const rpc = {
789
+ /**
790
+ * @deprecated
791
+ */
792
+ send(method, ...params) {
793
+ send(ipc, method, ...params);
794
+ },
795
+ invoke(method, ...params) {
796
+ return invoke$1(ipc, method, ...params);
797
+ },
798
+ invokeAndTransfer(method, ...params) {
799
+ return invokeAndTransfer$1(ipc, method, ...params);
800
+ }
801
+ };
802
+ return rpc;
803
+ };
804
+ const requiresSocket$1 = () => {
805
+ return false;
806
+ };
807
+ const preparePrettyError$1 = error => {
808
+ return error;
809
+ };
810
+ const logError$1 = () => {
811
+ // handled by renderer worker
812
+ };
813
+ const handleMessage = event => {
814
+ const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket$1;
815
+ return handleJsonRpcMessage(event.target, event.data, execute$3, resolve, preparePrettyError$1, logError$1, actualRequiresSocket);
816
+ };
817
+ const handleIpc = ipc => {
818
+ if ('addEventListener' in ipc) {
819
+ ipc.addEventListener('message', handleMessage);
820
+ } else if ('on' in ipc) {
821
+ // deprecated
822
+ ipc.on('message', handleMessage);
823
+ }
824
+ };
825
+ const listen$2 = async (module, options) => {
826
+ const rawIpc = await module.listen(options);
827
+ if (module.signal) {
828
+ module.signal(rawIpc);
829
+ }
830
+ const ipc = module.wrap(rawIpc);
831
+ return ipc;
832
+ };
833
+ const create$1 = async ({
834
+ commandMap
835
+ }) => {
836
+ // TODO create a commandMap per rpc instance
837
+ register(commandMap);
838
+ const ipc = await listen$2(IpcChildWithModuleWorkerAndMessagePort$1);
839
+ handleIpc(ipc);
840
+ const rpc = createRpc(ipc);
841
+ return rpc;
842
+ };
843
+ const WebWorkerRpcClient = {
844
+ __proto__: null,
845
+ create: create$1
846
+ };
847
+
848
+ const state$1 = {
849
+ rpc: undefined
850
+ };
851
+ const invoke = (method, ...params) => {
852
+ const rpc = state$1.rpc;
853
+ // @ts-ignore
854
+ return rpc.invoke(method, ...params);
855
+ };
856
+ const invokeAndTransfer = (method, ...params) => {
857
+ const rpc = state$1.rpc;
858
+ // @ts-ignore
859
+ return rpc.invokeAndTransfer(method, ...params);
860
+ };
861
+ const listen$1 = ipc => {
862
+ };
863
+ const setRpc = rpc => {
864
+ state$1.rpc = rpc;
865
+ };
866
+
867
+ const Rpc = {
868
+ __proto__: null,
869
+ invoke,
870
+ invokeAndTransfer,
871
+ listen: listen$1,
872
+ setRpc
873
+ };
874
+
875
+ const Fail = 'fail';
876
+ const Pass = 'pass';
877
+
878
+ const now = () => {
879
+ return performance.now();
880
+ };
881
+
882
+ const printError = error => {
883
+ if (error && error.constructor.name === 'AssertionError') {
884
+ console.error(error.message);
885
+ } else {
886
+ console.error(error);
887
+ }
888
+ };
889
+ const stringifyError = error => {
890
+ if (!error) {
891
+ return `${error}`;
892
+ }
893
+ if (error && error.message && error.constructor.name && error.constructor.name !== 'Error' && error.constructor.name !== 'VError') {
894
+ return `${error}`;
895
+ }
896
+ return `${error.message}`;
897
+ };
898
+ const formatDuration = duration => {
899
+ return duration.toFixed(2) + 'ms';
900
+ };
901
+ const executeTest = async (name, fn, globals = {}) => {
902
+ let _error;
903
+ let _start;
904
+ let _end;
905
+ let _duration;
906
+ let _formattedDuration;
907
+ try {
908
+ _start = now();
909
+ await fn(globals);
910
+ _end = now();
911
+ _duration = _end - _start;
912
+ _formattedDuration = formatDuration(_duration);
913
+ console.info(`PASS ${name} in ${_formattedDuration}`);
914
+ } catch (error) {
915
+ if (error &&
916
+ // @ts-ignore
917
+ error.message.startsWith('Failed to load command TestFrameWork.')) {
918
+ console.error(error);
919
+ return;
920
+ }
921
+ // @ts-ignore
922
+ _error = stringifyError(error);
923
+ if (!(error instanceof VError)) {
924
+ error = new VError(error, `Test failed: ${name}`);
925
+ }
926
+ // @ts-ignore
927
+ printError(error);
928
+ }
929
+ let state;
930
+ let background;
931
+ let text;
932
+ if (_error) {
933
+ state = Fail;
934
+ background = 'red';
935
+ text = `test failed: ${_error}`;
936
+ } else {
937
+ background = 'green';
938
+ text = `test passed in ${_formattedDuration}`;
939
+ state = Pass;
940
+ }
941
+ await invoke('TestFrameWork.showOverlay', state, background, text);
942
+ };
943
+
944
+ const importScript = async url => {
945
+ try {
558
946
  return await import(url);
559
947
  } catch (error) {
560
948
  throw error;
@@ -568,7 +956,7 @@ const importTest = async url => {
568
956
  try {
569
957
  return await importScript(url);
570
958
  } catch (error) {
571
- throw new VError$1(error, 'Failed to import test');
959
+ throw new VError(error, 'Failed to import test');
572
960
  }
573
961
  };
574
962
 
@@ -668,47 +1056,6 @@ const nameAnonymousFunction = (fn, name) => {
668
1056
  });
669
1057
  };
670
1058
 
671
- class AssertionError extends Error {
672
- constructor(message) {
673
- super(message);
674
- this.name = 'AssertionError';
675
- }
676
- }
677
- const getType = value => {
678
- switch (typeof value) {
679
- case 'number':
680
- return 'number';
681
- case 'function':
682
- return 'function';
683
- case 'string':
684
- return 'string';
685
- case 'object':
686
- if (value === null) {
687
- return 'null';
688
- }
689
- if (Array.isArray(value)) {
690
- return 'array';
691
- }
692
- return 'object';
693
- case 'boolean':
694
- return 'boolean';
695
- default:
696
- return 'unknown';
697
- }
698
- };
699
- const object = value => {
700
- const type = getType(value);
701
- if (type !== 'object') {
702
- throw new AssertionError('expected value to be of type object');
703
- }
704
- };
705
- const string = value => {
706
- const type = getType(value);
707
- if (type !== 'string') {
708
- throw new AssertionError('expected value to be of type string');
709
- }
710
- };
711
-
712
1059
  // @ts-nocheck
713
1060
 
714
1061
  const state = {
@@ -737,7 +1084,7 @@ const setMockRpc = mockRpc => {
737
1084
 
738
1085
  // @ts-nocheck
739
1086
 
740
- const create = (selector, options) => {
1087
+ const create = (selector, options = {}) => {
741
1088
  return new Locator(selector, options);
742
1089
  };
743
1090
  const Locator = function (selector, {
@@ -748,11 +1095,11 @@ const Locator = function (selector, {
748
1095
  this._nth = nth;
749
1096
  this._hasText = hasText;
750
1097
  };
751
- const performAction = async (locator, fnName, options) => {
1098
+ const performAction = async (locator, action, options) => {
752
1099
  const {
753
1100
  invoke
754
1101
  } = locator.webView || Rpc;
755
- return invoke('TestFrameWork.performAction', locator, fnName, options);
1102
+ return invoke('TestFrameWork.performAction', locator, action, options);
756
1103
  };
757
1104
  const toButtonNumber = buttonType => {
758
1105
  switch (buttonType) {
@@ -820,7 +1167,7 @@ const test = async (name, fn) => {
820
1167
  nameAnonymousFunction(fn, `test/${name}`);
821
1168
  addTest(name, fn);
822
1169
  };
823
- test.skip = async (id, fn) => {
1170
+ test.skip = async id => {
824
1171
  const state = 'skip';
825
1172
  const background = 'yellow';
826
1173
  const text = `test skipped ${id}`;
@@ -836,19 +1183,40 @@ const TestFrameWork = {
836
1183
  test
837
1184
  };
838
1185
 
1186
+ const show$1 = async () => {
1187
+ return invoke('About.showAbout');
1188
+ };
1189
+ const handleClickOk = async () => {
1190
+ return invoke('About.handleClickOk');
1191
+ };
1192
+ const handleClickClose = async () => {
1193
+ return invoke('About.handleClickClose');
1194
+ };
1195
+ const handleClickCopy = async () => {
1196
+ return invoke('About.handleClickCopy');
1197
+ };
1198
+
1199
+ const TestFrameWorkComponentAbout = {
1200
+ __proto__: null,
1201
+ handleClickClose,
1202
+ handleClickCopy,
1203
+ handleClickOk,
1204
+ show: show$1
1205
+ };
1206
+
839
1207
  const focus$2 = async () => {
840
1208
  await invoke('ActivityBar.focus');
841
1209
  };
842
- const focusFirst$2 = async () => {
1210
+ const focusFirst$3 = async () => {
843
1211
  await invoke('ActivityBar.focusFirst');
844
1212
  };
845
1213
  const focusLast$2 = async () => {
846
1214
  await invoke('ActivityBar.focusLast');
847
1215
  };
848
- const focusNext$4 = async () => {
1216
+ const focusNext$5 = async () => {
849
1217
  await invoke('ActivityBar.focusNext');
850
1218
  };
851
- const focusPrevious$2 = async () => {
1219
+ const focusPrevious$3 = async () => {
852
1220
  await invoke('ActivityBar.focusPrevious');
853
1221
  };
854
1222
  const handleClick$1 = async index => {
@@ -864,10 +1232,10 @@ const selectCurrent = async () => {
864
1232
  const TestFrameworkComponentActivityBar = {
865
1233
  __proto__: null,
866
1234
  focus: focus$2,
867
- focusFirst: focusFirst$2,
1235
+ focusFirst: focusFirst$3,
868
1236
  focusLast: focusLast$2,
869
- focusNext: focusNext$4,
870
- focusPrevious: focusPrevious$2,
1237
+ focusNext: focusNext$5,
1238
+ focusPrevious: focusPrevious$3,
871
1239
  handleClick: handleClick$1,
872
1240
  handleContextMenu,
873
1241
  selectCurrent
@@ -984,7 +1352,7 @@ const goToTypeDefinition = async () => {
984
1352
  await invoke('Editor.goToTypeDefinition');
985
1353
  };
986
1354
  const type = async text => {
987
- await invoke('Editor.type');
1355
+ await invoke('Editor.type', text);
988
1356
  };
989
1357
  const findAllReferences = async () => {
990
1358
  await invoke('SideBar.show', 'References', /* focus */true);
@@ -1150,10 +1518,10 @@ const openContextMenu = async index => {
1150
1518
  const focus$1 = async () => {
1151
1519
  await invoke('Explorer.focusIndex', -1);
1152
1520
  };
1153
- const focusNext$3 = async () => {
1521
+ const focusNext$4 = async () => {
1154
1522
  await invoke('Explorer.focusNext');
1155
1523
  };
1156
- const focusIndex$2 = async index => {
1524
+ const focusIndex$3 = async index => {
1157
1525
  await invoke('Explorer.focusIndex', index);
1158
1526
  };
1159
1527
  const clickCurrent = async () => {
@@ -1165,7 +1533,7 @@ const handleArrowLeft = async () => {
1165
1533
  const focusLast$1 = async () => {
1166
1534
  await invoke('Explorer.focusLast');
1167
1535
  };
1168
- const focusFirst$1 = async () => {
1536
+ const focusFirst$2 = async () => {
1169
1537
  await invoke('Explorer.focusFirst');
1170
1538
  };
1171
1539
  const removeDirent = async () => {
@@ -1204,10 +1572,10 @@ const TestFrameWorkComponentExplorer = {
1204
1572
  expandAll,
1205
1573
  expandRecursively,
1206
1574
  focus: focus$1,
1207
- focusFirst: focusFirst$1,
1208
- focusIndex: focusIndex$2,
1575
+ focusFirst: focusFirst$2,
1576
+ focusIndex: focusIndex$3,
1209
1577
  focusLast: focusLast$1,
1210
- focusNext: focusNext$3,
1578
+ focusNext: focusNext$4,
1211
1579
  handleArrowLeft,
1212
1580
  handleClick,
1213
1581
  newFile,
@@ -1287,7 +1655,7 @@ const TestFrameWorkComponentFileSystem = {
1287
1655
  writeFile
1288
1656
  };
1289
1657
 
1290
- const focusNext$2 = async () => {
1658
+ const focusNext$3 = async () => {
1291
1659
  await invoke('FindWidget.focusNext');
1292
1660
  };
1293
1661
  const setValue$2 = async value => {
@@ -1296,7 +1664,7 @@ const setValue$2 = async value => {
1296
1664
 
1297
1665
  const TestFrameWorkComponentFindWidget = {
1298
1666
  __proto__: null,
1299
- focusNext: focusNext$2,
1667
+ focusNext: focusNext$3,
1300
1668
  setValue: setValue$2
1301
1669
  };
1302
1670
 
@@ -1349,853 +1717,456 @@ const press = async key => {
1349
1717
  const options = {
1350
1718
  cancelable: true,
1351
1719
  bubbles: true,
1352
- ...keyOptions
1353
- };
1354
- await invoke('TestFrameWork.performKeyBoardAction', 'press', options);
1355
- };
1356
-
1357
- const TestFrameWorkComponentKeyBoard = {
1358
- __proto__: null,
1359
- press
1360
- };
1361
-
1362
- const openUri = async uri => {
1363
- await invoke('Main.openUri', uri);
1364
- };
1365
- const splitRight = async () => {
1366
- await invoke('Main.splitRight');
1367
- };
1368
-
1369
- const TestFrameWorkComponentMain = {
1370
- __proto__: null,
1371
- openUri,
1372
- splitRight
1373
- };
1374
-
1375
- const open$2 = async id => {
1376
- await invoke('Layout.showPanel', id);
1377
- };
1378
-
1379
- const TestFrameWorkComponentPanel = {
1380
- __proto__: null,
1381
- open: open$2
1382
- };
1383
-
1384
- const getIsFirefox = () => {
1385
- if (typeof navigator === 'undefined') {
1386
- return false;
1387
- }
1388
- if (
1389
- // @ts-expect-error
1390
- navigator.userAgentData?.brands) {
1391
- // @ts-expect-error
1392
- return navigator.userAgentData.brands.includes('Firefox');
1393
- }
1394
- return navigator.userAgent.toLowerCase().includes('firefox');
1395
- };
1396
-
1397
- /**
1398
- * @type {boolean}
1399
- */
1400
- const isFirefox$1 = getIsFirefox();
1401
-
1402
- const getNodePath$1 = () => {
1403
- return invoke(/* Platform.getNodePath */'Platform.getNodePath');
1404
- };
1405
-
1406
- const getNodePath = () => {
1407
- return getNodePath$1();
1408
- };
1409
- const isFirefox = () => {
1410
- return isFirefox$1;
1411
- };
1412
-
1413
- const TestFrameWorkComponentPlatform = {
1414
- __proto__: null,
1415
- getNodePath,
1416
- isFirefox
1417
- };
1418
-
1419
- const show = async () => {
1420
- await invoke('Panel.selectIndex', 0);
1421
- };
1422
-
1423
- const TestFrameWorkComponentProblems = {
1424
- __proto__: null,
1425
- show
1426
- };
1427
-
1428
- const QuickPick = 'QuickPick';
1429
-
1430
- const open$1 = async () => {
1431
- await invoke('Viewlet.openWidget', QuickPick, 'everything');
1432
- };
1433
- const setValue$1 = async value => {
1434
- await invoke('QuickPick.handleInput', value, 0);
1435
- };
1436
- const focusNext$1 = async () => {
1437
- await invoke('QuickPick.focusNext');
1438
- };
1439
- const focusIndex$1 = async index => {
1440
- await invoke('QuickPick.focusIndex', index);
1441
- };
1442
- const focusPrevious$1 = async () => {
1443
- await invoke('QuickPick.focusPrevious');
1444
- };
1445
- const selectItem = async label => {
1446
- await invoke('QuickPick.selectItem', label);
1447
- };
1448
- const executeCommand = async label => {
1449
- await invoke('QuickPick.showCommands');
1450
- await invoke('QuickPick.handleInput', label, 0);
1451
- await invoke('QuickPick.selectItem', label);
1452
- };
1453
-
1454
- const TestFrameWorkComponentQuickPick = {
1455
- __proto__: null,
1456
- executeCommand,
1457
- focusIndex: focusIndex$1,
1458
- focusNext: focusNext$1,
1459
- focusPrevious: focusPrevious$1,
1460
- open: open$1,
1461
- selectItem,
1462
- setValue: setValue$1
1463
- };
1464
-
1465
- const setValue = async value => {
1466
- await invoke('Search.handleInput', value);
1467
- };
1468
-
1469
- const TestFrameWorkComponentSearch = {
1470
- __proto__: null,
1471
- setValue
1472
- };
1473
-
1474
- const update$1 = settings => {
1475
- return invoke('Preferences.update', settings);
1476
- };
1477
-
1478
- const TestFrameWorkComponentSettings = {
1479
- __proto__: null,
1480
- update: update$1
1481
- };
1482
-
1483
- const open = async id => {
1484
- await invoke('SideBar.openViewlet', id);
1485
- };
1486
- const hide = async () => {
1487
- await invoke('Layout.hideSideBar');
1488
- };
1489
-
1490
- const TestFrameWorkComponentSideBar = {
1491
- __proto__: null,
1492
- hide,
1493
- open
1494
- };
1495
-
1496
- const acceptInput = async () => {
1497
- await invoke('Source Control.acceptInput');
1498
- };
1499
- const handleInput = async text => {
1500
- await invoke('Source Control.handleInput', text);
1501
- };
1502
-
1503
- const TestFrameWorkComponentSourceControl = {
1504
- __proto__: null,
1505
- acceptInput,
1506
- handleInput
1507
- };
1508
-
1509
- const update = async () => {
1510
- await invoke('StatusBar.updateStatusBarItems');
1511
- };
1512
-
1513
- const TestFrameWorkComponentStatusBar = {
1514
- __proto__: null,
1515
- update
1516
- };
1517
-
1518
- const closeMenu = async () => {
1519
- await invoke('TitleBarMenuBar.closeMenu');
1520
- };
1521
- const focus = async () => {
1522
- await invoke('TitleBarMenuBar.focus');
1523
- };
1524
- const focusFirst = async () => {
1525
- await invoke('TitleBarMenuBar.focusFirst');
1526
- };
1527
- const focusIndex = async index => {
1528
- await invoke('TitleBarMenuBar.focusIndex', index);
1529
- };
1530
- const focusLast = async () => {
1531
- await invoke('TitleBarMenuBar.focusLast');
1532
- };
1533
- const focusNext = async () => {
1534
- await invoke('TitleBarMenuBar.focusNext');
1535
- };
1536
- const focusPrevious = async () => {
1537
- await invoke('TitleBarMenuBar.focusPrevious');
1538
- };
1539
- const handleKeyArrowDown = async () => {
1540
- await invoke('TitleBarMenuBar.handleKeyArrowDown');
1541
- };
1542
- const handleKeyArrowLeft = async () => {
1543
- await invoke('TitleBarMenuBar.handleKeyArrowLeft');
1544
- };
1545
- const handleKeyArrowRight = async () => {
1546
- await invoke('TitleBarMenuBar.handleKeyArrowRight');
1547
- };
1548
- const handleKeyArrowUp = async () => {
1549
- await invoke('TitleBarMenuBar.handleKeyArrowUp');
1550
- };
1551
- const handleKeyEnd = async () => {
1552
- await invoke('TitleBarMenuBar.handleKeyEnd');
1553
- };
1554
- const handleKeyHome = async () => {
1555
- await invoke('TitleBarMenuBar.handleKeyHome');
1556
- };
1557
- const handleKeySpace = async () => {
1558
- await invoke('TitleBarMenuBar.handleKeySpace');
1559
- };
1560
- const handleKeyEscape = async () => {
1561
- await invoke('TitleBarMenuBar.handleKeyEscape');
1562
- };
1563
- const toggleIndex = async index => {
1564
- await invoke('TitleBarMenuBar.toggleIndex', index);
1565
- };
1566
- const toggleMenu = async () => {
1567
- await invoke('TitleBarMenuBar.toggleMenu');
1568
- };
1569
-
1570
- const TestFrameWorkComponentTitleBarMenuBar = {
1571
- __proto__: null,
1572
- closeMenu,
1573
- focus,
1574
- focusFirst,
1575
- focusIndex,
1576
- focusLast,
1577
- focusNext,
1578
- focusPrevious,
1579
- handleKeyArrowDown,
1580
- handleKeyArrowLeft,
1581
- handleKeyArrowRight,
1582
- handleKeyArrowUp,
1583
- handleKeyEnd,
1584
- handleKeyEscape,
1585
- handleKeyHome,
1586
- handleKeySpace,
1587
- toggleIndex,
1588
- toggleMenu
1589
- };
1590
-
1591
- const getPortTuple = () => {
1592
- const {
1593
- port1,
1594
- port2
1595
- } = new MessageChannel();
1596
- return {
1597
- port1,
1598
- port2
1720
+ ...keyOptions
1599
1721
  };
1722
+ await invoke('TestFrameWork.performKeyBoardAction', 'press', options);
1600
1723
  };
1601
1724
 
1602
- const sendPortToWebView = async (webviewId, port) => {
1603
- await invokeAndTransfer('Transferrable.transferToRendererProcess', webviewId, port);
1604
- console.log('did send port to renderer process');
1605
- // TODO ask renderer process to transfer the port to the webview
1725
+ const TestFrameWorkComponentKeyBoard = {
1726
+ __proto__: null,
1727
+ press
1606
1728
  };
1607
1729
 
1608
- const preparePrettyError$1 = error => {
1609
- return error;
1610
- };
1611
- const logError$1 = () => {
1612
- // ignore
1730
+ const openUri = async uri => {
1731
+ await invoke('Main.openUri', uri);
1613
1732
  };
1614
- const execute$1 = () => {};
1615
- const requiresSocket$1 = () => {
1616
- return false;
1733
+ const splitRight = async () => {
1734
+ await invoke('Main.splitRight');
1617
1735
  };
1618
- const createPortIpc = async webViewId => {
1619
- const {
1620
- port1,
1621
- port2
1622
- } = getPortTuple();
1623
- const firstEventPromise = new Promise(resolve => {
1624
- port1.onmessage = resolve;
1625
- });
1626
- await sendPortToWebView(webViewId, port2);
1627
- const firstEvent = await firstEventPromise;
1628
- // @ts-ignore
1629
- if (firstEvent.data !== 'ready') {
1630
- throw new Error('unexpected first message');
1631
- }
1632
- const handleOtherMessage = async event => {
1633
- // @ts-ignore
1634
- await handleJsonRpcMessage(ipc, event.data, resolve, preparePrettyError$1, execute$1, logError$1, requiresSocket$1);
1635
- };
1636
- port1.onmessage = handleOtherMessage;
1637
- const ipc = {
1638
- send(message) {
1639
- port1.postMessage(message);
1640
- }
1641
- };
1642
- return ipc;
1736
+
1737
+ const TestFrameWorkComponentMain = {
1738
+ __proto__: null,
1739
+ openUri,
1740
+ splitRight
1643
1741
  };
1644
1742
 
1645
- const fromId = async webViewId => {
1646
- const ipc = await createPortIpc(webViewId);
1647
- // TODO
1648
- // 1. create messagechannel
1649
- // 2. send one message port to webview
1650
- // 3. setup rpc connection and wait for webview to be ready
1651
- // 4. send test commands like locator.toBeVisible to webview
1652
- const webViewRpc = {
1653
- invoke(method, ...params) {
1654
- return invoke$1(ipc, method, ...params);
1655
- }
1656
- };
1657
- return {
1658
- locator(selector, options) {
1659
- const baseLocator = create(selector, options);
1660
- baseLocator.webView = webViewRpc;
1661
- return baseLocator;
1662
- },
1663
- expect: expect$1
1664
- };
1743
+ const open$2 = async id => {
1744
+ await invoke('Layout.showPanel', id);
1665
1745
  };
1666
1746
 
1667
- const TestFrameWorkComponentWebView = {
1747
+ const TestFrameWorkComponentPanel = {
1668
1748
  __proto__: null,
1669
- fromId
1749
+ open: open$2
1670
1750
  };
1671
1751
 
1672
- const setPath = async path => {
1673
- await invoke('Workspace.setPath', path);
1752
+ const getIsFirefox = () => {
1753
+ if (typeof navigator === 'undefined') {
1754
+ return false;
1755
+ }
1756
+ if (
1757
+ // @ts-expect-error
1758
+ navigator.userAgentData?.brands) {
1759
+ // @ts-expect-error
1760
+ return navigator.userAgentData.brands.includes('Firefox');
1761
+ }
1762
+ return navigator.userAgent.toLowerCase().includes('firefox');
1674
1763
  };
1675
1764
 
1676
- const TestFrameWorkComponentWorkspace = {
1765
+ /**
1766
+ * @type {boolean}
1767
+ */
1768
+ const isFirefox$1 = getIsFirefox();
1769
+
1770
+ const getNodePath$1 = () => {
1771
+ return invoke(/* Platform.getNodePath */'Platform.getNodePath');
1772
+ };
1773
+
1774
+ const getNodePath = () => {
1775
+ return getNodePath$1();
1776
+ };
1777
+ const isFirefox = () => {
1778
+ return isFirefox$1;
1779
+ };
1780
+
1781
+ const TestFrameWorkComponentPlatform = {
1677
1782
  __proto__: null,
1678
- setPath
1783
+ getNodePath,
1784
+ isFirefox
1679
1785
  };
1680
1786
 
1681
- const TestFrameWorkComponent = {
1787
+ const show = async () => {
1788
+ await invoke('Panel.selectIndex', 0);
1789
+ };
1790
+
1791
+ const TestFrameWorkComponentProblems = {
1682
1792
  __proto__: null,
1683
- ActivityBar: TestFrameworkComponentActivityBar,
1684
- BaseUrl: TestFrameWorkComponentBaseUrl,
1685
- Command: TestFrameWorkComponentCommand,
1686
- ContextMenu: TestFrameWorkComponentContextMenu,
1687
- Editor: TestFrameWorkComponentEditor,
1688
- Explorer: TestFrameWorkComponentExplorer,
1689
- Extension: TestFrameWorkComponentExtension,
1690
- FileSystem: TestFrameWorkComponentFileSystem,
1691
- FindWidget: TestFrameWorkComponentFindWidget,
1692
- IconTheme: TestFrameWorkComponentIconTheme,
1693
- KeyBoard: TestFrameWorkComponentKeyBoard,
1694
- Main: TestFrameWorkComponentMain,
1695
- Panel: TestFrameWorkComponentPanel,
1696
- Platform: TestFrameWorkComponentPlatform,
1697
- Problems: TestFrameWorkComponentProblems,
1698
- QuickPick: TestFrameWorkComponentQuickPick,
1699
- Search: TestFrameWorkComponentSearch,
1700
- Settings: TestFrameWorkComponentSettings,
1701
- SideBar: TestFrameWorkComponentSideBar,
1702
- SourceControl: TestFrameWorkComponentSourceControl,
1703
- StatusBar: TestFrameWorkComponentStatusBar,
1704
- TitleBarMenuBar: TestFrameWorkComponentTitleBarMenuBar,
1705
- WebView: TestFrameWorkComponentWebView,
1706
- Workspace: TestFrameWorkComponentWorkspace
1793
+ show
1707
1794
  };
1708
1795
 
1709
- const execute = async href => {
1710
- const globals = {
1711
- ...TestFrameWorkComponent,
1712
- ...TestFrameWork
1713
- };
1714
- // TODO
1715
- // 0. wait for page to be ready
1716
- // 1. get script to import from renderer process (url or from html)
1717
- const scriptUrl = href;
1718
- // 2. import that script
1719
- const module = await importTest(scriptUrl);
1720
- if (module.mockRpc) {
1721
- setMockRpc(module.mockRpc);
1722
- }
1723
- if (module.test) {
1724
- if (module.skip) {
1725
- await test.skip(module.name, () => {});
1726
- } else {
1727
- await executeTest(module.name, module.test, globals);
1728
- }
1729
- } else {
1730
- const tests = getTests();
1731
- for (const test of tests) {
1732
- // @ts-ignore
1733
- await executeTest(test.name, test.fn);
1734
- }
1735
- }
1736
- // 3. if import fails, display error message
1796
+ const QuickPick = 'QuickPick';
1737
1797
 
1738
- // 4. run the test
1739
- // 5. if test fails, display error message
1740
- // 6. if test succeeds, display success message
1798
+ const open$1 = async () => {
1799
+ await invoke('Viewlet.openWidget', QuickPick, 'everything');
1800
+ };
1801
+ const setValue$1 = async value => {
1802
+ await invoke('QuickPick.handleInput', value, 0);
1803
+ };
1804
+ const focusNext$2 = async () => {
1805
+ await invoke('QuickPick.focusNext');
1806
+ };
1807
+ const focusIndex$2 = async index => {
1808
+ await invoke('QuickPick.focusIndex', index);
1809
+ };
1810
+ const focusPrevious$2 = async () => {
1811
+ await invoke('QuickPick.focusPrevious');
1812
+ };
1813
+ const selectItem = async label => {
1814
+ await invoke('QuickPick.selectItem', label);
1815
+ };
1816
+ const executeCommand = async label => {
1817
+ await invoke('QuickPick.showCommands');
1818
+ await invoke('QuickPick.handleInput', label, 0);
1819
+ await invoke('QuickPick.selectItem', label);
1741
1820
  };
1742
1821
 
1743
- const commandMap = {
1744
- 'Test.execute': execute
1822
+ const TestFrameWorkComponentQuickPick = {
1823
+ __proto__: null,
1824
+ executeCommand,
1825
+ focusIndex: focusIndex$2,
1826
+ focusNext: focusNext$2,
1827
+ focusPrevious: focusPrevious$2,
1828
+ open: open$1,
1829
+ selectItem,
1830
+ setValue: setValue$1
1745
1831
  };
1746
1832
 
1747
- const requiresSocket = () => {
1748
- return false;
1833
+ const setValue = async value => {
1834
+ await invoke('Search.handleInput', value);
1749
1835
  };
1750
- const preparePrettyError = error => {
1751
- return error;
1836
+ const clearSearchResults = async () => {
1837
+ await invoke('Search.clearSearchResults');
1752
1838
  };
1753
- const logError = error => {
1754
- console.error(error);
1839
+ const dismissItem = async () => {
1840
+ await invoke('Search.dismissItem');
1755
1841
  };
1756
- const handleMessage = event => {
1757
- return handleJsonRpcMessage(event.target, event.data, execute$3, resolve, preparePrettyError, logError, requiresSocket);
1842
+ const focusFirst$1 = async () => {
1843
+ await invoke('Search.focusFirst');
1758
1844
  };
1759
-
1760
- const handleIpc = ipc => {
1761
- ipc.addEventListener('message', handleMessage);
1845
+ const focusIndex$1 = async index => {
1846
+ await invoke('Search.focusIndex', index);
1847
+ };
1848
+ const focusNext$1 = async () => {
1849
+ await invoke('Search.focusNext');
1850
+ };
1851
+ const focusNextPage = async () => {
1852
+ await invoke('Search.focusPage');
1853
+ };
1854
+ const focusPreviousPage = async () => {
1855
+ await invoke('Search.focusPreviousPage');
1856
+ };
1857
+ const focusPrevious$1 = async () => {
1858
+ await invoke('Search.focusPrevious');
1859
+ };
1860
+ const toggleMatchCase = async () => {
1861
+ await invoke('Search.toggleMatchCase');
1862
+ };
1863
+ const toggleMatchWholeWord = async () => {
1864
+ await invoke('Search.toggleMatchWholeWord');
1865
+ };
1866
+ const togglePreserveCase = async () => {
1867
+ await invoke('Search.togglePreserveCase');
1868
+ };
1869
+ const toggleUseRegularExpression = async () => {
1870
+ await invoke('Search.toggleUseRegularExpression');
1762
1871
  };
1763
1872
 
1764
- const MessagePort$1 = 1;
1765
- const ModuleWorker = 2;
1766
- const ReferencePort = 3;
1767
- const ModuleWorkerAndMessagePort = 8;
1768
- const Auto = () => {
1769
- // @ts-ignore
1770
- if (globalThis.acceptPort) {
1771
- return MessagePort$1;
1772
- }
1773
- // @ts-ignore
1774
- if (globalThis.acceptReferencePort) {
1775
- return ReferencePort;
1776
- }
1777
- return ModuleWorkerAndMessagePort;
1873
+ const TestFrameWorkComponentSearch = {
1874
+ __proto__: null,
1875
+ clearSearchResults,
1876
+ dismissItem,
1877
+ focusFirst: focusFirst$1,
1878
+ focusIndex: focusIndex$1,
1879
+ focusNext: focusNext$1,
1880
+ focusNextPage,
1881
+ focusPrevious: focusPrevious$1,
1882
+ focusPreviousPage,
1883
+ setValue,
1884
+ toggleMatchCase,
1885
+ toggleMatchWholeWord,
1886
+ togglePreserveCase,
1887
+ toggleUseRegularExpression
1778
1888
  };
1779
1889
 
1780
- const getData$1 = event => {
1781
- return event.data;
1890
+ const update$1 = settings => {
1891
+ return invoke('Preferences.update', settings);
1782
1892
  };
1783
- const walkValue = (value, transferrables, isTransferrable) => {
1784
- if (!value) {
1785
- return;
1786
- }
1787
- if (isTransferrable(value)) {
1788
- transferrables.push(value);
1789
- return;
1790
- }
1791
- if (Array.isArray(value)) {
1792
- for (const item of value) {
1793
- walkValue(item, transferrables, isTransferrable);
1794
- }
1795
- return;
1796
- }
1797
- if (typeof value === 'object') {
1798
- for (const property of Object.values(value)) {
1799
- walkValue(property, transferrables, isTransferrable);
1800
- }
1801
- return;
1802
- }
1893
+
1894
+ const TestFrameWorkComponentSettings = {
1895
+ __proto__: null,
1896
+ update: update$1
1803
1897
  };
1804
- const isMessagePort = value => {
1805
- return value && value instanceof MessagePort;
1898
+
1899
+ const open = async id => {
1900
+ await invoke('SideBar.openViewlet', id);
1806
1901
  };
1807
- const isMessagePortMain = value => {
1808
- return value && value.constructor && value.constructor.name === 'MessagePortMain';
1902
+ const hide = async () => {
1903
+ await invoke('Layout.hideSideBar');
1809
1904
  };
1810
- const isOffscreenCanvas = value => {
1811
- return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
1905
+
1906
+ const TestFrameWorkComponentSideBar = {
1907
+ __proto__: null,
1908
+ hide,
1909
+ open
1812
1910
  };
1813
- const isInstanceOf = (value, constructorName) => {
1814
- return value?.constructor?.name === constructorName;
1911
+
1912
+ const acceptInput = async () => {
1913
+ await invoke('Source Control.acceptInput');
1815
1914
  };
1816
- const isSocket = value => {
1817
- return isInstanceOf(value, 'Socket');
1915
+ const handleInput = async text => {
1916
+ await invoke('Source Control.handleInput', text);
1818
1917
  };
1819
- const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
1820
- const isTransferrable = value => {
1821
- for (const fn of transferrables) {
1822
- if (fn(value)) {
1823
- return true;
1824
- }
1825
- }
1826
- return false;
1918
+
1919
+ const TestFrameWorkComponentSourceControl = {
1920
+ __proto__: null,
1921
+ acceptInput,
1922
+ handleInput
1827
1923
  };
1828
- const getTransferrables = value => {
1829
- const transferrables = [];
1830
- walkValue(value, transferrables, isTransferrable);
1831
- return transferrables;
1924
+
1925
+ const update = async () => {
1926
+ await invoke('StatusBar.updateStatusBarItems');
1832
1927
  };
1833
- const attachEvents = that => {
1834
- const handleMessage = (...args) => {
1835
- const data = that.getData(...args);
1836
- that.dispatchEvent(new MessageEvent('message', {
1837
- data
1838
- }));
1839
- };
1840
- that.onMessage(handleMessage);
1841
- const handleClose = event => {
1842
- that.dispatchEvent(new Event('close'));
1843
- };
1844
- that.onClose(handleClose);
1928
+
1929
+ const TestFrameWorkComponentStatusBar = {
1930
+ __proto__: null,
1931
+ update
1845
1932
  };
1846
- class Ipc extends EventTarget {
1847
- constructor(rawIpc) {
1848
- super();
1849
- this._rawIpc = rawIpc;
1850
- attachEvents(this);
1851
- }
1852
- }
1853
- const readyMessage = 'ready';
1854
- const listen$4 = () => {
1855
- // @ts-ignore
1856
- if (typeof WorkerGlobalScope === 'undefined') {
1857
- throw new TypeError('module is not in web worker scope');
1858
- }
1859
- return globalThis;
1933
+
1934
+ const closeMenu = async () => {
1935
+ await invoke('TitleBarMenuBar.closeMenu');
1860
1936
  };
1861
- const signal$3 = global => {
1862
- global.postMessage(readyMessage);
1937
+ const focus = async () => {
1938
+ await invoke('TitleBarMenuBar.focus');
1863
1939
  };
1864
- class IpcChildWithModuleWorker extends Ipc {
1865
- getData(event) {
1866
- return getData$1(event);
1867
- }
1868
- send(message) {
1869
- // @ts-ignore
1870
- this._rawIpc.postMessage(message);
1871
- }
1872
- sendAndTransfer(message) {
1873
- const transfer = getTransferrables(message);
1874
- // @ts-ignore
1875
- this._rawIpc.postMessage(message, transfer);
1876
- }
1877
- dispose() {
1878
- // ignore
1879
- }
1880
- onClose(callback) {
1881
- // ignore
1882
- }
1883
- onMessage(callback) {
1884
- this._rawIpc.addEventListener('message', callback);
1885
- }
1886
- }
1887
- const wrap$6 = global => {
1888
- return new IpcChildWithModuleWorker(global);
1940
+ const focusFirst = async () => {
1941
+ await invoke('TitleBarMenuBar.focusFirst');
1889
1942
  };
1890
- const IpcChildWithModuleWorker$1 = {
1891
- __proto__: null,
1892
- listen: listen$4,
1893
- signal: signal$3,
1894
- wrap: wrap$6
1943
+ const focusIndex = async index => {
1944
+ await invoke('TitleBarMenuBar.focusIndex', index);
1895
1945
  };
1896
- const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
1897
- const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
1898
- const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
1899
- const NewLine$1 = '\n';
1900
- const joinLines = lines => {
1901
- return lines.join(NewLine$1);
1946
+ const focusLast = async () => {
1947
+ await invoke('TitleBarMenuBar.focusLast');
1902
1948
  };
1903
- const splitLines = lines => {
1904
- return lines.split(NewLine$1);
1949
+ const focusNext = async () => {
1950
+ await invoke('TitleBarMenuBar.focusNext');
1905
1951
  };
1906
- const isModuleNotFoundMessage = line => {
1907
- return line.includes('[ERR_MODULE_NOT_FOUND]');
1952
+ const focusPrevious = async () => {
1953
+ await invoke('TitleBarMenuBar.focusPrevious');
1908
1954
  };
1909
- const getModuleNotFoundError = stderr => {
1910
- const lines = splitLines(stderr);
1911
- const messageIndex = lines.findIndex(isModuleNotFoundMessage);
1912
- const message = lines[messageIndex];
1913
- return {
1914
- message,
1915
- code: ERR_MODULE_NOT_FOUND
1916
- };
1955
+ const handleKeyArrowDown = async () => {
1956
+ await invoke('TitleBarMenuBar.handleKeyArrowDown');
1917
1957
  };
1918
- const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
1919
- const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
1920
- const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
1921
- const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
1922
- const RE_AT = /^\s+at/;
1923
- const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
1924
- const isUnhelpfulNativeModuleError = stderr => {
1925
- return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
1958
+ const handleKeyArrowLeft = async () => {
1959
+ await invoke('TitleBarMenuBar.handleKeyArrowLeft');
1926
1960
  };
1927
- const isMessageCodeBlockStartIndex = line => {
1928
- return RE_MESSAGE_CODE_BLOCK_START.test(line);
1961
+ const handleKeyArrowRight = async () => {
1962
+ await invoke('TitleBarMenuBar.handleKeyArrowRight');
1929
1963
  };
1930
- const isMessageCodeBlockEndIndex = line => {
1931
- return RE_MESSAGE_CODE_BLOCK_END.test(line);
1964
+ const handleKeyArrowUp = async () => {
1965
+ await invoke('TitleBarMenuBar.handleKeyArrowUp');
1932
1966
  };
1933
- const getMessageCodeBlock = stderr => {
1934
- const lines = splitLines(stderr);
1935
- const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
1936
- const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
1937
- const relevantLines = lines.slice(startIndex, endIndex);
1938
- const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
1939
- return relevantMessage;
1967
+ const handleKeyEnd = async () => {
1968
+ await invoke('TitleBarMenuBar.handleKeyEnd');
1940
1969
  };
1941
- const getNativeModuleErrorMessage = stderr => {
1942
- const message = getMessageCodeBlock(stderr);
1943
- return {
1944
- message: `Incompatible native node module: ${message}`,
1945
- code: E_INCOMPATIBLE_NATIVE_MODULE
1946
- };
1970
+ const handleKeyHome = async () => {
1971
+ await invoke('TitleBarMenuBar.handleKeyHome');
1947
1972
  };
1948
- const isModulesSyntaxError = stderr => {
1949
- if (!stderr) {
1950
- return false;
1951
- }
1952
- return stderr.includes('SyntaxError: Cannot use import statement outside a module');
1973
+ const handleKeySpace = async () => {
1974
+ await invoke('TitleBarMenuBar.handleKeySpace');
1953
1975
  };
1954
- const getModuleSyntaxError = () => {
1955
- return {
1956
- message: `ES Modules are not supported in electron`,
1957
- code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
1958
- };
1976
+ const handleKeyEscape = async () => {
1977
+ await invoke('TitleBarMenuBar.handleKeyEscape');
1959
1978
  };
1960
- const isModuleNotFoundError = stderr => {
1961
- if (!stderr) {
1962
- return false;
1963
- }
1964
- return stderr.includes('ERR_MODULE_NOT_FOUND');
1979
+ const toggleIndex = async index => {
1980
+ await invoke('TitleBarMenuBar.toggleIndex', index);
1965
1981
  };
1966
- const isNormalStackLine = line => {
1967
- return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
1982
+ const toggleMenu = async () => {
1983
+ await invoke('TitleBarMenuBar.toggleMenu');
1968
1984
  };
1969
- const getDetails = lines => {
1970
- const index = lines.findIndex(isNormalStackLine);
1971
- if (index === -1) {
1972
- return {
1973
- actualMessage: joinLines(lines),
1974
- rest: []
1975
- };
1976
- }
1977
- let lastIndex = index - 1;
1978
- while (++lastIndex < lines.length) {
1979
- if (!isNormalStackLine(lines[lastIndex])) {
1980
- break;
1981
- }
1982
- }
1983
- return {
1984
- actualMessage: lines[index - 1],
1985
- rest: lines.slice(index, lastIndex)
1986
- };
1985
+
1986
+ const TestFrameWorkComponentTitleBarMenuBar = {
1987
+ __proto__: null,
1988
+ closeMenu,
1989
+ focus,
1990
+ focusFirst,
1991
+ focusIndex,
1992
+ focusLast,
1993
+ focusNext,
1994
+ focusPrevious,
1995
+ handleKeyArrowDown,
1996
+ handleKeyArrowLeft,
1997
+ handleKeyArrowRight,
1998
+ handleKeyArrowUp,
1999
+ handleKeyEnd,
2000
+ handleKeyEscape,
2001
+ handleKeyHome,
2002
+ handleKeySpace,
2003
+ toggleIndex,
2004
+ toggleMenu
1987
2005
  };
1988
- const getHelpfulChildProcessError = (stdout, stderr) => {
1989
- if (isUnhelpfulNativeModuleError(stderr)) {
1990
- return getNativeModuleErrorMessage(stderr);
1991
- }
1992
- if (isModulesSyntaxError(stderr)) {
1993
- return getModuleSyntaxError();
1994
- }
1995
- if (isModuleNotFoundError(stderr)) {
1996
- return getModuleNotFoundError(stderr);
1997
- }
1998
- const lines = splitLines(stderr);
2006
+
2007
+ const getPortTuple = () => {
1999
2008
  const {
2000
- actualMessage,
2001
- rest
2002
- } = getDetails(lines);
2009
+ port1,
2010
+ port2
2011
+ } = new MessageChannel();
2003
2012
  return {
2004
- message: `${actualMessage}`,
2005
- code: '',
2006
- stack: rest
2013
+ port1,
2014
+ port2
2007
2015
  };
2008
2016
  };
2009
- const normalizeLine = line => {
2010
- if (line.startsWith('Error: ')) {
2011
- return line.slice(`Error: `.length);
2012
- }
2013
- if (line.startsWith('VError: ')) {
2014
- return line.slice(`VError: `.length);
2015
- }
2016
- return line;
2017
+
2018
+ const sendPortToWebView = async (webviewId, port) => {
2019
+ await invokeAndTransfer('Transferrable.transferToRendererProcess', webviewId, port);
2020
+ console.log('did send port to renderer process');
2021
+ };
2022
+
2023
+ const waitForFirstEventEvent = async port => {
2024
+ const {
2025
+ resolve,
2026
+ promise
2027
+ } = Promise.withResolvers();
2028
+ port.onmessage = resolve;
2029
+ const firstEvent = await promise;
2030
+ return firstEvent;
2017
2031
  };
2018
- const getCombinedMessage = (error, message) => {
2019
- const stringifiedError = normalizeLine(`${error}`);
2020
- if (message) {
2021
- return `${message}: ${stringifiedError}`;
2022
- }
2023
- return stringifiedError;
2032
+
2033
+ const preparePrettyError = error => {
2034
+ return error;
2024
2035
  };
2025
- const NewLine = '\n';
2026
- const getNewLineIndex = (string, startIndex = undefined) => {
2027
- return string.indexOf(NewLine, startIndex);
2036
+ const logError = () => {
2037
+ // ignore
2028
2038
  };
2029
- const mergeStacks = (parent, child) => {
2030
- if (!child) {
2031
- return parent;
2032
- }
2033
- const parentNewLineIndex = getNewLineIndex(parent);
2034
- const childNewLineIndex = getNewLineIndex(child);
2035
- if (childNewLineIndex === -1) {
2036
- return parent;
2037
- }
2038
- const parentFirstLine = parent.slice(0, parentNewLineIndex);
2039
- const childRest = child.slice(childNewLineIndex);
2040
- const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
2041
- if (parentFirstLine.includes(childFirstLine)) {
2042
- return parentFirstLine + childRest;
2043
- }
2044
- return child;
2039
+ const execute$1 = () => {};
2040
+ const requiresSocket = () => {
2041
+ return false;
2045
2042
  };
2046
- class VError extends Error {
2047
- constructor(error, message) {
2048
- const combinedMessage = getCombinedMessage(error, message);
2049
- super(combinedMessage);
2050
- this.name = 'VError';
2051
- if (error instanceof Error) {
2052
- this.stack = mergeStacks(this.stack, error.stack);
2053
- }
2054
- if (error.codeFrame) {
2055
- // @ts-ignore
2056
- this.codeFrame = error.codeFrame;
2057
- }
2058
- if (error.code) {
2059
- // @ts-ignore
2060
- this.code = error.code;
2061
- }
2043
+ const createPortIpc = async webViewId => {
2044
+ const {
2045
+ port1,
2046
+ port2
2047
+ } = getPortTuple();
2048
+ const firstEventPromise = waitForFirstEventEvent(port1);
2049
+ await sendPortToWebView(webViewId, port2);
2050
+ const firstEvent = await firstEventPromise;
2051
+ if (firstEvent.data !== 'ready') {
2052
+ throw new Error('unexpected first message');
2062
2053
  }
2063
- }
2064
- class IpcError extends VError {
2065
- // @ts-ignore
2066
- constructor(betterMessage, stdout = '', stderr = '') {
2067
- if (stdout || stderr) {
2068
- // @ts-ignore
2069
- const {
2070
- message,
2071
- code,
2072
- stack
2073
- } = getHelpfulChildProcessError(stdout, stderr);
2074
- const cause = new Error(message);
2075
- // @ts-ignore
2076
- cause.code = code;
2077
- cause.stack = stack;
2078
- super(cause, betterMessage);
2079
- } else {
2080
- super(betterMessage);
2081
- }
2082
- // @ts-ignore
2083
- this.name = 'IpcError';
2084
- // @ts-ignore
2085
- this.stdout = stdout;
2054
+ const handleOtherMessage = async event => {
2086
2055
  // @ts-ignore
2087
- this.stderr = stderr;
2088
- }
2089
- }
2090
- const withResolvers = () => {
2091
- let _resolve;
2092
- const promise = new Promise(resolve => {
2093
- _resolve = resolve;
2094
- });
2056
+ await handleJsonRpcMessage(ipc, event.data, resolve, preparePrettyError, execute$1, logError, requiresSocket);
2057
+ };
2058
+ port1.onmessage = handleOtherMessage;
2059
+ const ipc = {
2060
+ send(message) {
2061
+ port1.postMessage(message);
2062
+ }
2063
+ };
2064
+ return ipc;
2065
+ };
2066
+
2067
+ const fromId = async webViewId => {
2068
+ const ipc = await createPortIpc(webViewId);
2069
+ const webViewRpc = {
2070
+ invoke(method, ...params) {
2071
+ return invoke$1(ipc, method, ...params);
2072
+ }
2073
+ };
2095
2074
  return {
2096
- resolve: _resolve,
2097
- promise
2075
+ locator(selector, options) {
2076
+ const baseLocator = create(selector, options);
2077
+ baseLocator.webView = webViewRpc;
2078
+ return baseLocator;
2079
+ },
2080
+ expect: expect$1
2098
2081
  };
2099
2082
  };
2100
- const waitForFirstMessage = async port => {
2101
- const {
2102
- resolve,
2103
- promise
2104
- } = withResolvers();
2105
- port.addEventListener('message', resolve, {
2106
- once: true
2107
- });
2108
- const event = await promise;
2109
- // @ts-ignore
2110
- return event.data;
2083
+
2084
+ const TestFrameWorkComponentWebView = {
2085
+ __proto__: null,
2086
+ fromId
2111
2087
  };
2112
- const listen$3 = async () => {
2113
- const parentIpcRaw = listen$4();
2114
- signal$3(parentIpcRaw);
2115
- const parentIpc = wrap$6(parentIpcRaw);
2116
- const firstMessage = await waitForFirstMessage(parentIpc);
2117
- if (firstMessage.method !== 'initialize') {
2118
- throw new IpcError('unexpected first message');
2119
- }
2120
- const type = firstMessage.params[0];
2121
- if (type === 'message-port') {
2122
- parentIpc.send({
2123
- jsonrpc: '2.0',
2124
- id: firstMessage.id,
2125
- result: null
2126
- });
2127
- parentIpc.dispose();
2128
- const port = firstMessage.params[1];
2129
- return port;
2130
- }
2131
- return globalThis;
2088
+
2089
+ const setPath = async path => {
2090
+ await invoke('Workspace.setPath', path);
2132
2091
  };
2133
- class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
2134
- constructor(port) {
2135
- super(port);
2136
- }
2137
- getData(event) {
2138
- return getData$1(event);
2139
- }
2140
- send(message) {
2141
- this._rawIpc.postMessage(message);
2142
- }
2143
- sendAndTransfer(message) {
2144
- const transfer = getTransferrables(message);
2145
- this._rawIpc.postMessage(message, transfer);
2146
- }
2147
- dispose() {
2148
- if (this._rawIpc.close) {
2149
- this._rawIpc.close();
2150
- }
2151
- }
2152
- onClose(callback) {
2153
- // ignore
2154
- }
2155
- onMessage(callback) {
2156
- this._rawIpc.addEventListener('message', callback);
2157
- this._rawIpc.start();
2158
- }
2159
- }
2160
- const wrap$5 = port => {
2161
- return new IpcChildWithModuleWorkerAndMessagePort(port);
2092
+
2093
+ const TestFrameWorkComponentWorkspace = {
2094
+ __proto__: null,
2095
+ setPath
2162
2096
  };
2163
- const IpcChildWithModuleWorkerAndMessagePort$1 = {
2097
+
2098
+ const TestFrameWorkComponent = {
2164
2099
  __proto__: null,
2165
- listen: listen$3,
2166
- wrap: wrap$5
2100
+ About: TestFrameWorkComponentAbout,
2101
+ ActivityBar: TestFrameworkComponentActivityBar,
2102
+ BaseUrl: TestFrameWorkComponentBaseUrl,
2103
+ Command: TestFrameWorkComponentCommand,
2104
+ ContextMenu: TestFrameWorkComponentContextMenu,
2105
+ Editor: TestFrameWorkComponentEditor,
2106
+ Explorer: TestFrameWorkComponentExplorer,
2107
+ Extension: TestFrameWorkComponentExtension,
2108
+ FileSystem: TestFrameWorkComponentFileSystem,
2109
+ FindWidget: TestFrameWorkComponentFindWidget,
2110
+ IconTheme: TestFrameWorkComponentIconTheme,
2111
+ KeyBoard: TestFrameWorkComponentKeyBoard,
2112
+ Main: TestFrameWorkComponentMain,
2113
+ Panel: TestFrameWorkComponentPanel,
2114
+ Platform: TestFrameWorkComponentPlatform,
2115
+ Problems: TestFrameWorkComponentProblems,
2116
+ QuickPick: TestFrameWorkComponentQuickPick,
2117
+ Search: TestFrameWorkComponentSearch,
2118
+ Settings: TestFrameWorkComponentSettings,
2119
+ SideBar: TestFrameWorkComponentSideBar,
2120
+ SourceControl: TestFrameWorkComponentSourceControl,
2121
+ StatusBar: TestFrameWorkComponentStatusBar,
2122
+ TitleBarMenuBar: TestFrameWorkComponentTitleBarMenuBar,
2123
+ WebView: TestFrameWorkComponentWebView,
2124
+ Workspace: TestFrameWorkComponentWorkspace
2167
2125
  };
2168
2126
 
2169
- const getModule = method => {
2170
- switch (method) {
2171
- case ModuleWorker:
2172
- return IpcChildWithModuleWorker$1;
2173
- case ModuleWorkerAndMessagePort:
2174
- return IpcChildWithModuleWorkerAndMessagePort$1;
2175
- default:
2176
- throw new Error('unexpected ipc type');
2127
+ const execute = async href => {
2128
+ const globals = {
2129
+ ...TestFrameWorkComponent,
2130
+ ...TestFrameWork
2131
+ };
2132
+ // TODO
2133
+ // 0. wait for page to be ready
2134
+ // 1. get script to import from renderer process (url or from html)
2135
+ const scriptUrl = href;
2136
+ // 2. import that script
2137
+ const module = await importTest(scriptUrl);
2138
+ if (module.mockRpc) {
2139
+ setMockRpc(module.mockRpc);
2140
+ }
2141
+ if (module.test) {
2142
+ if (module.skip) {
2143
+ await test.skip(module.name);
2144
+ } else {
2145
+ await executeTest(module.name, module.test, globals);
2146
+ }
2147
+ } else {
2148
+ const tests = getTests();
2149
+ for (const test of tests) {
2150
+ // @ts-ignore
2151
+ await executeTest(test.name, test.fn);
2152
+ }
2177
2153
  }
2154
+ // 3. if import fails, display error message
2155
+
2156
+ // 4. run the test
2157
+ // 5. if test fails, display error message
2158
+ // 6. if test succeeds, display success message
2178
2159
  };
2179
2160
 
2180
- const listen$1 = async ({
2181
- method
2182
- }) => {
2183
- const module = await getModule(method);
2184
- const rawIpc = await module.listen();
2185
- if (module.signal) {
2186
- module.signal(rawIpc);
2187
- }
2188
- const ipc = module.wrap(rawIpc);
2189
- return ipc;
2161
+ const commandMap = {
2162
+ 'Test.execute': execute
2190
2163
  };
2191
2164
 
2192
2165
  const listen = async () => {
2193
- register(commandMap);
2194
- const ipc = await listen$1({
2195
- method: Auto()
2166
+ const rpc = await WebWorkerRpcClient.create({
2167
+ commandMap: commandMap
2196
2168
  });
2197
- handleIpc(ipc);
2198
- listen$2(ipc);
2169
+ setRpc(rpc);
2199
2170
  };
2200
2171
 
2201
2172
  const main = async () => {