|
9 | 9 | <!-- Comment above line and Uncomment below line if you want to get more debug symbols in web inspector.--> |
10 | 10 | <!-- <script src="virtualfs-debug.js"></script>--> |
11 | 11 | <script> |
| 12 | + // Electron detection and setup |
| 13 | + if(window.electronAPI) { |
| 14 | + window.__ELECTRON__ = true; |
| 15 | + } |
12 | 16 | window.addEventListener('keydown', function(event) { |
13 | 17 | if (event.key === 'F5') { |
14 | 18 | location.reload(); |
15 | 19 | } |
16 | 20 | }); |
17 | | - if(window.showOpenFilePicker && !window.__TAURI__){ |
| 21 | + if(window.showOpenFilePicker){ |
18 | 22 | window.supportsFsAccessAPIs = true; |
19 | 23 | } |
| 24 | + if(window.__TAURI__ || window.__ELECTRON__) { |
| 25 | + window.supportsFsAccessAPIs = false; // use native fs apis directly |
| 26 | + } |
20 | 27 | const TEST_TYPE_FS_ACCESS = "fs access"; |
21 | 28 | const TEST_TYPE_FILER = "filer"; |
22 | | - const TEST_TYPE_TAURI = "tauri"; |
23 | | - const TEST_TYPE_TAURI_WS = "tauriWs"; |
| 29 | + const TEST_TYPE_TAURI = "tauri"; // electron will reuse this. tauri is our native edge name(which includes electron) |
| 30 | + const TEST_TYPE_TAURI_WS = "tauriWs"; // electron will reuse this |
24 | 31 | window.IS_WINDOWS = navigator.userAgent.includes('Windows'); |
25 | 32 | </script> |
26 | 33 | <script> |
|
76 | 83 | },10000); |
77 | 84 | }). catch(console.error); |
78 | 85 | } |
| 86 | + // Electron detection and setup |
| 87 | + if(window.electronAPI){ |
| 88 | + window.electronAPI.getNodeWSPort().then(port => { |
| 89 | + window.nodeWSEndpoint = `ws://localhost:${port}/phoenixFS`; |
| 90 | + fs.setNodeWSEndpoint(`ws://localhost:${port}/phoenixFS`); |
| 91 | + window.isNodeSetup = true; |
| 92 | + }); |
| 93 | + // Heartbeat to keep Node server alive |
| 94 | + setInterval(() => { |
| 95 | + // Heartbeat is handled by main process in Electron |
| 96 | + }, 10000); |
| 97 | + } |
79 | 98 | </script> |
80 | 99 | <script src="thirdparty/chai@4.2.0.js"></script> |
81 | 100 | <script src="thirdparty/mocha@10.3.0.js"></script> |
|
98 | 117 | window.virtualTestPath = '/test-phoenix-fs'; |
99 | 118 |
|
100 | 119 | function observeRunStatus(runner) { |
101 | | - if(!window.__TAURI__){ |
| 120 | + if(!window.__TAURI__ && !window.__ELECTRON__){ |
102 | 121 | return; |
103 | 122 | } |
104 | | - console.log("setting up tauri test reporters to log to system console.") |
105 | | - function consoleLogToShell(message) { |
106 | | - return __TAURI__.invoke("console_log", {message}); |
107 | | - } |
108 | 123 |
|
109 | | - async function quitIfNeeded(exitStatus) { |
110 | | - if(!window.__TAURI__){ |
111 | | - return; |
112 | | - } |
113 | | - if(!location.href.startsWith("http://localhost:8081/test/")) { |
114 | | - // during development, we dont switch off node at end of tests for ease of development and debug |
115 | | - fs.stopNodeWSEndpoint(); |
116 | | - window.execNode(NODE_COMMANDS.TERMINATE); |
117 | | - await waitForTrue(()=>{return window.isNodeTerminated;},1000); |
118 | | - } |
119 | | - __TAURI__.cli.getMatches().then(matches=>{ |
120 | | - if(matches?.args["quit-when-done"]?.occurrences) { |
121 | | - __TAURI__.process.exit(exitStatus) |
| 124 | + let consoleLogToShell; |
| 125 | + let quitIfNeeded; |
| 126 | + |
| 127 | + if(window.__TAURI__) { |
| 128 | + console.log("setting up tauri test reporters to log to system console."); |
| 129 | + consoleLogToShell = function(message) { |
| 130 | + return window.__TAURI__.invoke("console_log", {message}); |
| 131 | + }; |
| 132 | + quitIfNeeded = async function(exitStatus) { |
| 133 | + if(!location.href.startsWith("http://localhost:8081/test/")) { |
| 134 | + // during development, we dont switch off node at end of tests for ease of development and debug |
| 135 | + fs.stopNodeWSEndpoint(); |
| 136 | + window.execNode(NODE_COMMANDS.TERMINATE); |
| 137 | + await waitForTrue(()=>{return window.isNodeTerminated;},1000); |
122 | 138 | } |
123 | | - }); |
| 139 | + window.__TAURI__.cli.getMatches().then(matches=>{ |
| 140 | + if(matches?.args["quit-when-done"]?.occurrences) { |
| 141 | + window.__TAURI__.process.exit(exitStatus) |
| 142 | + } |
| 143 | + }); |
| 144 | + }; |
| 145 | + } else if(window.__ELECTRON__) { |
| 146 | + console.log("setting up electron test reporters to log to system console."); |
| 147 | + consoleLogToShell = function(message) { |
| 148 | + window.electronAPI.consoleLog(message); |
| 149 | + return Promise.resolve(); |
| 150 | + }; |
| 151 | + quitIfNeeded = async function(exitStatus) { |
| 152 | + if(!location.href.startsWith("http://localhost:8081/test/")) { |
| 153 | + // during development, we dont quit at end of tests for ease of development and debug |
| 154 | + fs.stopNodeWSEndpoint(); |
| 155 | + } |
| 156 | + // Always quit in Electron since there's no CLI arg parsing |
| 157 | + window.electronAPI.quitApp(exitStatus); |
| 158 | + }; |
124 | 159 | } |
125 | 160 |
|
126 | 161 | runner.on('end', function() { |
|
180 | 215 | observeRunStatus(mocha.run()); |
181 | 216 | }); |
182 | 217 | } |
183 | | - function runTauriTests() { |
184 | | - if(window.__TAURI__){ |
185 | | - window.tauriTests = true; |
186 | | - console.log("Tauri env detected. running tauri specific tests."); |
| 218 | + function runNativeAppTests() { |
| 219 | + if(window.__TAURI__ || window.__ELECTRON__){ |
| 220 | + window.tauriTests = true; // reuse tauriTests flag for both |
| 221 | + console.log("Native app env detected. Running native app tests."); |
187 | 222 | document.getElementById('openFolderButton').style = "display:none"; |
188 | | - observeRunStatus(mocha.run()); |
| 223 | + // Wait for Node WebSocket setup before running tests |
| 224 | + function waitAndRun() { |
| 225 | + if(window.isNodeSetup) { |
| 226 | + observeRunStatus(mocha.run()); |
| 227 | + } else { |
| 228 | + setTimeout(waitAndRun, 100); |
| 229 | + } |
| 230 | + } |
| 231 | + waitAndRun(); |
189 | 232 | } |
190 | 233 | } |
191 | 234 | </script> |
192 | 235 | </head> |
193 | | -<body onload="runTauriTests()"> |
| 236 | +<body onload="runNativeAppTests()"> |
194 | 237 | <div id="mocha"></div> |
195 | 238 | <button id="openFolderButton" onclick="openFolderAndRunTests()">Open any blank folder to start tests. Warning - folder contents will be deleted!!!!</button> |
196 | 239 | </body> |
|
0 commit comments