@lvce-editor/test-worker 6.0.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/testWorkerMain.js +68 -65
- package/package.json +1 -1
package/dist/testWorkerMain.js
CHANGED
|
@@ -1079,10 +1079,55 @@ const sendMessagePortToEditorWorker = async (port, rpcId) => {
|
|
|
1079
1079
|
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
|
|
1080
1080
|
};
|
|
1081
1081
|
|
|
1082
|
+
const callFunction = async (fn, args) => {
|
|
1083
|
+
try {
|
|
1084
|
+
await fn(args);
|
|
1085
|
+
return undefined;
|
|
1086
|
+
} catch (error) {
|
|
1087
|
+
return error;
|
|
1088
|
+
}
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1082
1091
|
const formatDuration = duration => {
|
|
1083
1092
|
return duration.toFixed(2) + 'ms';
|
|
1084
1093
|
};
|
|
1085
1094
|
|
|
1095
|
+
const Fail = 'fail';
|
|
1096
|
+
const Pass = 'pass';
|
|
1097
|
+
|
|
1098
|
+
const executeTest2 = async (name, fn, globals, timestampGenerator) => {
|
|
1099
|
+
const getTimestamp = timestampGenerator;
|
|
1100
|
+
const start = getTimestamp();
|
|
1101
|
+
const error = await callFunction(fn, globals);
|
|
1102
|
+
const end = getTimestamp();
|
|
1103
|
+
const duration = end - start;
|
|
1104
|
+
const formattedDuration = formatDuration(duration);
|
|
1105
|
+
if (error) {
|
|
1106
|
+
return {
|
|
1107
|
+
error,
|
|
1108
|
+
start,
|
|
1109
|
+
end,
|
|
1110
|
+
duration,
|
|
1111
|
+
formattedDuration,
|
|
1112
|
+
name,
|
|
1113
|
+
type: Fail,
|
|
1114
|
+
background: 'red',
|
|
1115
|
+
text: `test failed: ${error}`
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
return {
|
|
1119
|
+
error: undefined,
|
|
1120
|
+
start,
|
|
1121
|
+
end,
|
|
1122
|
+
duration,
|
|
1123
|
+
formattedDuration,
|
|
1124
|
+
name,
|
|
1125
|
+
type: Pass,
|
|
1126
|
+
background: 'green',
|
|
1127
|
+
text: `test passed in ${formattedDuration}`
|
|
1128
|
+
};
|
|
1129
|
+
};
|
|
1130
|
+
|
|
1086
1131
|
const printError = error => {
|
|
1087
1132
|
if (error && error.constructor.name === 'AssertionError') {
|
|
1088
1133
|
console.error(error.message);
|
|
@@ -1096,66 +1141,26 @@ const printTestError = async error => {
|
|
|
1096
1141
|
printError(error);
|
|
1097
1142
|
};
|
|
1098
1143
|
|
|
1099
|
-
const stringifyError = error => {
|
|
1100
|
-
if (!error) {
|
|
1101
|
-
return `${error}`;
|
|
1102
|
-
}
|
|
1103
|
-
if (error && error.message && error.constructor.name && error.constructor.name !== 'Error' && error.constructor.name !== 'VError') {
|
|
1104
|
-
return `${error}`;
|
|
1105
|
-
}
|
|
1106
|
-
return `${error.message}`;
|
|
1107
|
-
};
|
|
1108
|
-
|
|
1109
|
-
const Fail = 'fail';
|
|
1110
|
-
const Pass = 'pass';
|
|
1111
|
-
|
|
1112
1144
|
const now = () => {
|
|
1113
1145
|
return performance.now();
|
|
1114
1146
|
};
|
|
1115
1147
|
|
|
1116
|
-
// TODO make this code more functional, returning a test result
|
|
1117
|
-
// and a separate function prints out the test result
|
|
1118
1148
|
const executeTest = async (name, fn, globals = {}) => {
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
_end = now();
|
|
1128
|
-
_duration = _end - _start;
|
|
1129
|
-
_formattedDuration = formatDuration(_duration);
|
|
1130
|
-
// eslint-disable-next-line no-console
|
|
1131
|
-
console.info(`PASS ${name} in ${_formattedDuration}`);
|
|
1132
|
-
} catch (error) {
|
|
1133
|
-
if (error &&
|
|
1134
|
-
// @ts-ignore
|
|
1135
|
-
error.message.startsWith('Failed to load command TestFrameWork.')) {
|
|
1136
|
-
console.error(error);
|
|
1137
|
-
return;
|
|
1138
|
-
}
|
|
1139
|
-
_error = stringifyError(error);
|
|
1140
|
-
if (!(error instanceof VError)) {
|
|
1141
|
-
error = new VError(error, `Test failed: ${name}`);
|
|
1142
|
-
}
|
|
1149
|
+
const {
|
|
1150
|
+
error,
|
|
1151
|
+
formattedDuration,
|
|
1152
|
+
background,
|
|
1153
|
+
text,
|
|
1154
|
+
type
|
|
1155
|
+
} = await executeTest2(name, fn, globals, now);
|
|
1156
|
+
if (error) {
|
|
1143
1157
|
await printTestError(error);
|
|
1144
|
-
}
|
|
1145
|
-
let state;
|
|
1146
|
-
let background;
|
|
1147
|
-
let text;
|
|
1148
|
-
if (_error) {
|
|
1149
|
-
state = Fail;
|
|
1150
|
-
background = 'red';
|
|
1151
|
-
text = `test failed: ${_error}`;
|
|
1152
1158
|
} else {
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
state = Pass;
|
|
1159
|
+
// eslint-disable-next-line no-console
|
|
1160
|
+
console.info(`PASS ${name} in ${formattedDuration}`);
|
|
1156
1161
|
}
|
|
1157
1162
|
// @ts-ignore
|
|
1158
|
-
await invoke$1('TestFrameWork.showOverlay',
|
|
1163
|
+
await invoke$1('TestFrameWork.showOverlay', type, background, text);
|
|
1159
1164
|
};
|
|
1160
1165
|
|
|
1161
1166
|
const importScript = async url => {
|
|
@@ -2571,7 +2576,7 @@ const createDroppedFileHandle = async () => {
|
|
|
2571
2576
|
});
|
|
2572
2577
|
const file = await fileHandle.getFile();
|
|
2573
2578
|
// @ts-ignore
|
|
2574
|
-
const id = await
|
|
2579
|
+
const id = await invoke$1('FileSystemHandle.addFileHandle', fileHandle);
|
|
2575
2580
|
return {
|
|
2576
2581
|
file,
|
|
2577
2582
|
id
|
|
@@ -2964,11 +2969,6 @@ const getIsFirefox = () => {
|
|
|
2964
2969
|
return navigator.userAgent.toLowerCase().includes('firefox');
|
|
2965
2970
|
};
|
|
2966
2971
|
|
|
2967
|
-
/**
|
|
2968
|
-
* @type {boolean}
|
|
2969
|
-
*/
|
|
2970
|
-
const isFirefox$1 = getIsFirefox();
|
|
2971
|
-
|
|
2972
2972
|
const getNodePath$1 = () => {
|
|
2973
2973
|
// @ts-ignore
|
|
2974
2974
|
return invoke$1(/* Platform.getNodePath */'Platform.getNodePath');
|
|
@@ -2978,7 +2978,7 @@ const getNodePath = () => {
|
|
|
2978
2978
|
return getNodePath$1();
|
|
2979
2979
|
};
|
|
2980
2980
|
const isFirefox = () => {
|
|
2981
|
-
return
|
|
2981
|
+
return getIsFirefox();
|
|
2982
2982
|
};
|
|
2983
2983
|
|
|
2984
2984
|
const TestFrameWorkComponentPlatform = {
|
|
@@ -3498,6 +3498,7 @@ const getPortTuple = () => {
|
|
|
3498
3498
|
};
|
|
3499
3499
|
};
|
|
3500
3500
|
|
|
3501
|
+
// TODO ask webview worker directly
|
|
3501
3502
|
const getWebViewInfo = async webViewId => {
|
|
3502
3503
|
const info = await invoke$1('WebView.getWebViewInfo2', webViewId);
|
|
3503
3504
|
return info;
|
|
@@ -3507,6 +3508,12 @@ const setWebViewPort = async (uid, port, origin, portType) => {
|
|
|
3507
3508
|
await invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
|
|
3508
3509
|
};
|
|
3509
3510
|
|
|
3511
|
+
const transferWebViewPort = async (webViewId, port) => {
|
|
3512
|
+
const info = await getWebViewInfo(webViewId);
|
|
3513
|
+
const portType = 'test';
|
|
3514
|
+
await setWebViewPort(info.uid, port, info.origin, portType);
|
|
3515
|
+
};
|
|
3516
|
+
|
|
3510
3517
|
const waitForFirstEventEvent = async port => {
|
|
3511
3518
|
const {
|
|
3512
3519
|
resolve,
|
|
@@ -3517,7 +3524,7 @@ const waitForFirstEventEvent = async port => {
|
|
|
3517
3524
|
return firstEvent;
|
|
3518
3525
|
};
|
|
3519
3526
|
|
|
3520
|
-
const
|
|
3527
|
+
const createPortRpc = async webViewId => {
|
|
3521
3528
|
// TODO use transforpemssageportrpc
|
|
3522
3529
|
const {
|
|
3523
3530
|
port1,
|
|
@@ -3525,11 +3532,7 @@ const createPortIpc = async webViewId => {
|
|
|
3525
3532
|
} = getPortTuple();
|
|
3526
3533
|
const firstEventPromise = waitForFirstEventEvent(port1);
|
|
3527
3534
|
// TODO ask extension host worker about webview uid
|
|
3528
|
-
|
|
3529
|
-
const portType = 'test';
|
|
3530
|
-
await setWebViewPort(info.uid, port2, info.origin, portType);
|
|
3531
|
-
|
|
3532
|
-
// await SendPortToWebView.sendPortToWebView(webViewId, port2)
|
|
3535
|
+
await transferWebViewPort(webViewId, port2);
|
|
3533
3536
|
const firstEvent = await firstEventPromise;
|
|
3534
3537
|
if (firstEvent.data !== 'ready') {
|
|
3535
3538
|
throw new Error('unexpected first message');
|
|
@@ -3543,7 +3546,7 @@ const createPortIpc = async webViewId => {
|
|
|
3543
3546
|
};
|
|
3544
3547
|
|
|
3545
3548
|
const fromId = async webViewId => {
|
|
3546
|
-
const rpc = await
|
|
3549
|
+
const rpc = await createPortRpc(webViewId);
|
|
3547
3550
|
set(webViewId, rpc);
|
|
3548
3551
|
return {
|
|
3549
3552
|
locator(selector, options) {
|