@lvce-editor/test-worker 7.1.0 → 7.3.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 +14 -0
- package/dist/testWorkerMain.js +158 -79
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -46,6 +46,15 @@ interface LocatorConstructor {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
|
|
49
|
+
export interface Diagnostic {
|
|
50
|
+
readonly rowIndex: number;
|
|
51
|
+
readonly columnIndex: number;
|
|
52
|
+
readonly endRowIndex: number;
|
|
53
|
+
readonly endColumnIndex: number;
|
|
54
|
+
readonly message: string;
|
|
55
|
+
readonly type: "error" | "warning";
|
|
56
|
+
}
|
|
57
|
+
|
|
49
58
|
export interface DroppedFileHandle {
|
|
50
59
|
readonly id: number;
|
|
51
60
|
readonly file: File;
|
|
@@ -168,6 +177,7 @@ interface Editor {
|
|
|
168
177
|
readonly setCursor: (rowIndex: number, columnIndex: number) => Promise<void>;
|
|
169
178
|
readonly setDeltaY: (deltaY: number) => Promise<void>;
|
|
170
179
|
readonly setSelections: (selections: any) => Promise<void>;
|
|
180
|
+
readonly shouldHaveDiagnostics: (expectedDiagnostics: readonly Diagnostic[]) => Promise<void>;
|
|
171
181
|
readonly shouldHaveSelections: (expectedSelections: Uint32Array) => Promise<void>;
|
|
172
182
|
readonly shouldHaveText: (expectedText: string) => Promise<void>;
|
|
173
183
|
readonly showHover: () => Promise<void>;
|
|
@@ -182,6 +192,7 @@ interface Editor {
|
|
|
182
192
|
|
|
183
193
|
interface EditorCompletion {
|
|
184
194
|
readonly close: () => Promise<void>;
|
|
195
|
+
readonly handlePointerdown: (clientX: number, clientY: number) => Promise<void>;
|
|
185
196
|
readonly handleWheel: (deltaMode: number, deltaY: number) => Promise<void>;
|
|
186
197
|
readonly selectCurrentIndex: () => Promise<void>;
|
|
187
198
|
readonly selectIndex: (index: number) => Promise<void>;
|
|
@@ -276,6 +287,7 @@ interface FileSystem {
|
|
|
276
287
|
readonly getTmpDir: ({ scheme }?: FileSystemTmpDirOptions) => Promise<string>;
|
|
277
288
|
readonly loadFixture: (url: string) => Promise<string>;
|
|
278
289
|
readonly mkdir: (uri: string) => Promise<void>;
|
|
290
|
+
readonly readDir: (uri: string) => Promise<void>;
|
|
279
291
|
readonly readFile: (uri: string) => Promise<string>;
|
|
280
292
|
readonly remove: (uri: string) => Promise<void>;
|
|
281
293
|
readonly writeFile: (uri: string, content: string) => Promise<void>;
|
|
@@ -449,6 +461,8 @@ interface Search {
|
|
|
449
461
|
}
|
|
450
462
|
|
|
451
463
|
interface Settings {
|
|
464
|
+
readonly disableDiagnostics: () => Promise<void>;
|
|
465
|
+
readonly enableDiagnostics: () => Promise<void>;
|
|
452
466
|
readonly update: (settings: any) => Promise<void>;
|
|
453
467
|
}
|
|
454
468
|
|
package/dist/testWorkerMain.js
CHANGED
|
@@ -1034,6 +1034,8 @@ const WebWorkerRpcClient = {
|
|
|
1034
1034
|
create: create$2
|
|
1035
1035
|
};
|
|
1036
1036
|
|
|
1037
|
+
const Directory = 3;
|
|
1038
|
+
|
|
1037
1039
|
const Web = 1;
|
|
1038
1040
|
const Electron = 2;
|
|
1039
1041
|
const Remote = 3;
|
|
@@ -1109,6 +1111,42 @@ const createLazyRpc = rpcId => {
|
|
|
1109
1111
|
};
|
|
1110
1112
|
};
|
|
1111
1113
|
|
|
1114
|
+
// @ts-nocheck
|
|
1115
|
+
|
|
1116
|
+
const getPlatform = () => {
|
|
1117
|
+
// @ts-expect-error
|
|
1118
|
+
if (typeof PLATFORM !== 'undefined') {
|
|
1119
|
+
// @ts-expect-error
|
|
1120
|
+
return PLATFORM;
|
|
1121
|
+
}
|
|
1122
|
+
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
|
|
1123
|
+
return 'test';
|
|
1124
|
+
}
|
|
1125
|
+
// Check if running in web environment
|
|
1126
|
+
if (globalThis.window !== undefined && typeof document !== 'undefined') {
|
|
1127
|
+
return Web;
|
|
1128
|
+
}
|
|
1129
|
+
// TODO find a better way to pass runtime environment
|
|
1130
|
+
if (typeof name !== 'undefined' && name.endsWith('(Electron)')) {
|
|
1131
|
+
return Electron;
|
|
1132
|
+
}
|
|
1133
|
+
return Remote;
|
|
1134
|
+
};
|
|
1135
|
+
const platform = getPlatform(); // TODO tree-shake this out in production
|
|
1136
|
+
|
|
1137
|
+
const getAssetDir = () => {
|
|
1138
|
+
// @ts-expect-error
|
|
1139
|
+
if (typeof ASSET_DIR !== 'undefined') {
|
|
1140
|
+
// @ts-expect-error
|
|
1141
|
+
return ASSET_DIR;
|
|
1142
|
+
}
|
|
1143
|
+
if (platform === Electron) {
|
|
1144
|
+
return '../../../../..';
|
|
1145
|
+
}
|
|
1146
|
+
return '';
|
|
1147
|
+
};
|
|
1148
|
+
const assetDir = getAssetDir();
|
|
1149
|
+
|
|
1112
1150
|
class AssertionError extends Error {
|
|
1113
1151
|
constructor(message) {
|
|
1114
1152
|
super(message);
|
|
@@ -1619,42 +1657,6 @@ const ActivityBar = {
|
|
|
1619
1657
|
selectCurrent
|
|
1620
1658
|
};
|
|
1621
1659
|
|
|
1622
|
-
// @ts-nocheck
|
|
1623
|
-
|
|
1624
|
-
const getPlatform = () => {
|
|
1625
|
-
// @ts-expect-error
|
|
1626
|
-
if (typeof PLATFORM !== 'undefined') {
|
|
1627
|
-
// @ts-expect-error
|
|
1628
|
-
return PLATFORM;
|
|
1629
|
-
}
|
|
1630
|
-
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
|
|
1631
|
-
return 'test';
|
|
1632
|
-
}
|
|
1633
|
-
// Check if running in web environment
|
|
1634
|
-
if (globalThis.window !== undefined && typeof document !== 'undefined') {
|
|
1635
|
-
return Web;
|
|
1636
|
-
}
|
|
1637
|
-
// TODO find a better way to pass runtime environment
|
|
1638
|
-
if (typeof name !== 'undefined' && name.endsWith('(Electron)')) {
|
|
1639
|
-
return Electron;
|
|
1640
|
-
}
|
|
1641
|
-
return Remote;
|
|
1642
|
-
};
|
|
1643
|
-
const platform = getPlatform(); // TODO tree-shake this out in production
|
|
1644
|
-
|
|
1645
|
-
const getAssetDir = () => {
|
|
1646
|
-
// @ts-expect-error
|
|
1647
|
-
if (typeof ASSET_DIR !== 'undefined') {
|
|
1648
|
-
// @ts-expect-error
|
|
1649
|
-
return ASSET_DIR;
|
|
1650
|
-
}
|
|
1651
|
-
if (platform === Electron) {
|
|
1652
|
-
return '../../../../..';
|
|
1653
|
-
}
|
|
1654
|
-
return '';
|
|
1655
|
-
};
|
|
1656
|
-
const assetDir = getAssetDir();
|
|
1657
|
-
|
|
1658
1660
|
const getBaseUrl = () => {
|
|
1659
1661
|
return `${location.origin}/${assetDir}`;
|
|
1660
1662
|
};
|
|
@@ -1807,6 +1809,22 @@ const Dialog = {
|
|
|
1807
1809
|
showSaveFilePicker
|
|
1808
1810
|
};
|
|
1809
1811
|
|
|
1812
|
+
const isDiagnosticEqual = (actual, expected) => {
|
|
1813
|
+
return actual.rowIndex === expected.rowIndex && actual.columnIndex === expected.columnIndex && actual.endRowIndex === expected.endRowIndex && actual.endColumnIndex === expected.endColumnIndex && actual.message === expected.message && actual.type === expected.type;
|
|
1814
|
+
};
|
|
1815
|
+
|
|
1816
|
+
const areDiagnosticsEqual = (actual, expected) => {
|
|
1817
|
+
if (actual.length !== expected.length) {
|
|
1818
|
+
return false;
|
|
1819
|
+
}
|
|
1820
|
+
for (let i = 0; i < actual.length; i++) {
|
|
1821
|
+
if (!isDiagnosticEqual(actual[i], expected[i])) {
|
|
1822
|
+
return false;
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
return true;
|
|
1826
|
+
};
|
|
1827
|
+
|
|
1810
1828
|
const areSelectionsEqual = (a, b) => {
|
|
1811
1829
|
if (a.length !== b.length) {
|
|
1812
1830
|
return false;
|
|
@@ -1819,10 +1837,21 @@ const areSelectionsEqual = (a, b) => {
|
|
|
1819
1837
|
return true;
|
|
1820
1838
|
};
|
|
1821
1839
|
|
|
1840
|
+
const lazyRpc = createLazyRpc(EditorWorker);
|
|
1822
1841
|
const {
|
|
1823
1842
|
invoke,
|
|
1824
1843
|
setFactory
|
|
1825
|
-
} =
|
|
1844
|
+
} = lazyRpc;
|
|
1845
|
+
|
|
1846
|
+
const getEditorKey = async () => {
|
|
1847
|
+
const keys = await invoke('Editor.getKeys');
|
|
1848
|
+
if (keys.length === 0) {
|
|
1849
|
+
throw new Error(`no editor found`);
|
|
1850
|
+
}
|
|
1851
|
+
const key = keys.at(-1);
|
|
1852
|
+
const numeric = Number.parseInt(key);
|
|
1853
|
+
return numeric;
|
|
1854
|
+
};
|
|
1826
1855
|
|
|
1827
1856
|
const Script = 2;
|
|
1828
1857
|
|
|
@@ -2003,30 +2032,19 @@ const growSelection = async () => {
|
|
|
2003
2032
|
await invoke$1('Editor.selectionGrow');
|
|
2004
2033
|
};
|
|
2005
2034
|
const getSelections = async () => {
|
|
2006
|
-
const
|
|
2007
|
-
const key = keys.at(-1);
|
|
2008
|
-
const numeric = Number.parseInt(key);
|
|
2035
|
+
const key = await getEditorKey();
|
|
2009
2036
|
// @ts-ignore
|
|
2010
|
-
return invoke('Editor.getSelections',
|
|
2011
|
-
};
|
|
2012
|
-
const getKey = async () => {
|
|
2013
|
-
const keys = await invoke('Editor.getKeys');
|
|
2014
|
-
if (keys.length === 0) {
|
|
2015
|
-
throw new Error(`no editor found`);
|
|
2016
|
-
}
|
|
2017
|
-
const key = keys.at(-1);
|
|
2018
|
-
const numeric = Number.parseInt(key);
|
|
2019
|
-
return numeric;
|
|
2037
|
+
return invoke('Editor.getSelections', key);
|
|
2020
2038
|
};
|
|
2021
2039
|
const shouldHaveText = async expectedText => {
|
|
2022
|
-
const key = await
|
|
2040
|
+
const key = await getEditorKey();
|
|
2023
2041
|
const text = await invoke('Editor.getText', key);
|
|
2024
2042
|
if (text !== expectedText) {
|
|
2025
2043
|
throw new Error(`Expected editor to have text ${expectedText} but was ${text}`);
|
|
2026
2044
|
}
|
|
2027
2045
|
};
|
|
2028
2046
|
const shouldHaveSelections = async expectedSelections => {
|
|
2029
|
-
const key = await
|
|
2047
|
+
const key = await getEditorKey();
|
|
2030
2048
|
const selections = await invoke('Editor.getSelections', key);
|
|
2031
2049
|
if (!areSelectionsEqual(selections, expectedSelections)) {
|
|
2032
2050
|
throw new Error(`Expected editor to have selections ${expectedSelections} but was ${selections}`);
|
|
@@ -2040,6 +2058,15 @@ const redo = async () => {
|
|
|
2040
2058
|
// @ts-ignore
|
|
2041
2059
|
await invoke('Editor.redo');
|
|
2042
2060
|
};
|
|
2061
|
+
const shouldHaveDiagnostics = async expectedDiagnostics => {
|
|
2062
|
+
const key = await getEditorKey();
|
|
2063
|
+
const diagnostics = await invoke('Editor.getDiagnostics', key);
|
|
2064
|
+
if (!areDiagnosticsEqual(diagnostics, expectedDiagnostics)) {
|
|
2065
|
+
const stringifiedActual = JSON.stringify(diagnostics);
|
|
2066
|
+
const stringifiedExpected = JSON.stringify(expectedDiagnostics);
|
|
2067
|
+
throw new Error(`Expected editor to have diagnostics ${stringifiedActual} but was ${stringifiedExpected}`);
|
|
2068
|
+
}
|
|
2069
|
+
};
|
|
2043
2070
|
|
|
2044
2071
|
const Editor = {
|
|
2045
2072
|
__proto__: null,
|
|
@@ -2092,6 +2119,7 @@ const Editor = {
|
|
|
2092
2119
|
setCursor,
|
|
2093
2120
|
setDeltaY,
|
|
2094
2121
|
setSelections,
|
|
2122
|
+
shouldHaveDiagnostics,
|
|
2095
2123
|
shouldHaveSelections,
|
|
2096
2124
|
shouldHaveText,
|
|
2097
2125
|
showHover,
|
|
@@ -2118,10 +2146,15 @@ const handleWheel$2 = async (deltaMode, deltaY) => {
|
|
|
2118
2146
|
// @ts-ignore
|
|
2119
2147
|
await invoke$1('EditorCompletion.handleWheel', deltaMode, deltaY);
|
|
2120
2148
|
};
|
|
2149
|
+
const handlePointerdown = async (clientX, clientY) => {
|
|
2150
|
+
// @ts-ignore
|
|
2151
|
+
await invoke$1('EditorCompletion.handlePointerdown', clientX, clientY);
|
|
2152
|
+
};
|
|
2121
2153
|
|
|
2122
2154
|
const EditorCompletion = {
|
|
2123
2155
|
__proto__: null,
|
|
2124
2156
|
close: close$2,
|
|
2157
|
+
handlePointerdown,
|
|
2125
2158
|
handleWheel: handleWheel$2,
|
|
2126
2159
|
selectCurrentIndex: selectCurrentIndex$2,
|
|
2127
2160
|
selectIndex: selectIndex$6
|
|
@@ -2439,6 +2472,40 @@ const ExtensionDetail = {
|
|
|
2439
2472
|
|
|
2440
2473
|
const Memfs = 'memfs';
|
|
2441
2474
|
|
|
2475
|
+
const toFileUrl = url => {
|
|
2476
|
+
const urlObject = new URL(url);
|
|
2477
|
+
const pathName = urlObject.pathname;
|
|
2478
|
+
if (!pathName.startsWith('/remote')) {
|
|
2479
|
+
throw new Error(`url must start with /remote`);
|
|
2480
|
+
}
|
|
2481
|
+
const rest = pathName.slice('/remote'.length);
|
|
2482
|
+
return `file://${rest}`;
|
|
2483
|
+
};
|
|
2484
|
+
|
|
2485
|
+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
|
|
2486
|
+
const getDirents = async (allDirents, fileUrl) => {
|
|
2487
|
+
const dirents = await invoke$1('FileSystem.readDirWithFileTypes', fileUrl);
|
|
2488
|
+
for (const dirent of dirents) {
|
|
2489
|
+
if (dirent.type === Directory) {
|
|
2490
|
+
await getDirents(allDirents, `${fileUrl}/${dirent.name}`);
|
|
2491
|
+
} else {
|
|
2492
|
+
allDirents.push(`${fileUrl}/${dirent.name}`);
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
};
|
|
2496
|
+
const getFileMapNode = async url => {
|
|
2497
|
+
const fileUrl = toFileUrl(url);
|
|
2498
|
+
const allFiles = [];
|
|
2499
|
+
await getDirents(allFiles, fileUrl);
|
|
2500
|
+
const fileMap = Object.create(null);
|
|
2501
|
+
for (const filePath of allFiles) {
|
|
2502
|
+
const content = await invoke$1(`FileSystem.readFile`, filePath);
|
|
2503
|
+
const relativePaths = filePath.slice(fileUrl.length + 1);
|
|
2504
|
+
fileMap[relativePaths] = content;
|
|
2505
|
+
}
|
|
2506
|
+
return fileMap;
|
|
2507
|
+
};
|
|
2508
|
+
|
|
2442
2509
|
const isObject = value => {
|
|
2443
2510
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
2444
2511
|
};
|
|
@@ -2470,6 +2537,12 @@ const loadFileMap = async fileMapUrl => {
|
|
|
2470
2537
|
}
|
|
2471
2538
|
};
|
|
2472
2539
|
|
|
2540
|
+
const getFileMapWeb = async url => {
|
|
2541
|
+
const fileMapUrl = `${url}/fileMap.json`;
|
|
2542
|
+
const fileMap = await loadFileMap(fileMapUrl);
|
|
2543
|
+
return fileMap;
|
|
2544
|
+
};
|
|
2545
|
+
|
|
2473
2546
|
const Backslash = '\\';
|
|
2474
2547
|
const Slash$1 = '/';
|
|
2475
2548
|
|
|
@@ -2487,16 +2560,6 @@ const stringifyJson = data => {
|
|
|
2487
2560
|
return JSON.stringify(data, null, 2) + '\n';
|
|
2488
2561
|
};
|
|
2489
2562
|
|
|
2490
|
-
const toFileUrl = url => {
|
|
2491
|
-
const urlObject = new URL(url);
|
|
2492
|
-
const pathName = urlObject.pathname;
|
|
2493
|
-
if (!pathName.startsWith('/remote')) {
|
|
2494
|
-
throw new Error(`url must start with /remote`);
|
|
2495
|
-
}
|
|
2496
|
-
const rest = pathName.slice('/remote'.length);
|
|
2497
|
-
return `file://${rest}`;
|
|
2498
|
-
};
|
|
2499
|
-
|
|
2500
2563
|
const writeFile = async (uri, content) => {
|
|
2501
2564
|
await invoke$1('FileSystem.writeFile', uri, content);
|
|
2502
2565
|
};
|
|
@@ -2510,6 +2573,10 @@ const readFile = async uri => {
|
|
|
2510
2573
|
const mkdir = async uri => {
|
|
2511
2574
|
await invoke$1('FileSystem.mkdir', uri);
|
|
2512
2575
|
};
|
|
2576
|
+
const readDir = async uri => {
|
|
2577
|
+
// @ts-ignore
|
|
2578
|
+
return invoke$1('FileSystem.readDirWithFileTypes', uri);
|
|
2579
|
+
};
|
|
2513
2580
|
const remove = async uri => {
|
|
2514
2581
|
await invoke$1('FileSystem.remove', uri);
|
|
2515
2582
|
};
|
|
@@ -2565,20 +2632,12 @@ const loadFixture = async (platform, url) => {
|
|
|
2565
2632
|
if (typeof url !== 'string') {
|
|
2566
2633
|
throw new TypeError(`fixture url must be of type string`);
|
|
2567
2634
|
}
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
for (const [key, value] of Object.entries(fileMap)) {
|
|
2573
|
-
await writeFile(`memfs:///${key}`, value);
|
|
2574
|
-
}
|
|
2575
|
-
return 'memfs:///';
|
|
2635
|
+
const fn = platform === Web ? getFileMapWeb : getFileMapNode;
|
|
2636
|
+
const fileMap = await fn(url);
|
|
2637
|
+
for (const [key, value] of Object.entries(fileMap)) {
|
|
2638
|
+
await writeFile(`memfs:///${key}`, value);
|
|
2576
2639
|
}
|
|
2577
|
-
|
|
2578
|
-
// TODO maybe also create a memory file system for consistency with web
|
|
2579
|
-
// TODO covert remote url to file url
|
|
2580
|
-
// then set that as workspace path
|
|
2581
|
-
return toFileUrl(url);
|
|
2640
|
+
return 'memfs://';
|
|
2582
2641
|
};
|
|
2583
2642
|
|
|
2584
2643
|
const FileSystem = {
|
|
@@ -2590,6 +2649,7 @@ const FileSystem = {
|
|
|
2590
2649
|
getTmpDir,
|
|
2591
2650
|
loadFixture,
|
|
2592
2651
|
mkdir,
|
|
2652
|
+
readDir,
|
|
2593
2653
|
readFile,
|
|
2594
2654
|
remove,
|
|
2595
2655
|
writeFile,
|
|
@@ -3297,9 +3357,23 @@ const update$1 = settings => {
|
|
|
3297
3357
|
// @ts-ignore
|
|
3298
3358
|
return invoke$1('Preferences.update', settings);
|
|
3299
3359
|
};
|
|
3360
|
+
const enableDiagnostics = () => {
|
|
3361
|
+
// @ts-ignore
|
|
3362
|
+
return invoke$1('Preferences.update', {
|
|
3363
|
+
'editor.diagnostics': true
|
|
3364
|
+
});
|
|
3365
|
+
};
|
|
3366
|
+
const disableDiagnostics = () => {
|
|
3367
|
+
// @ts-ignore
|
|
3368
|
+
return invoke$1('Preferences.update', {
|
|
3369
|
+
'editor.diagnostics': false
|
|
3370
|
+
});
|
|
3371
|
+
};
|
|
3300
3372
|
|
|
3301
3373
|
const Settings = {
|
|
3302
3374
|
__proto__: null,
|
|
3375
|
+
disableDiagnostics,
|
|
3376
|
+
enableDiagnostics,
|
|
3303
3377
|
update: update$1
|
|
3304
3378
|
};
|
|
3305
3379
|
|
|
@@ -3577,11 +3651,16 @@ const Workspace = {
|
|
|
3577
3651
|
setPath
|
|
3578
3652
|
};
|
|
3579
3653
|
|
|
3580
|
-
const createApi = platform => {
|
|
3654
|
+
const createApi = (platform, assetDir$1) => {
|
|
3581
3655
|
return {
|
|
3582
3656
|
About,
|
|
3583
3657
|
ActivityBar,
|
|
3584
|
-
BaseUrl
|
|
3658
|
+
BaseUrl: {
|
|
3659
|
+
...BaseUrl,
|
|
3660
|
+
getBaseUrl() {
|
|
3661
|
+
return assetDir$1 || assetDir;
|
|
3662
|
+
}
|
|
3663
|
+
},
|
|
3585
3664
|
ClipBoard,
|
|
3586
3665
|
Command,
|
|
3587
3666
|
ContextMenu,
|
|
@@ -3738,8 +3817,8 @@ const importTest = async url => {
|
|
|
3738
3817
|
// 1. import test module
|
|
3739
3818
|
// 2. execute test
|
|
3740
3819
|
// 3. print out results
|
|
3741
|
-
const execute = async (href, platform) => {
|
|
3742
|
-
const globals = createApi(platform);
|
|
3820
|
+
const execute = async (href, platform, assetDir) => {
|
|
3821
|
+
const globals = createApi(platform, assetDir);
|
|
3743
3822
|
// TODO
|
|
3744
3823
|
// 0. wait for page to be ready
|
|
3745
3824
|
// 1. get script to import from renderer process (url or from html)
|