@lvce-editor/test-worker 7.0.0 → 7.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/api.d.ts +1 -0
- package/dist/testWorkerMain.js +97 -63
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -276,6 +276,7 @@ interface FileSystem {
|
|
|
276
276
|
readonly getTmpDir: ({ scheme }?: FileSystemTmpDirOptions) => Promise<string>;
|
|
277
277
|
readonly loadFixture: (url: string) => Promise<string>;
|
|
278
278
|
readonly mkdir: (uri: string) => Promise<void>;
|
|
279
|
+
readonly readDir: (uri: string) => Promise<void>;
|
|
279
280
|
readonly readFile: (uri: string) => Promise<string>;
|
|
280
281
|
readonly remove: (uri: string) => Promise<void>;
|
|
281
282
|
readonly writeFile: (uri: string, content: string) => Promise<void>;
|
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
|
};
|
|
@@ -2439,6 +2441,40 @@ const ExtensionDetail = {
|
|
|
2439
2441
|
|
|
2440
2442
|
const Memfs = 'memfs';
|
|
2441
2443
|
|
|
2444
|
+
const toFileUrl = url => {
|
|
2445
|
+
const urlObject = new URL(url);
|
|
2446
|
+
const pathName = urlObject.pathname;
|
|
2447
|
+
if (!pathName.startsWith('/remote')) {
|
|
2448
|
+
throw new Error(`url must start with /remote`);
|
|
2449
|
+
}
|
|
2450
|
+
const rest = pathName.slice('/remote'.length);
|
|
2451
|
+
return `file://${rest}`;
|
|
2452
|
+
};
|
|
2453
|
+
|
|
2454
|
+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
|
|
2455
|
+
const getDirents = async (allDirents, fileUrl) => {
|
|
2456
|
+
const dirents = await invoke$1('FileSystem.readDirWithFileTypes', fileUrl);
|
|
2457
|
+
for (const dirent of dirents) {
|
|
2458
|
+
if (dirent.type === Directory) {
|
|
2459
|
+
await getDirents(allDirents, `${fileUrl}/${dirent.name}`);
|
|
2460
|
+
} else {
|
|
2461
|
+
allDirents.push(`${fileUrl}/${dirent.name}`);
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
};
|
|
2465
|
+
const getFileMapNode = async url => {
|
|
2466
|
+
const fileUrl = toFileUrl(url);
|
|
2467
|
+
const allFiles = [];
|
|
2468
|
+
await getDirents(allFiles, fileUrl);
|
|
2469
|
+
const fileMap = Object.create(null);
|
|
2470
|
+
for (const filePath of allFiles) {
|
|
2471
|
+
const content = await invoke$1(`FileSystem.readFile`, filePath);
|
|
2472
|
+
const relativePaths = filePath.slice(fileUrl.length + 1);
|
|
2473
|
+
fileMap[relativePaths] = content;
|
|
2474
|
+
}
|
|
2475
|
+
return fileMap;
|
|
2476
|
+
};
|
|
2477
|
+
|
|
2442
2478
|
const isObject = value => {
|
|
2443
2479
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
2444
2480
|
};
|
|
@@ -2470,6 +2506,12 @@ const loadFileMap = async fileMapUrl => {
|
|
|
2470
2506
|
}
|
|
2471
2507
|
};
|
|
2472
2508
|
|
|
2509
|
+
const getFileMapWeb = async url => {
|
|
2510
|
+
const fileMapUrl = `${url}/fileMap.json`;
|
|
2511
|
+
const fileMap = await loadFileMap(fileMapUrl);
|
|
2512
|
+
return fileMap;
|
|
2513
|
+
};
|
|
2514
|
+
|
|
2473
2515
|
const Backslash = '\\';
|
|
2474
2516
|
const Slash$1 = '/';
|
|
2475
2517
|
|
|
@@ -2487,16 +2529,6 @@ const stringifyJson = data => {
|
|
|
2487
2529
|
return JSON.stringify(data, null, 2) + '\n';
|
|
2488
2530
|
};
|
|
2489
2531
|
|
|
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
2532
|
const writeFile = async (uri, content) => {
|
|
2501
2533
|
await invoke$1('FileSystem.writeFile', uri, content);
|
|
2502
2534
|
};
|
|
@@ -2510,6 +2542,10 @@ const readFile = async uri => {
|
|
|
2510
2542
|
const mkdir = async uri => {
|
|
2511
2543
|
await invoke$1('FileSystem.mkdir', uri);
|
|
2512
2544
|
};
|
|
2545
|
+
const readDir = async uri => {
|
|
2546
|
+
// @ts-ignore
|
|
2547
|
+
return invoke$1('FileSystem.readDirWithFileTypes', uri);
|
|
2548
|
+
};
|
|
2513
2549
|
const remove = async uri => {
|
|
2514
2550
|
await invoke$1('FileSystem.remove', uri);
|
|
2515
2551
|
};
|
|
@@ -2565,20 +2601,12 @@ const loadFixture = async (platform, url) => {
|
|
|
2565
2601
|
if (typeof url !== 'string') {
|
|
2566
2602
|
throw new TypeError(`fixture url must be of type string`);
|
|
2567
2603
|
}
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
for (const [key, value] of Object.entries(fileMap)) {
|
|
2573
|
-
await writeFile(`memfs:///${key}`, value);
|
|
2574
|
-
}
|
|
2575
|
-
return 'memfs:///';
|
|
2604
|
+
const fn = platform === Web ? getFileMapWeb : getFileMapNode;
|
|
2605
|
+
const fileMap = await fn(url);
|
|
2606
|
+
for (const [key, value] of Object.entries(fileMap)) {
|
|
2607
|
+
await writeFile(`memfs:///${key}`, value);
|
|
2576
2608
|
}
|
|
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);
|
|
2609
|
+
return 'memfs://';
|
|
2582
2610
|
};
|
|
2583
2611
|
|
|
2584
2612
|
const FileSystem = {
|
|
@@ -2590,6 +2618,7 @@ const FileSystem = {
|
|
|
2590
2618
|
getTmpDir,
|
|
2591
2619
|
loadFixture,
|
|
2592
2620
|
mkdir,
|
|
2621
|
+
readDir,
|
|
2593
2622
|
readFile,
|
|
2594
2623
|
remove,
|
|
2595
2624
|
writeFile,
|
|
@@ -3577,11 +3606,16 @@ const Workspace = {
|
|
|
3577
3606
|
setPath
|
|
3578
3607
|
};
|
|
3579
3608
|
|
|
3580
|
-
const createApi = platform => {
|
|
3609
|
+
const createApi = (platform, assetDir$1) => {
|
|
3581
3610
|
return {
|
|
3582
3611
|
About,
|
|
3583
3612
|
ActivityBar,
|
|
3584
|
-
BaseUrl
|
|
3613
|
+
BaseUrl: {
|
|
3614
|
+
...BaseUrl,
|
|
3615
|
+
getBaseUrl() {
|
|
3616
|
+
return assetDir$1 || assetDir;
|
|
3617
|
+
}
|
|
3618
|
+
},
|
|
3585
3619
|
ClipBoard,
|
|
3586
3620
|
Command,
|
|
3587
3621
|
ContextMenu,
|
|
@@ -3738,8 +3772,8 @@ const importTest = async url => {
|
|
|
3738
3772
|
// 1. import test module
|
|
3739
3773
|
// 2. execute test
|
|
3740
3774
|
// 3. print out results
|
|
3741
|
-
const execute = async (href, platform) => {
|
|
3742
|
-
const globals = createApi(platform);
|
|
3775
|
+
const execute = async (href, platform, assetDir) => {
|
|
3776
|
+
const globals = createApi(platform, assetDir);
|
|
3743
3777
|
// TODO
|
|
3744
3778
|
// 0. wait for page to be ready
|
|
3745
3779
|
// 1. get script to import from renderer process (url or from html)
|