-
Notifications
You must be signed in to change notification settings - Fork 112
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
stats: true outputs different data shape #246
Comments
For anyone else finding their way here from a google search, here is the TLDR: const fs = require('fs-extra');
const glob = require('fast-glob');
const path = require('path');
function copyFiles (filePatterns, excludes, dist) {
/*
Mock-fs in our unit tests, and versions of Node below 10.10, require stats to be true.
This will return an array of detailed objects about each file. stats: false is roughly
twice as fast and returns only an array of strings of the paths. This would be preferred
in the future for the performance increase, but for now, we have to live with this for
compatibility.
*/
const weAreUsingMockFsOrNodeUnder10dot10 = true;
const filesToCopy = glob.sync(filePatterns, {
ignore: excludes,
stats: weAreUsingMockFsOrNodeUnder10dot10
});
filesToCopy.forEach(function (file) {
try {
fs.copySync(file.path, path.join(dist, file.path));
} catch (err) {
console.log('Error copying file.');
console.log(file);
console.log(err);
}
});
} |
I'm sorry, but I don't see how I can help you. The Most likely the |
Thanks for the feedback! Closed in favor of tschaub/mock-fs#272 and possible solution — tschaub/mock-fs#287. |
Environment
Actual behavior
Expected behavior
The documentation states that the difference between
stats: true/false
is merely performance and the speed increase comes from newer Node versions.I was having issues testing this, because
mock-fs
got confused whenstats: false
was used (orstats
was omitted). I found a GitHub issue saying to fix this just run the slower version when running your tests:But this means my tests and my source code are expecting different data shapes.
My only course of action now is to always use the slow option to ensure it works everywhere.
It seems as though stats has two meanings. A boolean to double or half your performance. And a boolean to decide if you only need file paths, or details about each file. These concepts should not be linked like this.
The text was updated successfully, but these errors were encountered: