Skip to content

Commit db14913

Browse files
committed
fix: identical tests in tauri and electron all 329 tests pass
1 parent c166310 commit db14913

7 files changed

Lines changed: 73 additions & 13 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ Here's a closer look at the Phoenix VFS organization:
2525
- **Windows Example**: `/tauri/c/Program Files/` could represent the C drive's "Program Files" directory.
2626
- **Linux/macOS Example**: `/tauri/usr/bin/` might be an accessible directory, akin to native paths you'd expect on these platforms.
2727

28+
- **Electron Support**:
29+
- Electron is also supported using the same `/tauri/` paths for backward compatibility.
30+
- The APIs work identically in both Electron and Tauri environments.
31+
2832
- **Node Websocket Connector Integration**:
2933
- The `/tauri/` paths can be accessed via websockets. This integration is much more
3034
performant than Tauri's fs rust APIs(generally 4x faster and 10x faster for large files).

src-electron/main.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,26 @@ ipcMain.handle('get-app-data-dir', () => {
131131
}
132132
});
133133

134+
// Get Windows drive letters (returns null on non-Windows platforms)
135+
ipcMain.handle('get-windows-drives', async () => {
136+
if (process.platform !== 'win32') {
137+
return null;
138+
}
139+
// On Windows, check which drive letters exist by testing A-Z
140+
const drives = [];
141+
for (let i = 65; i <= 90; i++) { // A-Z
142+
const letter = String.fromCharCode(i);
143+
const drivePath = `${letter}:\\`;
144+
try {
145+
await fsp.access(drivePath);
146+
drives.push(letter);
147+
} catch {
148+
// Drive doesn't exist
149+
}
150+
}
151+
return drives.length > 0 ? drives : null;
152+
});
153+
134154
// Dialogs
135155
ipcMain.handle('show-open-dialog', async (event, options) => {
136156
const result = await dialog.showOpenDialog(mainWindow, options);

src-electron/preload.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
2222
getAppPath: () => ipcRenderer.invoke('get-app-path'),
2323
getDocumentsDir: () => ipcRenderer.invoke('get-documents-dir'),
2424
getAppDataDir: () => ipcRenderer.invoke('get-app-data-dir'),
25+
getWindowsDrives: () => ipcRenderer.invoke('get-windows-drives'),
2526
showOpenDialog: (options) => ipcRenderer.invoke('show-open-dialog', options),
2627
showSaveDialog: (options) => ipcRenderer.invoke('show-save-dialog', options),
2728

test/test-copy.browser.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,41 @@ function _setupTests(testTypeSrc, testTypeDst) {
6060
}
6161

6262
before(async function () {
63+
this.timeout(15000);
64+
if (window.__TAURI__ || window.__ELECTRON__) {
65+
await window.waitForTrue(()=>{return window.isNodeSetup;}, 10000);
66+
}
6367
srcTestPath = await _getPathForTestType(testTypeSrc) + '/src';
6468
destTestPath = await _getPathForTestType(testTypeDst)+ '/dest';
6569
});
6670

6771
beforeEach(async function () {
72+
this.timeout(15000);
6873
// setup test folders
6974
await _clean();
7075
console.log(`mkdir: `, srcTestPath);
7176
let makeSuccess = false;
72-
fs.mkdirs(srcTestPath, 0o777 ,true, ()=>{
77+
let makeError = null;
78+
fs.mkdirs(srcTestPath, 0o777 ,true, (err)=>{
79+
makeError = err;
7380
makeSuccess = true;
7481
});
7582
await waitForTrue(()=>{return makeSuccess;},10000);
83+
if (makeError) {
84+
console.error(`Failed to create srcTestPath: `, makeError);
85+
}
7686

7787
console.log(`mkdir: `, destTestPath);
7888
makeSuccess = false;
79-
fs.mkdirs(destTestPath, 0o777 ,true, ()=>{
89+
makeError = null;
90+
fs.mkdirs(destTestPath, 0o777 ,true, (err)=>{
91+
makeError = err;
8092
makeSuccess = true;
8193
});
8294
await waitForTrue(()=>{return makeSuccess;},10000);
95+
if (makeError) {
96+
console.error(`Failed to create destTestPath: `, makeError);
97+
}
8398
});
8499

85100
afterEach(async function () {

test/test-getPlatformPath-api.browser.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,32 @@ describe(`test getTauriVirtualPath api`, function () {
8484
}
8585
});
8686

87-
if(window.__TAURI__){
87+
if(window.__TAURI__ || window.__ELECTRON__){
8888
describe(`test _get_windows_drives api`, function () {
8989
function isLetter(str) {
9090
return !!(str.length === 1 && str.match(/[a-z]/i));
9191
}
92+
93+
async function getWindowsDrives() {
94+
if (window.__TAURI__) {
95+
return window.__TAURI__.invoke('_get_windows_drives');
96+
} else if (window.electronAPI) {
97+
return window.electronAPI.getWindowsDrives();
98+
}
99+
return null;
100+
}
101+
92102
if(IS_WINDOWS){
93103
it(`windows: should _get_windows_drives return all windows drives`, async function () {
94-
let drives = await window.__TAURI__.invoke('_get_windows_drives');
104+
let drives = await getWindowsDrives();
95105
expect(drives.length > 1).to.be.true;
96106
for(let drive of drives){
97107
expect(isLetter(drive)).to.be.true;
98108
}
99109
});
100110
} else {
101111
it(`should _get_windows_drives return null in other platforms`, async function () {
102-
let drives = await window.__TAURI__.invoke('_get_windows_drives');
112+
let drives = await getWindowsDrives();
103113
expect(drives).to.be.null;
104114
});
105115
}

test/test-node.browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* global expect, execNode, NODE_COMMANDS, fs */
22

33
describe(`node ws fs tests`, function () {
4-
if(!window.__TAURI__){
4+
if(!window.__TAURI__ && !window.__ELECTRON__){
55
return;
66
}
77

test/test.worker.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ function _setupTests(testType) {
66
let messageFromWorker = null;
77

88
function consoleLogToShell(message) {
9-
return window.__TAURI__.invoke("console_log", {message});
9+
if (window.__TAURI__) {
10+
return window.__TAURI__.invoke("console_log", {message});
11+
} else if (window.electronAPI) {
12+
return window.electronAPI.consoleLog(message);
13+
}
1014
}
1115

1216
async function _clean() {
@@ -28,8 +32,8 @@ function _setupTests(testType) {
2832
}
2933

3034
async function _requestWritePerm() {
31-
if(window.__TAURI__ || testPath !== window.mountTestPath){
32-
// fs access apis not tested in tauri
35+
if(window.__TAURI__ || window.__ELECTRON__ || testPath !== window.mountTestPath){
36+
// fs access apis not tested in tauri/electron
3337
return;
3438
}
3539
return new Promise((resolve, reject)=>{
@@ -45,13 +49,19 @@ function _setupTests(testType) {
4549
}
4650

4751
async function _setupTestPath() {
52+
let appDataDir;
4853
switch (testType) {
4954
case TEST_TYPE_FS_ACCESS: testPath = window.mountTestPath;break;
5055
case TEST_TYPE_FILER: testPath = window.virtualTestPath;break;
5156
case TEST_TYPE_TAURI_WS:
5257
await window.waitForTrue(()=>{return window.isNodeSetup;}, 10000);
5358
fs.forceUseNodeWSEndpoint(true);
54-
testPath = fs.getTauriVirtualPath(`${await window.__TAURI__.path.appLocalDataDir()}test-phoenix-fs`);
59+
if (window.__TAURI__) {
60+
appDataDir = await window.__TAURI__.path.appLocalDataDir();
61+
} else if (window.electronAPI) {
62+
appDataDir = await window.electronAPI.getAppDataDir();
63+
}
64+
testPath = fs.getTauriVirtualPath(`${appDataDir}test-phoenix-fs`);
5565
consoleLogToShell("using tauri websocket test path: "+ testPath);
5666
break;
5767
default: throw new Error("unknown file system impl");
@@ -171,16 +181,16 @@ describe(`web worker filer tests`, function () {
171181
_setupTests(TEST_TYPE_FILER);
172182
});
173183

174-
if(window.__TAURI__){
184+
if(window.__TAURI__ || window.__ELECTRON__){
175185
describe(`web worker Tauri WS tests`, function () {
176186
_setupTests(TEST_TYPE_TAURI_WS);
177187
});
178188
}
179189

180190
if(window.supportsFsAccessAPIs) {
181191
describe(`web worker fs access tests`, function () {
182-
if(window.__TAURI__){
183-
it(`fs access tests are disabled in tauri`, function () {});
192+
if(window.__TAURI__ || window.__ELECTRON__){
193+
it(`fs access tests are disabled in tauri/electron`, function () {});
184194
return;
185195
} else {
186196
_setupTests(TEST_TYPE_FS_ACCESS);

0 commit comments

Comments
 (0)