Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2921565
test_fs_sync.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
test_fs_sync.js
View Options
import
{
readFileSync
,
writeFileSync
,
unlinkSync
,
mkdirSync
,
rmdirSync
,
statSync
}
from
'ant:fs'
;
console
.
log
(
'Testing ant:fs with synchronous operations...\n'
);
function
testFs
()
{
const
testDir
=
'tests/.fs_test_tmp_sync'
;
const
testFile
=
testDir
+
'/sync_test.txt'
;
const
testData
=
'Hello from sync ant:fs!'
;
try
{
// Test mkdirSync
console
.
log
(
'=== Test: mkdirSync ==='
);
try
{
mkdirSync
(
testDir
);
console
.
log
(
'✓ Directory created'
);
}
catch
(
e
)
{
console
.
log
(
'Directory might exist, continuing...'
);
}
// Test writeFileSync
console
.
log
(
'\n=== Test: writeFileSync ==='
);
writeFileSync
(
testFile
,
testData
);
console
.
log
(
'✓ File written'
);
// Test readFileSync
console
.
log
(
'\n=== Test: readFileSync ==='
);
const
content
=
readFileSync
(
testFile
);
console
.
log
(
'✓ File read, length:'
,
content
.
length
);
if
(
content
===
testData
)
{
console
.
log
(
'✓ Content matches!'
);
}
else
{
console
.
log
(
'✗ Content mismatch!'
);
}
// Test statSync
console
.
log
(
'\n=== Test: statSync ==='
);
const
stats
=
statSync
(
testFile
);
console
.
log
(
'✓ File stats:'
);
console
.
log
(
' Size:'
,
stats
.
size
);
console
.
log
(
' Is file:'
,
stats
.
isFile
);
console
.
log
(
' Is directory:'
,
stats
.
isDirectory
);
// Cleanup
console
.
log
(
'\n=== Cleanup ==='
);
unlinkSync
(
testFile
);
console
.
log
(
'✓ File deleted'
);
rmdirSync
(
testDir
);
console
.
log
(
'✓ Directory deleted'
);
console
.
log
(
'\n✓✓✓ All tests passed! ✓✓✓'
);
}
catch
(
error
)
{
console
.
error
(
'\n✗ Test failed:'
,
error
);
}
}
// Run the synchronous function
testFs
();
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Mar 27, 9:54 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
512386
Default Alt Text
test_fs_sync.js (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment