Skip to content

Commit 94ffbd1

Browse files
committed
fix: test reliability
1 parent 3316912 commit 94ffbd1

7 files changed

Lines changed: 22 additions & 8 deletions

File tree

test/test-dir.browser.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ function _setupTests(testType) {
5858
}
5959

6060
before(async function () {
61+
this.timeout(15000); // Increase timeout for Node WebSocket setup
6162
switch (testType) {
6263
case TEST_TYPE_FS_ACCESS: testPath = window.mountTestPath;break;
6364
case TEST_TYPE_FILER: testPath = window.virtualTestPath;break;
6465
case TEST_TYPE_TAURI_WS:
65-
await window.waitForTrue(()=>{return window.isNodeSetup;},1000);
66+
await window.waitForTrue(()=>{return window.isNodeSetup;}, 10000);
6667
fs.forceUseNodeWSEndpoint(true);
6768
testPath = fs.getTauriVirtualPath(`${await _getTestBaseDir()}test-phoenix-fs`);
6869
consoleLogToShell("using tauri websocket test path: "+ testPath);
@@ -82,6 +83,7 @@ function _setupTests(testType) {
8283
});
8384

8485
beforeEach(async function () {
86+
this.timeout(10000); // Increase timeout for setup operations
8587
// setup test folders
8688
await _clean();
8789
console.log(`mkdirs: `, testPath);
@@ -573,7 +575,7 @@ describe(`Should phoenix be able to read root dir`, async function () {
573575
if(window.__TAURI__ || window.__ELECTRON__){
574576

575577
before(async ()=>{
576-
await window.waitForTrue(()=>{return window.isNodeSetup;},1000);
578+
await window.waitForTrue(()=>{return window.isNodeSetup;}, 10000);
577579
});
578580

579581
it(`Should read root /tauri dir`, async function () {

test/test-file.browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function _setupTests(testType) {
7979
case TEST_TYPE_FS_ACCESS: testPath = window.mountTestPath;break;
8080
case TEST_TYPE_FILER: testPath = window.virtualTestPath;break;
8181
case TEST_TYPE_TAURI_WS:
82-
await window.waitForTrue(()=>{return window.isNodeSetup;},1000);
82+
await window.waitForTrue(()=>{return window.isNodeSetup;}, 10000);
8383
fs.forceUseNodeWSEndpoint(true);
8484
testPath = fs.getTauriVirtualPath(`${await _getTestBaseDir()}test-phoenix-fs`);
8585
consoleLogToShell("using tauri websocket test path: "+ testPath);

test/test-node.browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe(`node ws fs tests`, function () {
88
let wssPort, wssEndpoint;
99

1010
before(async function () {
11-
await window.waitForTrue(()=>{return window.isNodeSetup;},1000);
11+
await window.waitForTrue(()=>{return window.isNodeSetup;}, 10000);
1212
let message = await execNode(NODE_COMMANDS.GET_PORT);
1313
expect(message.port).to.be.a('number');
1414
wssPort = message.port;

test/test-watcher.browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function _setupTests(testType) {
148148
case TEST_TYPE_FS_ACCESS: testPath = window.mountTestPath;break;
149149
case TEST_TYPE_FILER: testPath = window.virtualTestPath;break;
150150
case TEST_TYPE_TAURI_WS:
151-
await window.waitForTrue(()=>{return window.isNodeSetup;},1000);
151+
await window.waitForTrue(()=>{return window.isNodeSetup;}, 10000);
152152
fs.forceUseNodeWSEndpoint(true);
153153
testPath = fs.getTauriVirtualPath(`${await _getTestBaseDir()}test-phoenix-fs`);
154154
consoleLogToShell("using tauri websocket test path: "+ testPath);

test/test.worker.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function _setupTests(testType) {
4949
case TEST_TYPE_FS_ACCESS: testPath = window.mountTestPath;break;
5050
case TEST_TYPE_FILER: testPath = window.virtualTestPath;break;
5151
case TEST_TYPE_TAURI_WS:
52-
await window.waitForTrue(()=>{return window.isNodeSetup;},1000);
52+
await window.waitForTrue(()=>{return window.isNodeSetup;}, 10000);
5353
fs.forceUseNodeWSEndpoint(true);
5454
testPath = fs.getTauriVirtualPath(`${await window.__TAURI__.path.appLocalDataDir()}test-phoenix-fs`);
5555
consoleLogToShell("using tauri websocket test path: "+ testPath);
@@ -69,8 +69,11 @@ function _setupTests(testType) {
6969
console.log(`From Worker:`, event);
7070
messageFromWorker = event.data;
7171
};
72+
// Wait for worker to be ready before running tests
73+
let workerReady = await waitForWorkerMessage(`worker.ready`, 5000);
74+
expect(workerReady).to.be.true;
7275
if(testType === TEST_TYPE_TAURI_WS){
73-
await window.waitForTrue(()=>{return window.isNodeSetup;},1000);
76+
await window.waitForTrue(()=>{return window.isNodeSetup;}, 10000);
7477
worker.postMessage({command: `tauriWSInit`, wsEndpoint: window.nodeWSEndpoint});
7578
let status = await waitForWorkerMessage(`tauriWSInit.ok`, 1000);
7679
expect(status).to.be.true;

test/testInit.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ window.waitForTrue = async function(checkFn, timeoutMs) {
2525

2626
if(window.__TAURI__ || window.__ELECTRON__) {
2727
before(async function () {
28-
await window.waitForTrue(()=>{return window.isNodeSetup;},1000);
28+
this.timeout(15000); // Increase mocha timeout for Node WebSocket setup
29+
// Wait up to 10 seconds for Node WebSocket to be ready
30+
// This is important for slower systems or first-time loads
31+
let ready = await window.waitForTrue(()=>{return window.isNodeSetup;}, 10000);
32+
if (!ready) {
33+
throw new Error('Timeout waiting for Node WebSocket setup');
34+
}
2935
});
3036
}

test/worker-task.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,6 @@ self.addEventListener('message', (event) => {
9696
default: console.error('unknown worker command: ', command);
9797
}
9898
}, false);
99+
100+
// Signal that the worker is ready
101+
postMessage('worker.ready');

0 commit comments

Comments
 (0)