-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node compat: Add path
member to fs.Dirent
#7649
Changes from 9 commits
2b77f81
f52535a
ebacf48
141b03f
52ebf5f
1cd7028
43c13ca
64bfef3
cf6b2fd
f3f34aa
d8267c5
ab38aa2
ba856cf
130237a
80c5253
7a49083
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// This script tests the contents of fs.Dirent for all of the methods that return it. | ||
// Compare running with node vs. running with Bun for compatibility. | ||
|
||
const fs = require('fs'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add automated tests This is not an automated test. It won't run in CI. Have a look at files with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I now see the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that sounds like a good place for the test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added some passing tests to test/js/node/fs/fs.test.ts. Ideally I would also test relative paths (i.e. |
||
|
||
// From the working directory, create a collection of files and folders for testing. | ||
const target = process.argv[2]; | ||
|
||
// pass arguments: | ||
// /tmp/test | ||
// ./test | ||
// test | ||
// . | ||
// ../../test | ||
// .. | ||
|
||
// path is always identical to the argument except for recursive entries | ||
// For recursed entries, a leading `./` is not included | ||
|
||
fs.mkdirSync(target + '/subfolder/childfolder/grandchildfolder', { recursive: true }); | ||
fs.writeFileSync(target + '/file.txt', 'test'); | ||
fs.writeFileSync(target + '/subfolder/childfile.txt', 'test'); | ||
fs.writeFileSync(target + '/subfolder/childfolder/grandchildfile.txt', 'test'); | ||
|
||
let results = {}; | ||
function mapFiles(files) { | ||
return files.map(f => ({ name: f.name, path: f.path })) | ||
.toSorted((a, b) => a.path+'/'+a.name < b.path+'/'+b.name); | ||
} | ||
|
||
results['fs.readdirSync'] = mapFiles(fs.readdirSync(target, { withFileTypes: true })); | ||
results['fs.readdirSync recursive'] = mapFiles(fs.readdirSync(target, { withFileTypes: true, recursive: true })); | ||
fs.promises.readdir(target, { withFileTypes: true, recursive: true }) | ||
.then(files => { | ||
results['fs.promises.readdir recursive'] = mapFiles(files); | ||
console.log(results); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since ????
should be removedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this entire file gets deleted to resolve the merge conflict -- if I'm understanding things correctly, type definitions are now in https://github.com/DefinitelyTyped/DefinitelyTyped per #7670.