Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2921821
fs.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
fs.js
View Options
import
{
test
,
summary
}
from
'./helpers.js'
;
import
fs
from
'ant:fs'
;
import
path
from
'ant:path'
;
console
.
log
(
'FS Tests\n'
);
const
testDir
=
'/tmp/ant-spec-test'
;
const
testFile
=
path
.
join
(
testDir
,
'test.txt'
);
fs
.
mkdirSync
(
testDir
,
{
recursive
:
true
});
test
(
'mkdirSync creates dir'
,
fs
.
existsSync
(
testDir
),
true
);
fs
.
writeFileSync
(
testFile
,
'hello world'
);
test
(
'writeFileSync creates file'
,
fs
.
existsSync
(
testFile
),
true
);
const
content
=
fs
.
readFileSync
(
testFile
,
'utf8'
);
test
(
'readFileSync content'
,
content
,
'hello world'
);
fs
.
appendFileSync
(
testFile
,
'!'
);
const
appended
=
fs
.
readFileSync
(
testFile
,
'utf8'
);
test
(
'appendFileSync'
,
appended
,
'hello world!'
);
const
stat
=
fs
.
statSync
(
testFile
);
test
(
'statSync isFile'
,
stat
.
isFile
(),
true
);
test
(
'statSync isDirectory'
,
stat
.
isDirectory
(),
false
);
test
(
'statSync size'
,
stat
.
size
>
0
,
true
);
const
dirStat
=
fs
.
statSync
(
testDir
);
test
(
'statSync dir isDirectory'
,
dirStat
.
isDirectory
(),
true
);
const
copyFile
=
path
.
join
(
testDir
,
'copy.txt'
);
fs
.
copyFileSync
(
testFile
,
copyFile
);
test
(
'copyFileSync'
,
fs
.
existsSync
(
copyFile
),
true
);
const
renameFile
=
path
.
join
(
testDir
,
'renamed.txt'
);
fs
.
renameSync
(
copyFile
,
renameFile
);
test
(
'renameSync'
,
fs
.
existsSync
(
renameFile
),
true
);
test
(
'renameSync removes old'
,
fs
.
existsSync
(
copyFile
),
false
);
const
files
=
fs
.
readdirSync
(
testDir
);
test
(
'readdirSync length'
,
files
.
length
>=
2
,
true
);
test
(
'readdirSync includes test.txt'
,
files
.
includes
(
'test.txt'
),
true
);
fs
.
unlinkSync
(
testFile
);
test
(
'unlinkSync removes file'
,
fs
.
existsSync
(
testFile
),
false
);
fs
.
unlinkSync
(
renameFile
);
fs
.
rmdirSync
(
testDir
);
test
(
'rmdirSync removes dir'
,
fs
.
existsSync
(
testDir
),
false
);
summary
();
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Mar 27, 11:06 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
513077
Default Alt Text
fs.js (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment