-
-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathLowLevelFileIO-test.js
More file actions
725 lines (508 loc) · 27.8 KB
/
LowLevelFileIO-test.js
File metadata and controls
725 lines (508 loc) · 27.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
/*
* GNU AGPL-3.0 License
*
* Copyright (c) 2021 - present core.ai . All rights reserved.
* Original work Copyright (c) 2012 - 2021 Adobe Systems Incorporated. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
*
*/
/*global describe, it, expect, beforeEach, afterEach, awaitsFor, awaitsForDone*/
define(function (require, exports, module) {
require("utils/Global");
// Load dependent modules
const SpecRunnerUtils = require("spec/SpecRunnerUtils"),
Strings = require("strings");
var UTF8 = "utf8",
UTF16 = "utf16";
// These are tests for the low-level file io routines in brackets-app. Make sure
// you have the latest brackets-app before running.
describe("LowLevelFileIO", function () {
var baseDir = SpecRunnerUtils.getTempDirectory(),
testDir;
function readdirSpy() {
var callback = function (err, content) {
callback.error = err;
callback.content = content;
callback.wasCalled = true;
};
callback.wasCalled = false;
return callback;
}
function statSpy() {
var callback = function (err, stat) {
callback.error = err;
callback.stat = stat;
callback.wasCalled = true;
};
callback.wasCalled = false;
return callback;
}
function readFileSpy() {
var callback = function (err, content) {
callback.error = err;
callback.content = content;
callback.wasCalled = true;
};
callback.wasCalled = false;
return callback;
}
function errSpy() {
var callback = function (err) {
callback.error = err;
callback.wasCalled = true;
};
callback.wasCalled = false;
return callback;
}
beforeEach(async function () {
await SpecRunnerUtils.createTempDirectory();
// create the test folder and init the test files
var testFiles = SpecRunnerUtils.getTestPath("/spec/LowLevelFileIO-test-files");
await awaitsForDone(SpecRunnerUtils.copy(testFiles, baseDir), "copy temp files");
testDir = `${baseDir}/LowLevelFileIO-test-files`;
});
afterEach(async function () {
await SpecRunnerUtils.removeTempDirectory();
});
it("should have a brackets.fs namespace", function () {
expect(brackets.fs).toBeTruthy();
});
it("should getDisplayLocation return correct path in browsers", function () {
// mount paths
expect(brackets.app.getDisplayLocation("/mnt/apple")).toBe("apple");
expect(brackets.app.getDisplayLocation("/mnt/apple/x/")).toBe("apple/x/");
// filer paths
expect(brackets.app.getDisplayLocation("/x/apple")).toBe("apple - "+ Strings.STORED_IN_YOUR_BROWSER);
expect(brackets.app.getDisplayLocation("/y/apple/x/")).toBe("x - " + Strings.STORED_IN_YOUR_BROWSER);
});
it("should getDisplayLocation return correct path in tauri", function () {
if(!Phoenix.isNativeApp) {
return;
}
// tauri paths
if(brackets.platform === "win"){
expect(brackets.app.getDisplayLocation("/tauri/x")).toBe("x:\\");
expect(brackets.app.getDisplayLocation("/tauri/x/y")).toBe("x:\\y");
expect(brackets.app.getDisplayLocation("/tauri/x/y/d.txt")).toBe("x:\\y\\d.txt");
} else {
expect(brackets.app.getDisplayLocation("/tauri/apple")).toBe("/apple");
expect(brackets.app.getDisplayLocation("/tauri/apple/x/")).toBe("/apple/x/");
}
});
describe("readdir", function () {
it("should read a directory from disk", async function () {
var cb = readdirSpy();
brackets.fs.readdir(testDir, cb);
await awaitsFor(function () { return cb.wasCalled; }, "readdir to finish", 1000);
expect(cb.error).toBeFalsy();
// Look for known files
expect(cb.content.indexOf("file_one.txt")).not.toBe(-1);
expect(cb.content.indexOf("file_two.txt")).not.toBe(-1);
expect(cb.content.indexOf("file_three.txt")).not.toBe(-1);
// Make sure '.' and '..' are omitted
expect(cb.content.indexOf(".")).toBe(-1);
expect(cb.content.indexOf("..")).toBe(-1);
});
it("should return an error if the directory doesn't exist", async function () {
var cb = readdirSpy();
brackets.fs.readdir("/This/directory/doesnt/exist", cb);
await awaitsFor(function () { return cb.wasCalled; }, "readdir to finish");
expect(cb.error.code).toBe(brackets.fs.ERR_CODES.ENOENT);
});
it("should return an error if invalid parameters are passed", function () {
var cb = readdirSpy();
expect(function () {
brackets.fs.readdir(42, cb);
}).toThrow();
});
}); // describe("readdir")
describe("stat", function () {
it("should return correct information for a directory", async function () {
var cb = statSpy();
brackets.fs.stat(baseDir, cb);
await awaitsFor(function () { return cb.wasCalled; }, 1000);
expect(cb.error).toBeFalsy();
expect(cb.stat.isDirectory()).toBe(true);
expect(cb.stat.isFile()).toBe(false);
});
it("should return correct information for a file", async function () {
var cb = statSpy();
brackets.fs.stat(testDir + "/file_one.txt", cb);
await awaitsFor(function () { return cb.wasCalled; }, "stat to finish", 1000);
expect(cb.error).toBeFalsy();
expect(cb.stat.isDirectory()).toBe(false);
expect(cb.stat.isFile()).toBe(true);
});
it("should return an error if the file/directory doesn't exist", async function () {
var cb = statSpy();
brackets.fs.stat("/This/directory/doesnt/exist", cb);
await awaitsFor(function () { return cb.wasCalled; }, "stat to finish");
expect(cb.error.code).toBe(brackets.fs.ERR_CODES.ENOENT);
});
it("should return an error if incorrect parameters are passed", async function () {
var cb = statSpy();
brackets.fs.stat(42, cb);
await awaitsFor(function () { return cb.wasCalled; }, "stat to finish", 1000);
expect(cb.error.code).toBe(brackets.fs.ERR_CODES.EINVAL);
});
}); // describe("stat")
describe("readFile", function () {
it("should read a text file", async function () {
var cb = readFileSpy();
brackets.fs.readFile(testDir + "/file_one.txt", UTF8, cb);
await awaitsFor(function () { return cb.wasCalled; }, "readFile to finish", 1000);
expect(cb.error).toBeFalsy();
expect(cb.content).toBe("Hello world");
});
it("should return an error if trying to read a non-existent file", async function () {
var cb = readFileSpy();
brackets.fs.readFile("/This/file/doesnt/exist.txt", UTF8, cb);
await awaitsFor(function () { return cb.wasCalled; }, "readFile to finish");
expect(cb.error.code).toBe(brackets.fs.ERR_CODES.ENOENT);
});
it("should return an error if trying to use an unsppported encoding", function () {
brackets.fs.readFile(testDir + "/file_one.txt", "NOT_AN_ENCODING", (e, c)=>{
expect(e.code).toBe(brackets.fs.ERR_CODES.ECHARSET);
expect(c).toBeUndefined();
});
});
it("should readFile error if called with invalid parameters", async function () {
let cb = readFileSpy();
brackets.fs.readFile(42, [], cb);
await awaitsFor(function () { return cb.wasCalled; }, "readFile to finish", 1000);
expect(cb.error.code).toBeDefined();
});
it("should return an error if trying to read a directory", async function () {
var cb = readFileSpy();
brackets.fs.readFile(baseDir, UTF8, cb);
await awaitsFor(function () { return cb.wasCalled; }, 1000);
expect(cb.error.code).toBe(brackets.fs.ERR_CODES.EISDIR);
});
it("should return an error trying to read a binary file", function () {
brackets.fs.readFile(testDir + "/tree.jpg", "binary", (a, c)=> {
expect(ArrayBuffer.isView(c)).toBe(true);
});
});
it("should be able to quickly determine if a large file is UTF-8", async function () {
var cb = readFileSpy();
brackets.fs.readFile(testDir + "/ru_utf8.html", UTF8, cb);
await awaitsFor(function () { return cb.wasCalled; }, "readFile to finish", 1000);
expect(cb.error).toBe(null);
});
it("should be able to quickly read a small UTF-8 file", async function () {
var cb = readFileSpy();
brackets.fs.readFile(testDir + "/es_small_utf8.html", UTF8, cb);
await awaitsFor(function () { return cb.wasCalled; }, "readFile to finish", 1000);
expect(cb.error).toBe(null);
});
it("should be able to read a zero-length file", async function () {
var cb = readFileSpy();
brackets.fs.readFile(testDir + "/emptyfile.txt", UTF8, cb);
await awaitsFor(function () { return cb.wasCalled; }, "readFile to finish", 1000);
expect(cb.error).toBe(null);
});
it("should be able to read a UTF-8 file with a BOM", async function () {
var cb = readFileSpy();
brackets.fs.readFile(testDir + "/ru_utf8_wBOM.html", UTF8, cb);
await awaitsFor(function () { return cb.wasCalled; }, "readFile to finish", 1000);
expect(cb.error).toBe(null);
expect(cb.content[0]).toBe("<"); // should not have BOM
});
}); // describe("readFile")
describe("writeFile", function () {
var contents = "This content was generated from LowLevelFileIO-test.js";
it("should write the entire contents of a file", async function () {
var cb = errSpy(),
readFileCB = readFileSpy();
brackets.fs.writeFile(baseDir + "/write_test.txt", contents, UTF8, cb);
await awaitsFor(function () { return cb.wasCalled; }, "writeFile to finish", 1000);
expect(cb.error).toBeFalsy();
// Read contents to verify
brackets.fs.readFile(baseDir + "/write_test.txt", UTF8, readFileCB);
await awaitsFor(function () { return readFileCB.wasCalled; }, 1000);
expect(readFileCB.error).toBeFalsy();
expect(readFileCB.content).toBe(contents);
});
it("should writeFile return an error if called with invalid parameters", async function () {
var cb = errSpy();
brackets.fs.writeFile(42, contents, "utf8", cb);
await awaitsFor(function () { return cb.wasCalled; }, "writeFile to finish", 1000);
expect(cb.error.code).toBeDefined();
});
it("should return an error if trying to write a directory", async function () {
var cb = errSpy();
brackets.fs.writeFile(baseDir, contents, UTF8, cb);
await awaitsFor(function () { return cb.wasCalled; }, "writeFile to finish", 1000);
// Ideally we would get ERR_CANT_WRITE, but as long as we get some sort of error it's fine.
expect(cb.error).toBeTruthy();
});
}); // describe("writeFile")
describe("unlink", function () {
var contents = "This content was generated from LowLevelFileIO-test.js";
it("should remove a file", async function () {
var filename = baseDir + "/remove_me.txt",
writeFileCB = errSpy(),
readFileCB = readFileSpy(),
unlinkCB = errSpy(),
statCB = statSpy();
brackets.fs.writeFile(filename, contents, UTF8, writeFileCB);
await awaitsFor(function () { return writeFileCB.wasCalled; }, "writeFile to finish", 1000);
expect(writeFileCB.error).toBeFalsy();
brackets.fs.readFile(filename, UTF8, readFileCB);
await awaitsFor(function () { return readFileCB.wasCalled; }, "readFile to finish", 1000);
expect(readFileCB.error).toBeFalsy();
expect(readFileCB.content).toBe(contents);
// Remove the file
brackets.fs.unlink(filename, unlinkCB);
await awaitsFor(function () { return unlinkCB.wasCalled; }, "unlink to finish", 1000);
expect(unlinkCB.error).toBeFalsy();
// Verify it is gone
brackets.fs.stat(filename, statCB);
await awaitsFor(function () { return statCB.wasCalled; }, "stat to finish", 1000);
expect(statCB.error.code).toBe(brackets.fs.ERR_CODES.ENOENT);
});
it("should return an error if the file doesn't exist", async function () {
var cb = errSpy();
brackets.fs.unlink("/This/file/doesnt/exist.txt", cb);
await awaitsFor(function () { return cb.wasCalled; }, "unlink to finish");
expect(cb.error.code).toBe(brackets.fs.ERR_CODES.ENOENT);
});
it("should unlink return an error if called with invalid parameters", async function () {
var cb = errSpy();
brackets.fs.unlink(42, cb);
await awaitsFor(function () { return cb.wasCalled; }, "unlink to finish", 1000);
expect(cb.error.code).toBe(brackets.fs.ERR_CODES.EINVAL);
});
it("should remove a directory", async function () {
var delDirName = baseDir + "/unlink_dir",
cb = errSpy(),
statCB = statSpy(),
unlinkCB = errSpy();
brackets.fs.mkdir(delDirName, 0o777, cb);
await awaitsFor(function () { return cb.wasCalled; }, "makeDir to finish");
expect(cb.error).toBe(null);
// Verify directory was created
brackets.fs.stat(delDirName, statCB);
await awaitsFor(function () { return statCB.wasCalled; }, "stat to finish");
expect(statCB.error).toBe(null);
expect(statCB.stat.isDirectory()).toBe(true);
// Delete the directory
brackets.fs.unlink(delDirName, unlinkCB);
await awaitsFor(function () { return unlinkCB.wasCalled; });
expect(cb.error).toBe(null);
// Verify it is gone
statCB = statSpy();
brackets.fs.stat(delDirName, statCB);
await awaitsFor(function () { return statCB.wasCalled; }, 1000, "stat to finish");
expect(statCB.error.code).toBe(brackets.fs.ERR_CODES.ENOENT);
});
}); // describe("unlink")
describe("makedir", function () {
it("should make a new directory", async function () {
var newDirName = baseDir + "/brackets_unittests_new_dir",
cb = errSpy(),
statCB = statSpy(),
trashCB = errSpy();
brackets.fs.mkdir(newDirName, 0o777, cb);
await awaitsFor(function () { return cb.wasCalled; }, "makedir to finish");
expect(cb.error).toBe(null);
// Verify directory was created
brackets.fs.stat(newDirName, statCB);
await awaitsFor(function () { return statCB.wasCalled; }, "stat to finish");
expect(statCB.error).toBe(null);
expect(statCB.stat.isDirectory()).toBe(true);
// Delete the directory
brackets.fs.unlink(newDirName, trashCB);
await awaitsFor(function () { return trashCB.wasCalled; }, "moveToTrash to finish");
expect(trashCB.error).toBe(null);
});
});
describe("rename", function () {
var complete;
it("should rename a file", async function () {
var oldName = testDir + "/file_one.txt",
newName = testDir + "/file_one_renamed.txt",
renameCB = errSpy(),
statCB = statSpy();
complete = false;
brackets.fs.rename(oldName, newName, renameCB);
await awaitsFor(function () { return renameCB.wasCalled; }, "rename to finish", 1000);
expect(renameCB.error).toBe(null);
// Verify new file is found and old one is missing
brackets.fs.stat(oldName, statCB);
await awaitsFor(function () { return statCB.wasCalled; }, "stat to finish", 1000);
expect(statCB.error.code).toBe(brackets.fs.ERR_CODES.ENOENT);
statCB = statSpy();
brackets.fs.stat(newName, statCB);
await awaitsFor(function () { return statCB.wasCalled; }, "stat to finish", 1000);
expect(statCB.error).toBe(null);
// Rename the file back to the old name
renameCB = errSpy();
brackets.fs.rename(newName, oldName, renameCB);
await awaitsFor(function () { return renameCB.wasCalled; }, "rename to finish", 1000);
expect(renameCB.error).toBe(null);
});
it("should rename a folder", async function () {
var oldName = testDir + "/rename_me",
newName = testDir + "/renamed_folder",
renameCB = errSpy(),
statCB = statSpy();
complete = false;
brackets.fs.rename(oldName, newName, renameCB);
await awaitsFor(function () { return renameCB.wasCalled; }, "rename to finish", 1000);
expect(renameCB.error).toBe(null);
// Verify new folder is found and old one is missing
brackets.fs.stat(oldName, statCB);
await awaitsFor(function () { return statCB.wasCalled; }, "stat to finish", 1000);
expect(statCB.error.code).toBe(brackets.fs.ERR_CODES.ENOENT);
statCB = statSpy();
brackets.fs.stat(newName, statCB);
await awaitsFor(function () { return statCB.wasCalled; }, "stat to finish", 1000);
expect(statCB.error).toBe(null);
// Rename the folder back to the old name
renameCB = errSpy();
brackets.fs.rename(newName, oldName, renameCB);
await awaitsFor(function () { return renameCB.wasCalled; }, "rename to finish", 1000);
expect(renameCB.error).toBe(null);
});
it("should rename return an error if the new name already exists", async function () {
var oldName = testDir + "/file_one.txt",
newName = testDir + "/file_two.txt",
cb = errSpy();
complete = false;
brackets.fs.rename(oldName, newName, cb);
await awaitsFor(function () { return cb.wasCalled; }, "rename to finish", 1000);
expect(cb.error.code).toBe(brackets.fs.ERR_CODES.EEXIST);
});
// TODO: More testing of error cases?
});
describe("copyFile", function () {
var complete;
it("should copy a file", async function () {
var fileName = testDir + "/file_one.txt",
copyName = testDir + "/file_one_copy.txt",
copyCB = errSpy(),
unlinkCB = errSpy(),
statCB = statSpy(),
statCBsrc =statSpy();
complete = false;
// Verify new file does not exist
brackets.fs.stat(copyName, statCB);
await awaitsFor(function () { return statCB.wasCalled; }, "stat to finish", 1000);
expect(statCB.error.code).toBe(brackets.fs.ERR_CODES.ENOENT);
// Verify src file exist
brackets.fs.stat(fileName, statCBsrc);
await awaitsFor(function () { return statCBsrc.wasCalled; }, "stat to finish", 1000);
expect(statCBsrc.error).toBe(null);
// make the copy
brackets.fs.copyFile(fileName, copyName, copyCB);
await awaitsFor(function () { return copyCB.wasCalled; }, "copyFile to finish", 1000);
expect(copyCB.error).toBe(null);
// Verify new file is found
statCB = statSpy();
brackets.fs.stat(copyName, statCB);
await awaitsFor(function () { return statCB.wasCalled; }, "stat to finish", 1000);
expect(statCB.error).toBe(null);
// Verify the origin file still exists
statCB = statSpy();
brackets.fs.stat(fileName, statCB);
await awaitsFor(function () { return statCB.wasCalled; }, "stat to finish", 1000);
expect(statCB.error).toBe(null);
// Delete the copy
brackets.fs.unlink(copyName, unlinkCB);
await awaitsFor(function () { return unlinkCB.wasCalled; }, "unlink to finish", 1000);
expect(unlinkCB.error).toBe(null);
});
});
describe("specialDirectories", function () {
it("should have an application support directory", async function () {
// these tests are here as these are absolute unchanging dir convention used by phoenix.
if(window.__TAURI__){
const appSupportDIR = window.fs.getTauriVirtualPath(window._tauriBootVars.appLocalDir);
expect(brackets.app.getApplicationSupportDirectory().startsWith("/tauri/")).toBeTrue();
expect(brackets.app.getApplicationSupportDirectory()).toBe(appSupportDIR);
} else {
expect(brackets.app.getApplicationSupportDirectory()).toBe('/fs/app/');
}
});
it("should have a user documents directory", function () {
// these tests are here as these are absolute unchanging dir convention used by phoenix.
if(window.__TAURI__){
const documentsDIR = window.fs.getTauriVirtualPath(window._tauriBootVars.documentDir);
expect(brackets.app.getUserDocumentsDirectory().startsWith("/tauri/")).toBeTrue();
expect(brackets.app.getUserDocumentsDirectory()).toBe(documentsDIR);
} else {
expect(brackets.app.getUserDocumentsDirectory()).toBe('/fs/local/');
}
});
it("should have a user projects directory", function () {
// these tests are here as these are absolute unchanging dir convention used by phoenix.
if(window.__TAURI__){
const documentsDIR = window.fs.getTauriVirtualPath(window._tauriBootVars.documentDir);
const appName = window._tauriBootVars.appname;
const userProjectsDir = `${documentsDIR}${appName}/`;
expect(brackets.app.getUserProjectsDirectory().startsWith("/tauri/")).toBeTrue();
expect(brackets.app.getUserProjectsDirectory()).toBe(userProjectsDir);
} else {
expect(brackets.app.getUserProjectsDirectory()).toBe('/fs/local/');
}
});
it("should have a temp directory", function () {
// these tests are here as these are absolute unchanging dir convention used by phoenix.
if(window.__TAURI__){
let tempDIR = window.fs.getTauriVirtualPath(window._tauriBootVars.tempDir);
if(!tempDIR.endsWith("/")){
tempDIR = `${tempDIR}/`;
}
const appName = window._tauriBootVars.appname;
tempDIR = `${tempDIR}${appName}/`;
expect(brackets.app.getTempDirectory().startsWith("/tauri/")).toBeTrue();
expect(brackets.app.getTempDirectory()).toBe(tempDIR);
} else {
expect(brackets.app.getTempDirectory()).toBe('/temp/');
}
});
it("should have extensions directory", function () {
// these tests are here as these are absolute unchanging dir convention used by phoenix.
if(window.__TAURI__){
const appSupportDIR = window.fs.getTauriVirtualPath(window._tauriBootVars.appLocalDir);
const extensionsDir = `${appSupportDIR}assets/extensions/`;
expect(brackets.app.getExtensionsDirectory().startsWith("/tauri/")).toBeTrue();
expect(brackets.app.getExtensionsDirectory()).toBe(extensionsDir);
} else {
expect(brackets.app.getExtensionsDirectory()).toBe('/fs/app/extensions/');
}
});
it("should get virtual serving directory from virtual serving URL in browser", async function () {
if(window.__TAURI__){
return;
}
expect(brackets.VFS.getPathForVirtualServingURL(`${window.fsServerUrl}blinker`)).toBe("/blinker");
expect(brackets.VFS.getPathForVirtualServingURL(`${window.fsServerUrl}path/to/file_x.mp3`))
.toBe("/path/to/file_x.mp3");
expect(brackets.VFS.getPathForVirtualServingURL("/some/path")).toBe(null);
expect(brackets.VFS.getPathForVirtualServingURL("/fs")).toBe(null);
});
it("should not get virtual serving directory from virtual serving URL in tauri", async function () {
if(!window.__TAURI__){
return;
}
expect(window.fsServerUrl).not.toBeDefined();
expect(brackets.VFS.getPathForVirtualServingURL("/some/path")).toBe(null);
expect(brackets.VFS.getPathForVirtualServingURL("/fs")).toBe(null);
});
});
});
});