@lvce-editor/test-worker 9.6.0 → 9.8.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 +93 -4
- package/package.json +1 -1
package/dist/testWorkerMain.js
CHANGED
|
@@ -64,7 +64,7 @@ const Object$1 = 1;
|
|
|
64
64
|
const Number$1 = 2;
|
|
65
65
|
const Array$1 = 3;
|
|
66
66
|
const String = 4;
|
|
67
|
-
const Boolean = 5;
|
|
67
|
+
const Boolean$1 = 5;
|
|
68
68
|
const Function = 6;
|
|
69
69
|
const Null = 7;
|
|
70
70
|
const Unknown = 8;
|
|
@@ -85,7 +85,7 @@ const getType = value => {
|
|
|
85
85
|
}
|
|
86
86
|
return Object$1;
|
|
87
87
|
case 'boolean':
|
|
88
|
-
return Boolean;
|
|
88
|
+
return Boolean$1;
|
|
89
89
|
default:
|
|
90
90
|
return Unknown;
|
|
91
91
|
}
|
|
@@ -1087,6 +1087,9 @@ const sendMessagePortToEditorWorker = async (port, rpcId) => {
|
|
|
1087
1087
|
// @ts-ignore
|
|
1088
1088
|
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
|
|
1089
1089
|
};
|
|
1090
|
+
const getPreference = async key => {
|
|
1091
|
+
return await invoke$1('Preferences.get', key);
|
|
1092
|
+
};
|
|
1090
1093
|
|
|
1091
1094
|
const createLazyRpc = rpcId => {
|
|
1092
1095
|
let rpcPromise;
|
|
@@ -1113,8 +1116,11 @@ const createLazyRpc = rpcId => {
|
|
|
1113
1116
|
};
|
|
1114
1117
|
};
|
|
1115
1118
|
|
|
1116
|
-
const
|
|
1117
|
-
|
|
1119
|
+
const createUrlWithQueryParameter = url => {
|
|
1120
|
+
const parsedUrl = new URL(url, location.href);
|
|
1121
|
+
parsedUrl.searchParams.set('time', `${Date.now()}`);
|
|
1122
|
+
const string = parsedUrl.toString();
|
|
1123
|
+
return string;
|
|
1118
1124
|
};
|
|
1119
1125
|
|
|
1120
1126
|
// @ts-nocheck
|
|
@@ -3882,6 +3888,11 @@ const executeTest = async (name, fn, globals = {}) => {
|
|
|
3882
3888
|
await invoke$1('TestFrameWork.showOverlay', type, background, text);
|
|
3883
3889
|
};
|
|
3884
3890
|
|
|
3891
|
+
const hotReloadEnabled = async () => {
|
|
3892
|
+
const preference = await getPreference('E2eTest.hotReload');
|
|
3893
|
+
return Boolean(preference);
|
|
3894
|
+
};
|
|
3895
|
+
|
|
3885
3896
|
const importScript = async url => {
|
|
3886
3897
|
try {
|
|
3887
3898
|
return await import(url);
|
|
@@ -3901,11 +3912,50 @@ const importTest = async url => {
|
|
|
3901
3912
|
}
|
|
3902
3913
|
};
|
|
3903
3914
|
|
|
3915
|
+
let items = [];
|
|
3916
|
+
const hasItems = () => {
|
|
3917
|
+
return items.length > 0;
|
|
3918
|
+
};
|
|
3919
|
+
const push = item => {
|
|
3920
|
+
items = [...items, item];
|
|
3921
|
+
};
|
|
3922
|
+
const last = () => {
|
|
3923
|
+
const item = items.at(-1);
|
|
3924
|
+
if (!item) {
|
|
3925
|
+
throw new Error(`no item found`);
|
|
3926
|
+
}
|
|
3927
|
+
return item;
|
|
3928
|
+
};
|
|
3929
|
+
|
|
3930
|
+
const getFileUri = href => {
|
|
3931
|
+
const rest = href.slice('/remote'.length);
|
|
3932
|
+
const fileUrl = `file://${rest}`;
|
|
3933
|
+
return fileUrl;
|
|
3934
|
+
};
|
|
3935
|
+
const watchForHotReload = async (platform, href) => {
|
|
3936
|
+
if (platform !== Remote) {
|
|
3937
|
+
return;
|
|
3938
|
+
}
|
|
3939
|
+
if (!href.startsWith('/remote')) {
|
|
3940
|
+
return;
|
|
3941
|
+
}
|
|
3942
|
+
const fileUrl = getFileUri(href);
|
|
3943
|
+
const callbackCommand = 'FileWatcher.handleEvent';
|
|
3944
|
+
// @ts-ignore
|
|
3945
|
+
await invoke$1('FileWatcher.watchFile', TestWorker, callbackCommand, fileUrl);
|
|
3946
|
+
};
|
|
3947
|
+
|
|
3904
3948
|
// TODO move this into three steps:
|
|
3905
3949
|
// 1. import test module
|
|
3906
3950
|
// 2. execute test
|
|
3907
3951
|
// 3. print out results
|
|
3908
3952
|
const execute = async (href, platform, assetDir) => {
|
|
3953
|
+
push({
|
|
3954
|
+
url: href,
|
|
3955
|
+
assetDir,
|
|
3956
|
+
platform,
|
|
3957
|
+
inProgress: true
|
|
3958
|
+
});
|
|
3909
3959
|
const globals = createApi(platform, assetDir);
|
|
3910
3960
|
// TODO
|
|
3911
3961
|
// 0. wait for page to be ready
|
|
@@ -3935,6 +3985,45 @@ const execute = async (href, platform, assetDir) => {
|
|
|
3935
3985
|
// 4. run the test
|
|
3936
3986
|
// 5. if test fails, display error message
|
|
3937
3987
|
// 6. if test succeeds, display success message
|
|
3988
|
+
|
|
3989
|
+
// TODO maybe setup file watcher earlier, to not miss events?
|
|
3990
|
+
|
|
3991
|
+
push({
|
|
3992
|
+
url: href,
|
|
3993
|
+
assetDir,
|
|
3994
|
+
platform,
|
|
3995
|
+
inProgress: false
|
|
3996
|
+
});
|
|
3997
|
+
// TODO if file watcher was previously added, don't need to add one
|
|
3998
|
+
try {
|
|
3999
|
+
if (await hotReloadEnabled()) {
|
|
4000
|
+
await watchForHotReload(platform, href);
|
|
4001
|
+
}
|
|
4002
|
+
} catch {
|
|
4003
|
+
// ignore
|
|
4004
|
+
}
|
|
4005
|
+
};
|
|
4006
|
+
|
|
4007
|
+
const hotReloadTest = async () => {
|
|
4008
|
+
if (!hasItems()) {
|
|
4009
|
+
return;
|
|
4010
|
+
}
|
|
4011
|
+
const last$1 = last();
|
|
4012
|
+
const {
|
|
4013
|
+
platform,
|
|
4014
|
+
url,
|
|
4015
|
+
assetDir,
|
|
4016
|
+
inProgress
|
|
4017
|
+
} = last$1;
|
|
4018
|
+
if (inProgress) {
|
|
4019
|
+
return;
|
|
4020
|
+
}
|
|
4021
|
+
const withQueryParameter = createUrlWithQueryParameter(url);
|
|
4022
|
+
await execute(withQueryParameter, platform, assetDir);
|
|
4023
|
+
};
|
|
4024
|
+
|
|
4025
|
+
const handleFileWatcherEvent = async event => {
|
|
4026
|
+
await hotReloadTest();
|
|
3938
4027
|
};
|
|
3939
4028
|
|
|
3940
4029
|
const commandMap = {
|