Skip to content

Commit d94256b

Browse files
committed
test: point all unit and integ tests folder to tauri node fs in tauri env
1 parent 37a27f1 commit d94256b

File tree

8 files changed

+51
-25
lines changed

8 files changed

+51
-25
lines changed

src-node/index.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function randomNonce(byteLength) {
4040
return randomId;
4141
}
4242

43+
let debugMode = false;
4344
const COMMAND_RESPONSE_PREFIX = 'phnodeResp:';
4445
// Generate a random 64-bit url. This should take 100 million+ of years to crack with current http connection speed.
4546
const PHOENIX_FS_URL = `/PhoenixFS${randomNonce(8)}`;
@@ -66,25 +67,33 @@ function _sendResponse(responseMessage, commandID) {
6667
}) + "\n");
6768
}
6869

70+
function resetOrphanExitTimer() {
71+
const timeout = debugMode ? 60000 * 15 : 60000;
72+
// in debug mode, we wait for more minutes to not exit node if phcode doesn't send heartbeats on break point debug
73+
clearTimeout(orphanExitTimer);
74+
orphanExitTimer = setTimeout(()=>{
75+
process.exit(1);
76+
}, timeout);
77+
}
78+
6979
function processCommand(line) {
7080
try{
7181
let jsonCmd = JSON.parse(line);
7282
switch (jsonCmd.commandCode) {
7383
case "terminate": process.exit(0); return;
7484
case "heartBeat":
75-
clearTimeout(orphanExitTimer);
76-
orphanExitTimer = setTimeout(()=>{
77-
process.exit(1);
78-
}, 60000);
85+
resetOrphanExitTimer();
7986
return;
8087
case "ping": _sendResponse("pong", jsonCmd.commandID); return;
8188
case "setDebugMode":
82-
if(jsonCmd.commandData) {
89+
debugMode = jsonCmd.commandData;
90+
if(debugMode) {
8391
console.log = savedConsoleLog;
8492
console.log("Debug Mode Enabled");
8593
} else {
8694
console.log = function () {}; // swallow logs
8795
}
96+
resetOrphanExitTimer();
8897
_sendResponse("done", jsonCmd.commandID); return;
8998
case "getEndpoints":
9099
serverPortPromise.then(port =>{

src/node-loader.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ if(Phoenix.browser.isTauri) {
7878
child = await command.spawn();
7979

8080
const execNode = function (commandCode, commandData) {
81+
if(window.isNodeTerminated){
82+
return Promise.reject("Node is terminated! Cannot execute: " + commandCode);
83+
}
8184
const newCommandID = commandID ++;
8285
child.write(JSON.stringify({
8386
commandCode: commandCode, commandID: newCommandID, commandData
@@ -92,7 +95,9 @@ if(Phoenix.browser.isTauri) {
9295
setInspectEnabled,
9396
isInspectEnabled,
9497
terminateNode: function () {
95-
execNode(NODE_COMMANDS.TERMINATE);
98+
if(!window.isNodeTerminated) {
99+
execNode(NODE_COMMANDS.TERMINATE);
100+
}
96101
},
97102
getInspectPort: function () {
98103
return inspectPort;

test/SpecRunner.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@
277277

278278
<script src="../src/phoenix/shell.js" type="module"></script>
279279
<script src="virtual-server-loader.js" type="module"></script>
280+
<script src="../src/node-loader.js"></script>
280281

281282
<link href="../src/thirdparty/bootstrap/bootstrap.min.css" rel="stylesheet">
282283
<link href="../src/thirdparty/bootstrap/bootstrap-grid.min.css" rel="stylesheet">

test/SpecRunner.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ define(function (require, exports, module) {
498498

499499
function _copyZippedItemToFS(path, item) {
500500
return new Promise((resolve, reject) =>{
501-
let destPath = `/test/${path}`;
501+
let destPath = `${SpecRunnerUtils.getTestPath()}/${path}`;
502502
if(item.dir){
503503
window.fs.mkdirs(destPath, 0o777, true, (err)=>{
504504
if(err){
@@ -525,7 +525,7 @@ define(function (require, exports, module) {
525525

526526
function makeTestDir() {
527527
return new Promise((resolve, reject)=>{
528-
let testPath = `/test/`;
528+
let testPath = SpecRunnerUtils.getTestPath();
529529
window.fs.mkdirs(testPath, 0o777, true, (err)=>{
530530
if(err){
531531
reject();
@@ -553,16 +553,16 @@ define(function (require, exports, module) {
553553
} else {
554554
JSZip.loadAsync(data).then(function (zip) {
555555
let keys = Object.keys(zip.files);
556-
let destPath = `/test/`;
557-
globalTestRunnerLogToConsole("Cleaning test directory: /test/");
556+
let destPath = SpecRunnerUtils.getTestPath();
557+
globalTestRunnerLogToConsole("Cleaning test directory: " + destPath);
558558
window.fs.unlink(destPath, async function (err) {
559559
if(err && err.code !== 'ENOENT'){
560560
console.error("Could not clean test dir. we will try to move ahead", err);
561561
// we will now try to overwrite existing
562562
}
563-
globalTestRunnerLogToConsole("Creating test folder /test/");
563+
globalTestRunnerLogToConsole("Creating test folder " + destPath);
564564
await makeTestDir();
565-
globalTestRunnerLogToConsole("Copying test assets to /test/");
565+
globalTestRunnerLogToConsole("Copying test assets to " + destPath);
566566
let progressMessageEl = document.getElementById("loadProgressMessage");
567567
let lastPrintedPercent = 0;
568568
for (let i = 0; i < keys.length; i++) {

test/spec/FindInFiles-integ-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,19 @@ define(function (require, exports, module) {
313313
let editor;
314314
await awaitsFor(function () {
315315
editor = SearchResultsView._previewEditorForTests;
316-
return (editor && editor.document.file.fullPath === "/test/spec/FindReplace-test-files/css/foo.css");
317-
}, "keyboard nav", 1000);
316+
return (editor && editor.document.file.fullPath === SpecRunnerUtils.getTestPath("/spec/FindReplace-test-files/css/foo.css"));
317+
}, "file open");
318318
SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_DOWN, "keydown", $searchField[0]);
319319
await awaitsFor(function () {
320320
editor = SearchResultsView._previewEditorForTests;
321-
return (editor && editor.document.file.fullPath === "/test/spec/FindReplace-test-files/foo.js");
322-
}, "keyboard nav", 1000);
321+
return (editor && editor.document.file.fullPath === SpecRunnerUtils.getTestPath("/spec/FindReplace-test-files/foo.js"));
322+
}, "keyboard nav down");
323323
SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_UP, "keydown", $searchField[0]);
324324
await awaitsFor(function () {
325325
editor = SearchResultsView._previewEditorForTests;
326326
console.log(editor && editor.document.file.fullPath);
327-
return (editor && editor.document.file.fullPath === "/test/spec/FindReplace-test-files/css/foo.css");
328-
}, "keyboard nav", 1000);
327+
return (editor && editor.document.file.fullPath === SpecRunnerUtils.getTestPath("/spec/FindReplace-test-files/css/foo.css"));
328+
}, "keyboard nav up");
329329
});
330330

331331
it("should find start and end positions", async function () {

test/spec/LowLevelFileIO-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ define(function (require, exports, module) {
155155

156156
brackets.fs.readdir("/This/directory/doesnt/exist", cb);
157157

158-
await awaitsFor(function () { return cb.wasCalled; }, "readdir to finish", 1000);
158+
await awaitsFor(function () { return cb.wasCalled; }, "readdir to finish");
159159

160160
expect(cb.error.code).toBe(brackets.fs.ERR_CODES.ENOENT);
161161
});
@@ -200,7 +200,7 @@ define(function (require, exports, module) {
200200

201201
brackets.fs.stat("/This/directory/doesnt/exist", cb);
202202

203-
await awaitsFor(function () { return cb.wasCalled; }, "stat to finish", 1000);
203+
await awaitsFor(function () { return cb.wasCalled; }, "stat to finish");
204204

205205
expect(cb.error.code).toBe(brackets.fs.ERR_CODES.ENOENT);
206206
});
@@ -235,7 +235,7 @@ define(function (require, exports, module) {
235235

236236
brackets.fs.readFile("/This/file/doesnt/exist.txt", UTF8, cb);
237237

238-
await awaitsFor(function () { return cb.wasCalled; }, "readFile to finish", 1000);
238+
await awaitsFor(function () { return cb.wasCalled; }, "readFile to finish");
239239

240240
expect(cb.error.code).toBe(brackets.fs.ERR_CODES.ENOENT);
241241
});
@@ -406,7 +406,7 @@ define(function (require, exports, module) {
406406

407407
brackets.fs.unlink("/This/file/doesnt/exist.txt", cb);
408408

409-
await awaitsFor(function () { return cb.wasCalled; }, "unlink to finish", 1000);
409+
await awaitsFor(function () { return cb.wasCalled; }, "unlink to finish");
410410

411411
expect(cb.error.code).toBe(brackets.fs.ERR_CODES.ENOENT);
412412
});

test/spec/ProjectManager-integ-test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
*/
2121

22-
/*global describe, it, expect, afterEach, awaitsFor, awaitsForDone, beforeAll, afterAll, awaits */
22+
/*global describe, it, expect, afterEach, awaitsFor, awaitsForDone, beforeAll, afterAll, awaits, Phoenix */
2323

2424
define(function (require, exports, module) {
2525

@@ -509,6 +509,10 @@ define(function (require, exports, module) {
509509
});
510510

511511
describe("Project, file and folder download", function () {
512+
if(Phoenix.browser.isTauri) {
513+
it("Not tested: download project is not present desktop local file system", async function () {});
514+
return;
515+
}
512516
it("should download project command work", async function () {
513517
let restore = testWindow.saveAs;
514518
let blob, name;

test/spec/SpecRunnerUtils.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
*/
2121

22-
/*global jsPromise, jasmine, expect, beforeEach, awaitsFor,awaitsForDone, spyOn, KeyboardEvent, waits, awaits */
22+
/*global Phoenix, jsPromise, jasmine, expect, awaitsFor,awaitsForDone, spyOn, awaits */
2323

2424
define(function (require, exports, module) {
2525

@@ -216,10 +216,16 @@ define(function (require, exports, module) {
216216
}
217217

218218
function getTestRoot() {
219+
if(Phoenix.browser.isTauri){
220+
return Phoenix.app.getApplicationSupportDirectory() + "test";
221+
}
219222
return '/test';
220223
}
221224

222-
function getTestPath(path) {
225+
function getTestPath(path = '') {
226+
if(path && !path.startsWith("/")){
227+
throw new Error("getTestPath path should start with a /");
228+
}
223229
return getTestRoot() + path;
224230
}
225231

@@ -712,6 +718,7 @@ define(function (require, exports, module) {
712718
delete _testWindow.fs;
713719

714720
}
721+
_testWindow.PhNodeEngine && _testWindow.PhNodeEngine.terminateNode();
715722
if(blankTestWindow){
716723
_testWindow.location.href = "about:blank";
717724
await awaits(2000); // UTS will crap without these time waits, esp in chromium. Browser freezes

0 commit comments

Comments
 (0)