@lvce-editor/test-worker 6.4.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 CHANGED
@@ -275,6 +275,7 @@ interface FileSystem {
275
275
  readonly createExecutable: (content: string) => Promise<string>;
276
276
  readonly createExecutableFrom: (uri: string) => Promise<string>;
277
277
  readonly getTmpDir: ({ scheme }?: FileSystemTmpDirOptions) => Promise<string>;
278
+ readonly loadFixture: (platform: number, url: string) => Promise<string>;
278
279
  readonly mkdir: (uri: string) => Promise<void>;
279
280
  readonly readFile: (uri: string) => Promise<string>;
280
281
  readonly remove: (uri: string) => Promise<void>;
@@ -1034,6 +1034,10 @@ const WebWorkerRpcClient = {
1034
1034
  create: create$2
1035
1035
  };
1036
1036
 
1037
+ const Web = 1;
1038
+ const Electron = 2;
1039
+ const Remote = 3;
1040
+
1037
1041
  const EditorWorker = 99;
1038
1042
  const RendererWorker = 1;
1039
1043
  const TestWorker = 9001;
@@ -1726,9 +1730,6 @@ const TestFrameworkComponentActivityBar = {
1726
1730
  selectCurrent
1727
1731
  };
1728
1732
 
1729
- const Electron = 'electron';
1730
- const Remote = 'remote';
1731
-
1732
1733
  // @ts-nocheck
1733
1734
 
1734
1735
  const getPlatform = () => {
@@ -1740,6 +1741,10 @@ const getPlatform = () => {
1740
1741
  if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
1741
1742
  return 'test';
1742
1743
  }
1744
+ // Check if running in web environment
1745
+ if (globalThis.window !== undefined && typeof document !== 'undefined') {
1746
+ return Web;
1747
+ }
1743
1748
  // TODO find a better way to pass runtime environment
1744
1749
  if (typeof name !== 'undefined' && name.endsWith('(Electron)')) {
1745
1750
  return Electron;
@@ -2545,6 +2550,37 @@ const TestFrameWorkComponentExtensionDetail = {
2545
2550
 
2546
2551
  const Memfs = 'memfs';
2547
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
+
2548
2584
  const Backslash = '\\';
2549
2585
  const Slash$1 = '/';
2550
2586
 
@@ -2562,6 +2598,16 @@ const stringifyJson = data => {
2562
2598
  return JSON.stringify(data, null, 2) + '\n';
2563
2599
  };
2564
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
+
2565
2611
  const writeFile = async (uri, content) => {
2566
2612
  await invoke$1('FileSystem.writeFile', uri, content);
2567
2613
  };
@@ -2626,6 +2672,22 @@ const createDroppedFileHandle = async () => {
2626
2672
  id
2627
2673
  };
2628
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
+ };
2629
2691
 
2630
2692
  const TestFrameWorkComponentFileSystem = {
2631
2693
  __proto__: null,
@@ -2634,6 +2696,7 @@ const TestFrameWorkComponentFileSystem = {
2634
2696
  createExecutable,
2635
2697
  createExecutableFrom,
2636
2698
  getTmpDir,
2699
+ loadFixture,
2637
2700
  mkdir,
2638
2701
  readFile,
2639
2702
  remove,
@@ -3607,16 +3670,6 @@ const TestFrameWorkComponentWebView = {
3607
3670
  fromId
3608
3671
  };
3609
3672
 
3610
- const toFileUrl = url => {
3611
- const urlObject = new URL(url);
3612
- const pathName = urlObject.pathname;
3613
- if (!pathName.startsWith('/remote')) {
3614
- throw new Error(`url must start with /remote`);
3615
- }
3616
- const rest = pathName.slice('/remote'.length);
3617
- return `file://${rest}`;
3618
- };
3619
-
3620
3673
  const setPath = async path => {
3621
3674
  await invoke$1('Workspace.setPath', path);
3622
3675
  };
@@ -3625,13 +3678,13 @@ const openTmpDir = async () => {
3625
3678
  await setPath(tmpDir);
3626
3679
  return tmpDir;
3627
3680
  };
3681
+
3682
+ /**
3683
+ * @deprecated use FileSystem.loadFixture instead
3684
+ */
3628
3685
  const resolveFileUrl = url => {
3629
- // TODO in web, convert to memfs or fetch url
3630
- // TODO on web: read filemap for that fixture
3631
- // else, use filesystem to read the files
3632
3686
  // TODO covert remote url to file url
3633
3687
  // then set that as workspace path
3634
-
3635
3688
  return toFileUrl(url);
3636
3689
  };
3637
3690
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/test-worker",
3
- "version": "6.4.0",
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
  }