@lvce-editor/test-worker 6.1.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 +63 -54
- 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 => {
|
|
@@ -3503,6 +3508,12 @@ const setWebViewPort = async (uid, port, origin, portType) => {
|
|
|
3503
3508
|
await invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
|
|
3504
3509
|
};
|
|
3505
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
|
+
|
|
3506
3517
|
const waitForFirstEventEvent = async port => {
|
|
3507
3518
|
const {
|
|
3508
3519
|
resolve,
|
|
@@ -3521,9 +3532,7 @@ const createPortRpc = async webViewId => {
|
|
|
3521
3532
|
} = getPortTuple();
|
|
3522
3533
|
const firstEventPromise = waitForFirstEventEvent(port1);
|
|
3523
3534
|
// TODO ask extension host worker about webview uid
|
|
3524
|
-
|
|
3525
|
-
const portType = 'test';
|
|
3526
|
-
await setWebViewPort(info.uid, port2, info.origin, portType);
|
|
3535
|
+
await transferWebViewPort(webViewId, port2);
|
|
3527
3536
|
const firstEvent = await firstEventPromise;
|
|
3528
3537
|
if (firstEvent.data !== 'ready') {
|
|
3529
3538
|
throw new Error('unexpected first message');
|