Helper for running tests interacting with the file system: It should happen, but when? So stat again!
npm install stat-againWhen a file or a directory should be there but is not, or shouldn't be there but still is, promises are to be made and resolved. Node module ``stat-again` factors out some of the cumbersome logic.
`js
import {expectEventuallyFound} from 'stat-again';
const pathname = 'dir/file.js';
const delayInMs = 30;
const numberOfTries = 10;
expectEventuallyFound(pathname, delayInMs, numberOfTries)
.then(() => {
// File was found within a reasonable time
}, err => {
// Handle error
});
`
`js
import {expectEventuallyDeleted} from 'stat-again';
const pathname = 'dir/file.js';
const delayInMs = 30;
const numberOfTries = 10;
expectEventuallyDeleted(pathname, delayInMs, numberOfTries)
.then(() => {
// File was deleted within a reasonable time
}, err => {
// Handle error
});
`
Stats are as returned by fs.stat(path, callback).
`js
import statAgain from 'stat-again';
const pathname = 'dir/file.js';
const delayInMs = 30;
const numberOfTries = 10;
statAgain(pathname, delayInMs, numberOfTries)
.then(stats => {
// Do something with stats
}, err => {
// Handle error
});
`
`js
import {isNewerThan} from 'stat-again';
const pathname1 = 'dir/file1.js';
const pathname2 = 'dir/file2.js';
isNewerThan(pathname1, pathname2)
.then(bool => {
if (bool) {
// file1 is newer than file2...
} else {
// ...
}
}, err => {
// Handle error
});
``
stat-again is MIT licensed.
© 2016 Jason Lenoble