@lvce-editor/test-worker 6.3.0 → 6.5.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/api.d.ts +8 -0
- package/dist/testWorkerMain.js +133 -39
- package/package.json +4 -1
package/dist/api.d.ts
CHANGED
|
@@ -193,6 +193,12 @@ interface EditorHover {
|
|
|
193
193
|
readonly show: () => Promise<void>;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
+
interface EditorRename {
|
|
197
|
+
readonly accept: () => Promise<void>;
|
|
198
|
+
readonly cancel: () => Promise<void>;
|
|
199
|
+
readonly handleInput: (value: string) => Promise<void>;
|
|
200
|
+
}
|
|
201
|
+
|
|
196
202
|
interface EditorSourceAction {
|
|
197
203
|
readonly selectCurrentIndex: () => Promise<void>;
|
|
198
204
|
readonly selectIndex: (index: number) => Promise<void>;
|
|
@@ -269,6 +275,7 @@ interface FileSystem {
|
|
|
269
275
|
readonly createExecutable: (content: string) => Promise<string>;
|
|
270
276
|
readonly createExecutableFrom: (uri: string) => Promise<string>;
|
|
271
277
|
readonly getTmpDir: ({ scheme }?: FileSystemTmpDirOptions) => Promise<string>;
|
|
278
|
+
readonly loadFixture: (platform: number, url: string) => Promise<string>;
|
|
272
279
|
readonly mkdir: (uri: string) => Promise<void>;
|
|
273
280
|
readonly readFile: (uri: string) => Promise<string>;
|
|
274
281
|
readonly remove: (uri: string) => Promise<void>;
|
|
@@ -517,6 +524,7 @@ export interface TestApi {
|
|
|
517
524
|
readonly Editor: Editor
|
|
518
525
|
readonly EditorCompletion: EditorCompletion
|
|
519
526
|
readonly EditorHover: EditorHover
|
|
527
|
+
readonly EditorRename: EditorRename
|
|
520
528
|
readonly EditorSourceAction: EditorSourceAction
|
|
521
529
|
readonly Explorer: Explorer
|
|
522
530
|
readonly Extension: Extension
|
package/dist/testWorkerMain.js
CHANGED
|
@@ -1034,6 +1034,11 @@ const WebWorkerRpcClient = {
|
|
|
1034
1034
|
create: create$2
|
|
1035
1035
|
};
|
|
1036
1036
|
|
|
1037
|
+
const Web = 1;
|
|
1038
|
+
const Electron = 2;
|
|
1039
|
+
const Remote = 3;
|
|
1040
|
+
|
|
1041
|
+
const EditorWorker = 99;
|
|
1037
1042
|
const RendererWorker = 1;
|
|
1038
1043
|
const TestWorker = 9001;
|
|
1039
1044
|
|
|
@@ -1079,6 +1084,31 @@ const sendMessagePortToEditorWorker = async (port, rpcId) => {
|
|
|
1079
1084
|
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
|
|
1080
1085
|
};
|
|
1081
1086
|
|
|
1087
|
+
const createLazyRpc = rpcId => {
|
|
1088
|
+
let rpcPromise;
|
|
1089
|
+
let factory;
|
|
1090
|
+
const createRpc = async () => {
|
|
1091
|
+
const rpc = await factory();
|
|
1092
|
+
set$2(rpcId, rpc);
|
|
1093
|
+
};
|
|
1094
|
+
const ensureRpc = async () => {
|
|
1095
|
+
if (!rpcPromise) {
|
|
1096
|
+
rpcPromise = createRpc();
|
|
1097
|
+
}
|
|
1098
|
+
await rpcPromise;
|
|
1099
|
+
};
|
|
1100
|
+
return {
|
|
1101
|
+
setFactory(value) {
|
|
1102
|
+
factory = value;
|
|
1103
|
+
},
|
|
1104
|
+
async invoke(method, ...params) {
|
|
1105
|
+
await ensureRpc();
|
|
1106
|
+
const rpc = get$1(rpcId);
|
|
1107
|
+
return rpc.invoke(method, ...params);
|
|
1108
|
+
}
|
|
1109
|
+
};
|
|
1110
|
+
};
|
|
1111
|
+
|
|
1082
1112
|
const callFunction = async (fn, args) => {
|
|
1083
1113
|
try {
|
|
1084
1114
|
await fn(args);
|
|
@@ -1700,9 +1730,6 @@ const TestFrameworkComponentActivityBar = {
|
|
|
1700
1730
|
selectCurrent
|
|
1701
1731
|
};
|
|
1702
1732
|
|
|
1703
|
-
const Electron = 'electron';
|
|
1704
|
-
const Remote = 'remote';
|
|
1705
|
-
|
|
1706
1733
|
// @ts-nocheck
|
|
1707
1734
|
|
|
1708
1735
|
const getPlatform = () => {
|
|
@@ -1714,6 +1741,10 @@ const getPlatform = () => {
|
|
|
1714
1741
|
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
|
|
1715
1742
|
return 'test';
|
|
1716
1743
|
}
|
|
1744
|
+
// Check if running in web environment
|
|
1745
|
+
if (globalThis.window !== undefined && typeof document !== 'undefined') {
|
|
1746
|
+
return Web;
|
|
1747
|
+
}
|
|
1717
1748
|
// TODO find a better way to pass runtime environment
|
|
1718
1749
|
if (typeof name !== 'undefined' && name.endsWith('(Electron)')) {
|
|
1719
1750
|
return Electron;
|
|
@@ -1899,28 +1930,10 @@ const areSelectionsEqual = (a, b) => {
|
|
|
1899
1930
|
return true;
|
|
1900
1931
|
};
|
|
1901
1932
|
|
|
1902
|
-
const
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
const rpc = await TransferMessagePortRpcParent.create({
|
|
1907
|
-
commandMap: {},
|
|
1908
|
-
send
|
|
1909
|
-
});
|
|
1910
|
-
return rpc;
|
|
1911
|
-
};
|
|
1912
|
-
|
|
1913
|
-
let rpcPromise;
|
|
1914
|
-
const getRpc = () => {
|
|
1915
|
-
if (!rpcPromise) {
|
|
1916
|
-
rpcPromise = launchEditorWorkerRpc();
|
|
1917
|
-
}
|
|
1918
|
-
return rpcPromise;
|
|
1919
|
-
};
|
|
1920
|
-
const invoke = async (method, ...params) => {
|
|
1921
|
-
const rpc = await getRpc();
|
|
1922
|
-
return rpc.invoke(method, ...params);
|
|
1923
|
-
};
|
|
1933
|
+
const {
|
|
1934
|
+
invoke,
|
|
1935
|
+
setFactory
|
|
1936
|
+
} = createLazyRpc(EditorWorker);
|
|
1924
1937
|
|
|
1925
1938
|
const Script = 2;
|
|
1926
1939
|
|
|
@@ -2239,6 +2252,26 @@ const TestFrameWorkComponentEditorHover = {
|
|
|
2239
2252
|
show: show$3
|
|
2240
2253
|
};
|
|
2241
2254
|
|
|
2255
|
+
const handleInput$4 = async value => {
|
|
2256
|
+
// @ts-ignore
|
|
2257
|
+
await invoke$1('EditorRename.handleInput', value, Script);
|
|
2258
|
+
};
|
|
2259
|
+
const accept = async () => {
|
|
2260
|
+
// @ts-ignore
|
|
2261
|
+
await invoke$1('EditorRename.accept');
|
|
2262
|
+
};
|
|
2263
|
+
const cancel = async () => {
|
|
2264
|
+
// @ts-ignore
|
|
2265
|
+
await invoke$1('EditorRename.cancel');
|
|
2266
|
+
};
|
|
2267
|
+
|
|
2268
|
+
const TestFrameWorkComponentEditorRename = {
|
|
2269
|
+
__proto__: null,
|
|
2270
|
+
accept,
|
|
2271
|
+
cancel,
|
|
2272
|
+
handleInput: handleInput$4
|
|
2273
|
+
};
|
|
2274
|
+
|
|
2242
2275
|
const selectIndex$5 = async index => {
|
|
2243
2276
|
// @ts-ignore
|
|
2244
2277
|
await invoke$1('EditorSourceAction.selectIndex', index);
|
|
@@ -2517,6 +2550,37 @@ const TestFrameWorkComponentExtensionDetail = {
|
|
|
2517
2550
|
|
|
2518
2551
|
const Memfs = 'memfs';
|
|
2519
2552
|
|
|
2553
|
+
const isObject = value => {
|
|
2554
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
2555
|
+
};
|
|
2556
|
+
const isValidFileMap = value => {
|
|
2557
|
+
if (!isObject(value)) {
|
|
2558
|
+
return false;
|
|
2559
|
+
}
|
|
2560
|
+
for (const key in value) {
|
|
2561
|
+
if (typeof value[key] !== 'string') {
|
|
2562
|
+
return false;
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
return true;
|
|
2566
|
+
};
|
|
2567
|
+
|
|
2568
|
+
const loadFileMap = async fileMapUrl => {
|
|
2569
|
+
try {
|
|
2570
|
+
const response = await fetch(fileMapUrl);
|
|
2571
|
+
if (!response.ok) {
|
|
2572
|
+
throw new Error(`Failed to load filemap.json: ${response.status} ${response.statusText}`);
|
|
2573
|
+
}
|
|
2574
|
+
const parsedJson = await response.json();
|
|
2575
|
+
if (!isValidFileMap(parsedJson)) {
|
|
2576
|
+
throw new Error('Invalid file map format: expected an object with string values');
|
|
2577
|
+
}
|
|
2578
|
+
return parsedJson;
|
|
2579
|
+
} catch (error) {
|
|
2580
|
+
throw new VError(error, `Failed to load file map from ${fileMapUrl}`);
|
|
2581
|
+
}
|
|
2582
|
+
};
|
|
2583
|
+
|
|
2520
2584
|
const Backslash = '\\';
|
|
2521
2585
|
const Slash$1 = '/';
|
|
2522
2586
|
|
|
@@ -2534,6 +2598,16 @@ const stringifyJson = data => {
|
|
|
2534
2598
|
return JSON.stringify(data, null, 2) + '\n';
|
|
2535
2599
|
};
|
|
2536
2600
|
|
|
2601
|
+
const toFileUrl = url => {
|
|
2602
|
+
const urlObject = new URL(url);
|
|
2603
|
+
const pathName = urlObject.pathname;
|
|
2604
|
+
if (!pathName.startsWith('/remote')) {
|
|
2605
|
+
throw new Error(`url must start with /remote`);
|
|
2606
|
+
}
|
|
2607
|
+
const rest = pathName.slice('/remote'.length);
|
|
2608
|
+
return `file://${rest}`;
|
|
2609
|
+
};
|
|
2610
|
+
|
|
2537
2611
|
const writeFile = async (uri, content) => {
|
|
2538
2612
|
await invoke$1('FileSystem.writeFile', uri, content);
|
|
2539
2613
|
};
|
|
@@ -2598,6 +2672,22 @@ const createDroppedFileHandle = async () => {
|
|
|
2598
2672
|
id
|
|
2599
2673
|
};
|
|
2600
2674
|
};
|
|
2675
|
+
const loadFixture = async (platform, url) => {
|
|
2676
|
+
// Handle fixture URLs in web environment
|
|
2677
|
+
if (platform === Web) {
|
|
2678
|
+
const fileMapUrl = `${url}/fileMap.json`;
|
|
2679
|
+
// @ts-ignore
|
|
2680
|
+
loadFileMap(fileMapUrl);
|
|
2681
|
+
// TODO add those files to memory file system
|
|
2682
|
+
// TODO then return the memory file system url
|
|
2683
|
+
return '';
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
// TODO maybe also create a memory file system for consistency with web
|
|
2687
|
+
// TODO covert remote url to file url
|
|
2688
|
+
// then set that as workspace path
|
|
2689
|
+
return toFileUrl(url);
|
|
2690
|
+
};
|
|
2601
2691
|
|
|
2602
2692
|
const TestFrameWorkComponentFileSystem = {
|
|
2603
2693
|
__proto__: null,
|
|
@@ -2606,6 +2696,7 @@ const TestFrameWorkComponentFileSystem = {
|
|
|
2606
2696
|
createExecutable,
|
|
2607
2697
|
createExecutableFrom,
|
|
2608
2698
|
getTmpDir,
|
|
2699
|
+
loadFixture,
|
|
2609
2700
|
mkdir,
|
|
2610
2701
|
readFile,
|
|
2611
2702
|
remove,
|
|
@@ -3579,16 +3670,6 @@ const TestFrameWorkComponentWebView = {
|
|
|
3579
3670
|
fromId
|
|
3580
3671
|
};
|
|
3581
3672
|
|
|
3582
|
-
const toFileUrl = url => {
|
|
3583
|
-
const urlObject = new URL(url);
|
|
3584
|
-
const pathName = urlObject.pathname;
|
|
3585
|
-
if (!pathName.startsWith('/remote')) {
|
|
3586
|
-
throw new Error(`url must start with /remote`);
|
|
3587
|
-
}
|
|
3588
|
-
const rest = pathName.slice('/remote'.length);
|
|
3589
|
-
return `file://${rest}`;
|
|
3590
|
-
};
|
|
3591
|
-
|
|
3592
3673
|
const setPath = async path => {
|
|
3593
3674
|
await invoke$1('Workspace.setPath', path);
|
|
3594
3675
|
};
|
|
@@ -3597,13 +3678,13 @@ const openTmpDir = async () => {
|
|
|
3597
3678
|
await setPath(tmpDir);
|
|
3598
3679
|
return tmpDir;
|
|
3599
3680
|
};
|
|
3681
|
+
|
|
3682
|
+
/**
|
|
3683
|
+
* @deprecated use FileSystem.loadFixture instead
|
|
3684
|
+
*/
|
|
3600
3685
|
const resolveFileUrl = url => {
|
|
3601
|
-
// TODO in web, convert to memfs or fetch url
|
|
3602
|
-
// TODO on web: read filemap for that fixture
|
|
3603
|
-
// else, use filesystem to read the files
|
|
3604
3686
|
// TODO covert remote url to file url
|
|
3605
3687
|
// then set that as workspace path
|
|
3606
|
-
|
|
3607
3688
|
return toFileUrl(url);
|
|
3608
3689
|
};
|
|
3609
3690
|
|
|
@@ -3627,6 +3708,7 @@ const TestFrameWorkComponent = {
|
|
|
3627
3708
|
Editor: TestFrameWorkComponentEditor,
|
|
3628
3709
|
EditorCompletion: TestFrameWorkComponentEditorCompletion,
|
|
3629
3710
|
EditorHover: TestFrameWorkComponentEditorHover,
|
|
3711
|
+
EditorRename: TestFrameWorkComponentEditorRename,
|
|
3630
3712
|
EditorSourceAction: TestFrameWorkComponentEditorSourceAction,
|
|
3631
3713
|
Explorer: TestFrameWorkComponentExplorer,
|
|
3632
3714
|
Extension: TestFrameWorkComponentExtension,
|
|
@@ -3701,7 +3783,19 @@ const commandMap = {
|
|
|
3701
3783
|
'Test.executeMock': executeMock
|
|
3702
3784
|
};
|
|
3703
3785
|
|
|
3786
|
+
const send = async port => {
|
|
3787
|
+
await sendMessagePortToEditorWorker(port, TestWorker);
|
|
3788
|
+
};
|
|
3789
|
+
const launchEditorWorkerRpc = async () => {
|
|
3790
|
+
const rpc = await TransferMessagePortRpcParent.create({
|
|
3791
|
+
commandMap: {},
|
|
3792
|
+
send
|
|
3793
|
+
});
|
|
3794
|
+
return rpc;
|
|
3795
|
+
};
|
|
3796
|
+
|
|
3704
3797
|
const listen = async () => {
|
|
3798
|
+
setFactory(launchEditorWorkerRpc);
|
|
3705
3799
|
const rpc = await WebWorkerRpcClient.create({
|
|
3706
3800
|
commandMap: commandMap
|
|
3707
3801
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/test-worker",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.0",
|
|
4
4
|
"description": "Test Worker",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,5 +10,8 @@
|
|
|
10
10
|
"author": "Lvce Editor",
|
|
11
11
|
"type": "module",
|
|
12
12
|
"main": "dist/testWorkerMain.js",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@lvce-editor/constants": "^1.24.0"
|
|
15
|
+
},
|
|
13
16
|
"types": "dist/api.d.ts"
|
|
14
17
|
}
|