@lvce-editor/test-worker 6.6.0 → 6.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/api.d.ts CHANGED
@@ -275,7 +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
+ readonly loadFixture: (url: string) => Promise<string>;
279
279
  readonly mkdir: (uri: string) => Promise<void>;
280
280
  readonly readFile: (uri: string) => Promise<string>;
281
281
  readonly remove: (uri: string) => Promise<void>;
@@ -1109,109 +1109,6 @@ const createLazyRpc = rpcId => {
1109
1109
  };
1110
1110
  };
1111
1111
 
1112
- const callFunction = async (fn, args) => {
1113
- try {
1114
- await fn(args);
1115
- return undefined;
1116
- } catch (error) {
1117
- return error;
1118
- }
1119
- };
1120
-
1121
- const formatDuration = duration => {
1122
- return duration.toFixed(2) + 'ms';
1123
- };
1124
-
1125
- const Fail = 'fail';
1126
- const Pass = 'pass';
1127
-
1128
- const executeTest2 = async (name, fn, globals, timestampGenerator) => {
1129
- const getTimestamp = timestampGenerator;
1130
- const start = getTimestamp();
1131
- const error = await callFunction(fn, globals);
1132
- const end = getTimestamp();
1133
- const duration = end - start;
1134
- const formattedDuration = formatDuration(duration);
1135
- if (error) {
1136
- return {
1137
- error,
1138
- start,
1139
- end,
1140
- duration,
1141
- formattedDuration,
1142
- name,
1143
- type: Fail,
1144
- background: 'red',
1145
- text: `test failed: ${error}`
1146
- };
1147
- }
1148
- return {
1149
- error: undefined,
1150
- start,
1151
- end,
1152
- duration,
1153
- formattedDuration,
1154
- name,
1155
- type: Pass,
1156
- background: 'green',
1157
- text: `test passed in ${formattedDuration}`
1158
- };
1159
- };
1160
-
1161
- const printError = error => {
1162
- if (error && error.constructor.name === 'AssertionError') {
1163
- console.error(error.message);
1164
- } else {
1165
- console.error(error);
1166
- }
1167
- };
1168
-
1169
- const printTestError = async error => {
1170
- // TODO ask error worker to add codeframe
1171
- printError(error);
1172
- };
1173
-
1174
- const now = () => {
1175
- return performance.now();
1176
- };
1177
-
1178
- const executeTest = async (name, fn, globals = {}) => {
1179
- const {
1180
- error,
1181
- formattedDuration,
1182
- background,
1183
- text,
1184
- type
1185
- } = await executeTest2(name, fn, globals, now);
1186
- if (error) {
1187
- await printTestError(error);
1188
- } else {
1189
- // eslint-disable-next-line no-console
1190
- console.info(`PASS ${name} in ${formattedDuration}`);
1191
- }
1192
- // @ts-ignore
1193
- await invoke$1('TestFrameWork.showOverlay', type, background, text);
1194
- };
1195
-
1196
- const importScript = async url => {
1197
- try {
1198
- return await import(url);
1199
- } catch (error) {
1200
- throw error;
1201
- // TODO
1202
- // const actualErrorMessage = await TryToGetactualImportErrorMessage.tryToGetActualImportErrorMessage(url, error)
1203
- // throw new Error(actualErrorMessage)
1204
- }
1205
- };
1206
-
1207
- const importTest = async url => {
1208
- try {
1209
- return await importScript(url);
1210
- } catch (error) {
1211
- throw new VError(error, 'Failed to import test');
1212
- }
1213
- };
1214
-
1215
1112
  class AssertionError extends Error {
1216
1113
  constructor(message) {
1217
1114
  super(message);
@@ -1656,14 +1553,6 @@ const {
1656
1553
  expect
1657
1554
  } = Expect$1;
1658
1555
 
1659
- const TestFrameWork = {
1660
- __proto__: null,
1661
- Locator: create,
1662
- expect,
1663
- getTmpDir: getTmpDir$1,
1664
- test
1665
- };
1666
-
1667
1556
  const show$4 = async () => {
1668
1557
  return invoke$1('About.showAbout');
1669
1558
  };
@@ -1683,7 +1572,7 @@ const focusPrevious$8 = async () => {
1683
1572
  return invoke$1('About.focusPrevious');
1684
1573
  };
1685
1574
 
1686
- const TestFrameWorkComponentAbout = {
1575
+ const About = {
1687
1576
  __proto__: null,
1688
1577
  focusNext: focusNext$9,
1689
1578
  focusPrevious: focusPrevious$8,
@@ -1718,7 +1607,7 @@ const selectCurrent = async () => {
1718
1607
  await invoke$1('ActivityBar.selectCurrent');
1719
1608
  };
1720
1609
 
1721
- const TestFrameworkComponentActivityBar = {
1610
+ const ActivityBar = {
1722
1611
  __proto__: null,
1723
1612
  focus: focus$2,
1724
1613
  focusFirst: focusFirst$7,
@@ -1770,7 +1659,7 @@ const getBaseUrl = () => {
1770
1659
  return `${location.origin}/${assetDir}`;
1771
1660
  };
1772
1661
 
1773
- const TestFrameWorkComponentBaseUrl = {
1662
+ const BaseUrl = {
1774
1663
  __proto__: null,
1775
1664
  getBaseUrl
1776
1665
  };
@@ -1804,7 +1693,7 @@ const shouldHaveText$1 = async expectedText => {
1804
1693
  }
1805
1694
  };
1806
1695
 
1807
- const TestFrameworkComponentClipBoard = {
1696
+ const ClipBoard = {
1808
1697
  __proto__: null,
1809
1698
  disableMemoryClipBoard,
1810
1699
  enableMemoryClipBoard,
@@ -1818,7 +1707,7 @@ const execute$1 = async (id, ...args) => {
1818
1707
  return invoke$1(id, ...args);
1819
1708
  };
1820
1709
 
1821
- const TestFrameWorkComponentCommand = {
1710
+ const Command = {
1822
1711
  __proto__: null,
1823
1712
  execute: execute$1
1824
1713
  };
@@ -1827,7 +1716,7 @@ const selectItem$1 = async text => {
1827
1716
  await invoke$1('Menu.selectItem', text);
1828
1717
  };
1829
1718
 
1830
- const TestFrameWorkComponentContextMenu = {
1719
+ const ContextMenu = {
1831
1720
  __proto__: null,
1832
1721
  selectItem: selectItem$1
1833
1722
  };
@@ -1865,7 +1754,7 @@ const toggleDeveloperTools = async () => {
1865
1754
  return invoke$1('Developer.toggleDeveloperTools');
1866
1755
  };
1867
1756
 
1868
- const TestFrameWorkComponentDeveloper = {
1757
+ const Developer = {
1869
1758
  __proto__: null,
1870
1759
  openCacheFolder,
1871
1760
  openConfigFolder,
@@ -1910,7 +1799,7 @@ const executeMock = (id, ...args) => {
1910
1799
  return executeMock$1(id, ...args);
1911
1800
  };
1912
1801
 
1913
- const TestFrameWorkComponentDialog = {
1802
+ const Dialog = {
1914
1803
  __proto__: null,
1915
1804
  executeMock,
1916
1805
  mockConfirm,
@@ -2152,7 +2041,7 @@ const redo = async () => {
2152
2041
  await invoke('Editor.redo');
2153
2042
  };
2154
2043
 
2155
- const TestFrameWorkComponentEditor = {
2044
+ const Editor = {
2156
2045
  __proto__: null,
2157
2046
  addAllMissingImports,
2158
2047
  closeColorPicker,
@@ -2230,7 +2119,7 @@ const handleWheel$2 = async (deltaMode, deltaY) => {
2230
2119
  await invoke$1('EditorCompletion.handleWheel', deltaMode, deltaY);
2231
2120
  };
2232
2121
 
2233
- const TestFrameWorkComponentEditorCompletion = {
2122
+ const EditorCompletion = {
2234
2123
  __proto__: null,
2235
2124
  close: close$2,
2236
2125
  handleWheel: handleWheel$2,
@@ -2246,7 +2135,7 @@ const close$1 = async () => {
2246
2135
  await invoke$1('EditorHover.close');
2247
2136
  };
2248
2137
 
2249
- const TestFrameWorkComponentEditorHover = {
2138
+ const EditorHover = {
2250
2139
  __proto__: null,
2251
2140
  close: close$1,
2252
2141
  show: show$3
@@ -2265,7 +2154,7 @@ const cancel = async () => {
2265
2154
  await invoke$1('EditorRename.cancel');
2266
2155
  };
2267
2156
 
2268
- const TestFrameWorkComponentEditorRename = {
2157
+ const EditorRename = {
2269
2158
  __proto__: null,
2270
2159
  accept,
2271
2160
  cancel,
@@ -2281,7 +2170,7 @@ const selectCurrentIndex$1 = async () => {
2281
2170
  await invoke$1('EditorSourceAction.selectCurrentIndex');
2282
2171
  };
2283
2172
 
2284
- const TestFrameWorkComponentEditorSourceAction = {
2173
+ const EditorSourceAction = {
2285
2174
  __proto__: null,
2286
2175
  selectCurrentIndex: selectCurrentIndex$1,
2287
2176
  selectIndex: selectIndex$5
@@ -2407,7 +2296,7 @@ const toggleIndividualSelection = async index => {
2407
2296
  await invoke$1('Explorer.toggleIndividualSelection', index);
2408
2297
  };
2409
2298
 
2410
- const TestFrameWorkComponentExplorer = {
2299
+ const Explorer = {
2411
2300
  __proto__: null,
2412
2301
  acceptEdit,
2413
2302
  cancelEdit,
@@ -2458,7 +2347,7 @@ const addNodeExtension = async relativePath => {
2458
2347
  await invoke$1('ExtensionMeta.addNodeExtension', absolutePath);
2459
2348
  };
2460
2349
 
2461
- const TestFrameWorkComponentExtension = {
2350
+ const Extension = {
2462
2351
  __proto__: null,
2463
2352
  addNodeExtension,
2464
2353
  addWebExtension
@@ -2526,7 +2415,7 @@ const handleScroll$1 = async scrollTop => {
2526
2415
  return invoke$1('ExtensionDetail.handleScroll', scrollTop);
2527
2416
  };
2528
2417
 
2529
- const TestFrameWorkComponentExtensionDetail = {
2418
+ const ExtensionDetail = {
2530
2419
  __proto__: null,
2531
2420
  handleClickCategory,
2532
2421
  handleClickDisable,
@@ -2673,14 +2562,17 @@ const createDroppedFileHandle = async () => {
2673
2562
  };
2674
2563
  };
2675
2564
  const loadFixture = async (platform, url) => {
2565
+ if (typeof url !== 'string') {
2566
+ throw new TypeError(`fixture url must be of type string`);
2567
+ }
2676
2568
  // Handle fixture URLs in web environment
2677
2569
  if (platform === Web) {
2678
2570
  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 '';
2571
+ const fileMap = await loadFileMap(fileMapUrl);
2572
+ for (const [key, value] of Object.entries(fileMap)) {
2573
+ await writeFile(`memfs:///${key}`, value);
2574
+ }
2575
+ return 'memfs:///';
2684
2576
  }
2685
2577
 
2686
2578
  // TODO maybe also create a memory file system for consistency with web
@@ -2689,7 +2581,7 @@ const loadFixture = async (platform, url) => {
2689
2581
  return toFileUrl(url);
2690
2582
  };
2691
2583
 
2692
- const TestFrameWorkComponentFileSystem = {
2584
+ const FileSystem = {
2693
2585
  __proto__: null,
2694
2586
  chmod,
2695
2587
  createDroppedFileHandle,
@@ -2764,7 +2656,7 @@ const focusPreviousElement = async () => {
2764
2656
  await invoke$1('FindWidget.focusPreviousElement');
2765
2657
  };
2766
2658
 
2767
- const TestFrameWorkComponentFindWidget = {
2659
+ const FindWidget = {
2768
2660
  __proto__: null,
2769
2661
  close,
2770
2662
  focusElement,
@@ -2787,7 +2679,7 @@ const setIconTheme = async id => {
2787
2679
  await invoke$1('IconTheme.setIconTheme', id);
2788
2680
  };
2789
2681
 
2790
- const TestFrameWorkComponentIconTheme = {
2682
+ const IconTheme = {
2791
2683
  __proto__: null,
2792
2684
  setIconTheme
2793
2685
  };
@@ -2808,7 +2700,7 @@ const focusLast$4 = async () => {
2808
2700
  return invoke$1('IframeInspector.focusLast');
2809
2701
  };
2810
2702
 
2811
- const TestFrameWorkComponentIframeInspector = {
2703
+ const IframeInspector = {
2812
2704
  __proto__: null,
2813
2705
  focusFirst: focusFirst$5,
2814
2706
  focusLast: focusLast$4,
@@ -2888,7 +2780,7 @@ const resetKeyBinding = () => {
2888
2780
  return invoke$1('KeyBindings.resetKeyBinding');
2889
2781
  };
2890
2782
 
2891
- const TestFrameWorkComponentKeyBindingsEditor = {
2783
+ const KeyBindingsEditor = {
2892
2784
  __proto__: null,
2893
2785
  addKeyBinding,
2894
2786
  changeWhenExpression,
@@ -2965,7 +2857,7 @@ const press = async key => {
2965
2857
  await invoke$1('TestFrameWork.performKeyBoardAction', 'press', options);
2966
2858
  };
2967
2859
 
2968
- const TestFrameWorkComponentKeyBoard = {
2860
+ const KeyBoard = {
2969
2861
  __proto__: null,
2970
2862
  press
2971
2863
  };
@@ -3007,7 +2899,7 @@ const focusLast$2 = async () => {
3007
2899
  await invoke$1('Main.focusLast');
3008
2900
  };
3009
2901
 
3010
- const TestFrameWorkComponentMain = {
2902
+ const Main = {
3011
2903
  __proto__: null,
3012
2904
  closeActiveEditor,
3013
2905
  closeAllEditors,
@@ -3040,7 +2932,7 @@ const clear$2 = async () => {
3040
2932
  await invoke$1('Output.clear');
3041
2933
  };
3042
2934
 
3043
- const TestFrameWorkComponentOutput = {
2935
+ const Output = {
3044
2936
  __proto__: null,
3045
2937
  clear: clear$2,
3046
2938
  handleFilterInput: handleFilterInput$1,
@@ -3057,7 +2949,7 @@ const openProblems = async () => {
3057
2949
  await invoke$1('Panel.selectIndex', 0);
3058
2950
  };
3059
2951
 
3060
- const TestFrameWorkComponentPanel = {
2952
+ const Panel = {
3061
2953
  __proto__: null,
3062
2954
  open: open$3,
3063
2955
  openProblems
@@ -3088,7 +2980,7 @@ const isFirefox = () => {
3088
2980
  return getIsFirefox();
3089
2981
  };
3090
2982
 
3091
- const TestFrameWorkComponentPlatform = {
2983
+ const Platform = {
3092
2984
  __proto__: null,
3093
2985
  getNodePath,
3094
2986
  isFirefox
@@ -3135,7 +3027,7 @@ const viewAsTable = async () => {
3135
3027
  await invoke$1('Problems.viewAsTable');
3136
3028
  };
3137
3029
 
3138
- const TestFrameWorkComponentProblems = {
3030
+ const Problems = {
3139
3031
  __proto__: null,
3140
3032
  copyMessage,
3141
3033
  focusIndex: focusIndex$3,
@@ -3149,11 +3041,11 @@ const TestFrameWorkComponentProblems = {
3149
3041
  viewAsTable
3150
3042
  };
3151
3043
 
3152
- const QuickPick = 'QuickPick';
3044
+ const QuickPick$1 = 'QuickPick';
3153
3045
 
3154
3046
  const open$2 = async () => {
3155
3047
  // @ts-ignore
3156
- await invoke$1('Viewlet.openWidget', QuickPick, 'everything');
3048
+ await invoke$1('Viewlet.openWidget', QuickPick$1, 'everything');
3157
3049
  };
3158
3050
  const handleInput$2 = async value => {
3159
3051
  // @ts-ignore
@@ -3208,7 +3100,7 @@ const executeCommand = async label => {
3208
3100
  await invoke$1('QuickPick.selectItem', label);
3209
3101
  };
3210
3102
 
3211
- const TestFrameWorkComponentQuickPick = {
3103
+ const QuickPick = {
3212
3104
  __proto__: null,
3213
3105
  executeCommand,
3214
3106
  focusFirst: focusFirst$2,
@@ -3238,7 +3130,7 @@ const refresh = async () => {
3238
3130
  return invoke$1('References.refresh');
3239
3131
  };
3240
3132
 
3241
- const TestFrameWorkComponentReferences = {
3133
+ const References = {
3242
3134
  __proto__: null,
3243
3135
  clear: clear$1,
3244
3136
  collapseAll,
@@ -3278,7 +3170,7 @@ const handleSpace = async () => {
3278
3170
  await invoke$1('Run And Debug.handleSpace');
3279
3171
  };
3280
3172
 
3281
- const TestFrameWorkComponentRunAndDebug = {
3173
+ const RunAndDebug = {
3282
3174
  __proto__: null,
3283
3175
  acceptWatchExpressionEdit,
3284
3176
  addWatchExpression,
@@ -3372,7 +3264,7 @@ const setLimit = async limit => {
3372
3264
  await invoke$1('Search.setLimit', limit);
3373
3265
  };
3374
3266
 
3375
- const TestFrameWorkComponentSearch = {
3267
+ const Search = {
3376
3268
  __proto__: null,
3377
3269
  clearSearchResults,
3378
3270
  collapseDetails,
@@ -3406,7 +3298,7 @@ const update$1 = settings => {
3406
3298
  return invoke$1('Preferences.update', settings);
3407
3299
  };
3408
3300
 
3409
- const TestFrameWorkComponentSettings = {
3301
+ const Settings = {
3410
3302
  __proto__: null,
3411
3303
  update: update$1
3412
3304
  };
@@ -3448,7 +3340,7 @@ const handleScroll = async scrollTop => {
3448
3340
  await invoke$1('Settings.handleScroll', scrollTop, Script);
3449
3341
  };
3450
3342
 
3451
- const TestFrameWorkComponentSettingsView = {
3343
+ const SettingsView = {
3452
3344
  __proto__: null,
3453
3345
  clear,
3454
3346
  handleInput: handleInput$1,
@@ -3469,7 +3361,7 @@ const hide = async () => {
3469
3361
  await invoke$1('Layout.hideSideBar');
3470
3362
  };
3471
3363
 
3472
- const TestFrameWorkComponentSideBar = {
3364
+ const SideBar = {
3473
3365
  __proto__: null,
3474
3366
  hide,
3475
3367
  open
@@ -3489,7 +3381,7 @@ const handleClickSourceControlButtons = async (index, name) => {
3489
3381
  await invoke$1('Source Control.handleClickSourceControlButtons', index, name);
3490
3382
  };
3491
3383
 
3492
- const TestFrameWorkComponentSourceControl = {
3384
+ const SourceControl = {
3493
3385
  __proto__: null,
3494
3386
  acceptInput,
3495
3387
  handleClickSourceControlButtons,
@@ -3501,7 +3393,7 @@ const update = async () => {
3501
3393
  await invoke$1('StatusBar.updateStatusBarItems');
3502
3394
  };
3503
3395
 
3504
- const TestFrameWorkComponentStatusBar = {
3396
+ const StatusBar = {
3505
3397
  __proto__: null,
3506
3398
  update
3507
3399
  };
@@ -3559,7 +3451,7 @@ const toggleMenu = async () => {
3559
3451
  await invoke$1('TitleBarMenuBar.toggleMenu');
3560
3452
  };
3561
3453
 
3562
- const TestFrameWorkComponentTitleBarMenuBar = {
3454
+ const TitleBarMenuBar = {
3563
3455
  __proto__: null,
3564
3456
  closeMenu,
3565
3457
  focus,
@@ -3588,7 +3480,7 @@ const resolve = relativePath => {
3588
3480
  return new URL(relativePath, url).toString();
3589
3481
  };
3590
3482
 
3591
- const TestFrameWorkComponentUrl = {
3483
+ const Url = {
3592
3484
  __proto__: null,
3593
3485
  resolve,
3594
3486
  setUrl
@@ -3665,7 +3557,7 @@ const fromId = async webViewId => {
3665
3557
  };
3666
3558
  };
3667
3559
 
3668
- const TestFrameWorkComponentWebView = {
3560
+ const WebView = {
3669
3561
  __proto__: null,
3670
3562
  fromId
3671
3563
  };
@@ -3688,55 +3580,168 @@ const resolveFileUrl = url => {
3688
3580
  return toFileUrl(url);
3689
3581
  };
3690
3582
 
3691
- const TestFrameWorkComponentWorkspace = {
3583
+ const Workspace = {
3692
3584
  __proto__: null,
3693
3585
  openTmpDir,
3694
3586
  resolveFileUrl,
3695
3587
  setPath
3696
3588
  };
3697
3589
 
3698
- const TestFrameWorkComponent = {
3699
- __proto__: null,
3700
- About: TestFrameWorkComponentAbout,
3701
- ActivityBar: TestFrameworkComponentActivityBar,
3702
- BaseUrl: TestFrameWorkComponentBaseUrl,
3703
- ClipBoard: TestFrameworkComponentClipBoard,
3704
- Command: TestFrameWorkComponentCommand,
3705
- ContextMenu: TestFrameWorkComponentContextMenu,
3706
- Developer: TestFrameWorkComponentDeveloper,
3707
- Dialog: TestFrameWorkComponentDialog,
3708
- Editor: TestFrameWorkComponentEditor,
3709
- EditorCompletion: TestFrameWorkComponentEditorCompletion,
3710
- EditorHover: TestFrameWorkComponentEditorHover,
3711
- EditorRename: TestFrameWorkComponentEditorRename,
3712
- EditorSourceAction: TestFrameWorkComponentEditorSourceAction,
3713
- Explorer: TestFrameWorkComponentExplorer,
3714
- Extension: TestFrameWorkComponentExtension,
3715
- ExtensionDetail: TestFrameWorkComponentExtensionDetail,
3716
- FileSystem: TestFrameWorkComponentFileSystem,
3717
- FindWidget: TestFrameWorkComponentFindWidget,
3718
- IconTheme: TestFrameWorkComponentIconTheme,
3719
- IframeInspector: TestFrameWorkComponentIframeInspector,
3720
- KeyBindingsEditor: TestFrameWorkComponentKeyBindingsEditor,
3721
- KeyBoard: TestFrameWorkComponentKeyBoard,
3722
- Main: TestFrameWorkComponentMain,
3723
- Output: TestFrameWorkComponentOutput,
3724
- Panel: TestFrameWorkComponentPanel,
3725
- Platform: TestFrameWorkComponentPlatform,
3726
- Problems: TestFrameWorkComponentProblems,
3727
- QuickPick: TestFrameWorkComponentQuickPick,
3728
- References: TestFrameWorkComponentReferences,
3729
- RunAndDebug: TestFrameWorkComponentRunAndDebug,
3730
- Search: TestFrameWorkComponentSearch,
3731
- Settings: TestFrameWorkComponentSettings,
3732
- SettingsView: TestFrameWorkComponentSettingsView,
3733
- SideBar: TestFrameWorkComponentSideBar,
3734
- SourceControl: TestFrameWorkComponentSourceControl,
3735
- StatusBar: TestFrameWorkComponentStatusBar,
3736
- TitleBarMenuBar: TestFrameWorkComponentTitleBarMenuBar,
3737
- Url: TestFrameWorkComponentUrl,
3738
- WebView: TestFrameWorkComponentWebView,
3739
- Workspace: TestFrameWorkComponentWorkspace
3590
+ const createApi = platform => {
3591
+ return {
3592
+ About,
3593
+ ActivityBar,
3594
+ BaseUrl,
3595
+ ClipBoard,
3596
+ Command,
3597
+ ContextMenu,
3598
+ Developer,
3599
+ Dialog,
3600
+ Editor,
3601
+ EditorCompletion,
3602
+ EditorHover,
3603
+ EditorRename,
3604
+ EditorSourceAction,
3605
+ Explorer,
3606
+ Extension,
3607
+ ExtensionDetail,
3608
+ FileSystem: {
3609
+ ...FileSystem,
3610
+ loadFixture(url) {
3611
+ return loadFixture(platform, url);
3612
+ }
3613
+ },
3614
+ FindWidget,
3615
+ IconTheme,
3616
+ IframeInspector,
3617
+ KeyBindingsEditor,
3618
+ KeyBoard,
3619
+ Main,
3620
+ Output,
3621
+ Panel,
3622
+ Platform,
3623
+ Problems,
3624
+ QuickPick,
3625
+ References,
3626
+ RunAndDebug,
3627
+ Search,
3628
+ Settings,
3629
+ SettingsView,
3630
+ SideBar,
3631
+ SourceControl,
3632
+ StatusBar,
3633
+ TitleBarMenuBar,
3634
+ Url,
3635
+ WebView,
3636
+ Workspace,
3637
+ test,
3638
+ Locator: create,
3639
+ expect,
3640
+ getTmpDir: getTmpDir$1 // TODO maybe deprecate this or move to file system
3641
+ };
3642
+ };
3643
+
3644
+ const callFunction = async (fn, args) => {
3645
+ try {
3646
+ await fn(args);
3647
+ return undefined;
3648
+ } catch (error) {
3649
+ return error;
3650
+ }
3651
+ };
3652
+
3653
+ const formatDuration = duration => {
3654
+ return duration.toFixed(2) + 'ms';
3655
+ };
3656
+
3657
+ const Fail = 'fail';
3658
+ const Pass = 'pass';
3659
+
3660
+ const executeTest2 = async (name, fn, globals, timestampGenerator) => {
3661
+ const getTimestamp = timestampGenerator;
3662
+ const start = getTimestamp();
3663
+ const error = await callFunction(fn, globals);
3664
+ const end = getTimestamp();
3665
+ const duration = end - start;
3666
+ const formattedDuration = formatDuration(duration);
3667
+ if (error) {
3668
+ return {
3669
+ error,
3670
+ start,
3671
+ end,
3672
+ duration,
3673
+ formattedDuration,
3674
+ name,
3675
+ type: Fail,
3676
+ background: 'red',
3677
+ text: `test failed: ${error}`
3678
+ };
3679
+ }
3680
+ return {
3681
+ error: undefined,
3682
+ start,
3683
+ end,
3684
+ duration,
3685
+ formattedDuration,
3686
+ name,
3687
+ type: Pass,
3688
+ background: 'green',
3689
+ text: `test passed in ${formattedDuration}`
3690
+ };
3691
+ };
3692
+
3693
+ const printError = error => {
3694
+ if (error && error.constructor.name === 'AssertionError') {
3695
+ console.error(error.message);
3696
+ } else {
3697
+ console.error(error);
3698
+ }
3699
+ };
3700
+
3701
+ const printTestError = async error => {
3702
+ // TODO ask error worker to add codeframe
3703
+ printError(error);
3704
+ };
3705
+
3706
+ const now = () => {
3707
+ return performance.now();
3708
+ };
3709
+
3710
+ const executeTest = async (name, fn, globals = {}) => {
3711
+ const {
3712
+ error,
3713
+ formattedDuration,
3714
+ background,
3715
+ text,
3716
+ type
3717
+ } = await executeTest2(name, fn, globals, now);
3718
+ if (error) {
3719
+ await printTestError(error);
3720
+ } else {
3721
+ // eslint-disable-next-line no-console
3722
+ console.info(`PASS ${name} in ${formattedDuration}`);
3723
+ }
3724
+ // @ts-ignore
3725
+ await invoke$1('TestFrameWork.showOverlay', type, background, text);
3726
+ };
3727
+
3728
+ const importScript = async url => {
3729
+ try {
3730
+ return await import(url);
3731
+ } catch (error) {
3732
+ throw error;
3733
+ // TODO
3734
+ // const actualErrorMessage = await TryToGetactualImportErrorMessage.tryToGetActualImportErrorMessage(url, error)
3735
+ // throw new Error(actualErrorMessage)
3736
+ }
3737
+ };
3738
+
3739
+ const importTest = async url => {
3740
+ try {
3741
+ return await importScript(url);
3742
+ } catch (error) {
3743
+ throw new VError(error, 'Failed to import test');
3744
+ }
3740
3745
  };
3741
3746
 
3742
3747
  // TODO move this into three steps:
@@ -3744,21 +3749,12 @@ const TestFrameWorkComponent = {
3744
3749
  // 2. execute test
3745
3750
  // 3. print out results
3746
3751
  const execute = async (href, platform) => {
3747
- const globals = {
3748
- ...TestFrameWorkComponent,
3749
- FileSystem: {
3750
- ...TestFrameWorkComponentFileSystem,
3751
- loadFixture(url) {
3752
- return loadFixture(platform, url);
3753
- }
3754
- },
3755
- ...TestFrameWork
3756
- };
3752
+ const globals = createApi(platform);
3757
3753
  // TODO
3758
3754
  // 0. wait for page to be ready
3759
3755
  // 1. get script to import from renderer process (url or from html)
3760
3756
  const scriptUrl = href;
3761
- setUrl(scriptUrl);
3757
+ setUrl(scriptUrl); // TODO avoid side effect
3762
3758
  // 2. import that script
3763
3759
  const module = await importTest(scriptUrl);
3764
3760
  if (module.mockRpc) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/test-worker",
3
- "version": "6.6.0",
3
+ "version": "6.8.0",
4
4
  "description": "Test Worker",
5
5
  "repository": {
6
6
  "type": "git",