Skip to content
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

fix timeout in failing test #390

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions test/lib/fs.appendFile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ describe('fs.appendFile(filename, data, [options], callback)', function () {
});

it('promise writes a string to a new file', function (done) {
fs.promises.appendFile('foo', 'bar').then(function () {
assert.equal(String(fs.readFileSync('foo')), 'bar');
done();
}, done);
fs.promises
.appendFile('foo', 'bar')
.then(function () {
assert.equal(String(fs.readFileSync('foo')), 'bar');
done();
})
.catch(done);
});

it('appends a string to an existing file', function (done) {
Expand All @@ -43,10 +46,16 @@ describe('fs.appendFile(filename, data, [options], callback)', function () {
});

it('promise appends a string to an existing file', function (done) {
fs.promises.appendFile('dir/file.txt', ' bar').then(function () {
assert.equal(String(fs.readFileSync('dir/file.txt')), 'file content bar');
done();
}, done);
fs.promises
.appendFile('dir/file.txt', ' bar')
.then(function () {
assert.equal(
String(fs.readFileSync('dir/file.txt')),
'file content bar'
);
done();
})
.catch(done);
});

it('appends a buffer to a file', function (done) {
Expand All @@ -68,7 +77,8 @@ describe('fs.appendFile(filename, data, [options], callback)', function () {
'file content bar'
);
done();
}, done);
})
.catch(done);
});

it('appends via a symbolic link file', function (done) {
Expand All @@ -82,10 +92,16 @@ describe('fs.appendFile(filename, data, [options], callback)', function () {
});

it('promise appends via a symbolic link file', function (done) {
fs.promises.appendFile('link.txt', ' bar').then(function () {
assert.equal(String(fs.readFileSync('dir/file.txt')), 'file content bar');
done();
}, done);
fs.promises
.appendFile('link.txt', ' bar')
.then(function () {
assert.equal(
String(fs.readFileSync('dir/file.txt')),
'file content bar'
);
done();
})
.catch(done);
});

it('fails if directory does not exist', function (done) {
Expand Down
16 changes: 10 additions & 6 deletions test/lib/fs.chmod-fchmod.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ describe('fs.chmod(path, mode, callback)', function () {
});

it('promise changes permissions of a file', function (done) {
fs.promises.chmod('file.txt', parseInt('0664', 8)).then(function () {
const stats = fs.statSync('file.txt');
assert.equal(stats.mode & parseInt('0777', 8), parseInt('0664', 8));
done();
}, done);
fs.promises
.chmod('file.txt', parseInt('0664', 8))
.then(function () {
const stats = fs.statSync('file.txt');
assert.equal(stats.mode & parseInt('0777', 8), parseInt('0664', 8));
done();
})
.catch(done);
});

it('fails if file does not exist', function (done) {
Expand Down Expand Up @@ -117,7 +120,8 @@ describe('fs.fchmod(fd, mode, callback)', function () {
const stats = fs.statSync('file.txt');
assert.equal(stats.mode & parseInt('0777', 8), parseInt('0644', 8));
done();
}, done);
})
.catch(done);
});
});

Expand Down
6 changes: 4 additions & 2 deletions test/lib/fs.copyFile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ if (fs.copyFile && fs.copyFileSync) {
'file content'
);
done();
}, done);
})
.catch(done);
});

it('truncates dest file if it exists', function (done) {
Expand All @@ -75,7 +76,8 @@ if (fs.copyFile && fs.copyFileSync) {
'file content'
);
done();
}, done);
})
.catch(done);
});

it('throws if dest exists and exclusive', function (done) {
Expand Down
92 changes: 55 additions & 37 deletions test/lib/fs.link-symlink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ describe('fs.link(srcpath, dstpath, callback)', function () {
it('promise creates a link to a file', function (done) {
assert.equal(fs.statSync('file.txt').nlink, 1);

fs.promises.link('file.txt', 'link.txt').then(function () {
assert.isTrue(fs.statSync('link.txt').isFile());
assert.equal(fs.statSync('link.txt').nlink, 2);
assert.equal(fs.statSync('file.txt').nlink, 2);
assert.equal(String(fs.readFileSync('link.txt')), 'content');
done();
}, done);
fs.promises
.link('file.txt', 'link.txt')
.then(function () {
assert.isTrue(fs.statSync('link.txt').isFile());
assert.equal(fs.statSync('link.txt').nlink, 2);
assert.equal(fs.statSync('file.txt').nlink, 2);
assert.equal(String(fs.readFileSync('link.txt')), 'content');
done();
})
.catch(done);
});

it('works if original is renamed', function (done) {
Expand All @@ -71,12 +74,15 @@ describe('fs.link(srcpath, dstpath, callback)', function () {
});

it('promise works if original is renamed', function (done) {
fs.promises.link('file.txt', 'link.txt').then(function () {
fs.renameSync('file.txt', 'renamed.txt');
assert.isTrue(fs.statSync('link.txt').isFile());
assert.equal(String(fs.readFileSync('link.txt')), 'content');
done();
}, done);
fs.promises
.link('file.txt', 'link.txt')
.then(function () {
fs.renameSync('file.txt', 'renamed.txt');
assert.isTrue(fs.statSync('link.txt').isFile());
assert.equal(String(fs.readFileSync('link.txt')), 'content');
done();
})
.catch(done);
});

it('works if original is removed', function (done) {
Expand All @@ -99,15 +105,18 @@ describe('fs.link(srcpath, dstpath, callback)', function () {
it('promise works if original is removed', function (done) {
assert.equal(fs.statSync('file.txt').nlink, 1);

fs.promises.link('file.txt', 'link.txt').then(function () {
assert.equal(fs.statSync('link.txt').nlink, 2);
assert.equal(fs.statSync('file.txt').nlink, 2);
fs.unlinkSync('file.txt');
assert.isTrue(fs.statSync('link.txt').isFile());
assert.equal(fs.statSync('link.txt').nlink, 1);
assert.equal(String(fs.readFileSync('link.txt')), 'content');
done();
}, done);
fs.promises
.link('file.txt', 'link.txt')
.then(function () {
assert.equal(fs.statSync('link.txt').nlink, 2);
assert.equal(fs.statSync('file.txt').nlink, 2);
fs.unlinkSync('file.txt');
assert.isTrue(fs.statSync('link.txt').isFile());
assert.equal(fs.statSync('link.txt').nlink, 1);
assert.equal(String(fs.readFileSync('link.txt')), 'content');
done();
})
.catch(done);
});

it('fails if original is a directory', function (done) {
Expand Down Expand Up @@ -221,11 +230,14 @@ describe('fs.symlink(srcpath, dstpath, [type], callback)', function () {
}

it('promise creates a symbolic link to a file', function (done) {
fs.promises.symlink('../file.txt', 'dir/link.txt').then(function () {
assert.isTrue(fs.statSync('dir/link.txt').isFile());
assert.equal(String(fs.readFileSync('dir/link.txt')), 'content');
done();
}, done);
fs.promises
.symlink('../file.txt', 'dir/link.txt')
.then(function () {
assert.isTrue(fs.statSync('dir/link.txt').isFile());
assert.equal(String(fs.readFileSync('dir/link.txt')), 'content');
done();
})
.catch(done);
});

it('breaks if original is renamed', function (done) {
Expand All @@ -241,12 +253,15 @@ describe('fs.symlink(srcpath, dstpath, [type], callback)', function () {
});

it('promise breaks if original is renamed', function (done) {
fs.promises.symlink('file.txt', 'link.txt').then(function () {
assert.isTrue(fs.existsSync('link.txt'));
fs.renameSync('file.txt', 'renamed.txt');
assert.isFalse(fs.existsSync('link.txt'));
done();
}, done);
fs.promises
.symlink('file.txt', 'link.txt')
.then(function () {
assert.isTrue(fs.existsSync('link.txt'));
fs.renameSync('file.txt', 'renamed.txt');
assert.isFalse(fs.existsSync('link.txt'));
done();
})
.catch(done);
});

it('works if original is a directory', function (done) {
Expand All @@ -260,10 +275,13 @@ describe('fs.symlink(srcpath, dstpath, [type], callback)', function () {
});

it('promise works if original is a directory', function (done) {
fs.promises.symlink('dir', 'link').then(function () {
assert.isTrue(fs.statSync('link').isDirectory());
done();
}, done);
fs.promises
.symlink('dir', 'link')
.then(function () {
assert.isTrue(fs.statSync('link').isDirectory());
done();
})
.catch(done);
});
});

Expand Down
60 changes: 36 additions & 24 deletions test/lib/fs.lstat.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,27 @@ describe('fs.lstat(path, options, callback)', function () {
});

it('promise stats a symbolic link', function (done) {
fs.promises.lstat('link').then(function (stats) {
assert.isTrue(stats.isSymbolicLink());
assert.isFalse(stats.isFile());
assert.equal(stats.mtime.getTime(), 2);
done();
}, done);
fs.promises
.lstat('link')
.then(function (stats) {
assert.isTrue(stats.isSymbolicLink());
assert.isFalse(stats.isFile());
assert.equal(stats.mtime.getTime(), 2);
done();
})
.catch(done);
});

it('promise stats a symbolic link with bigint', function (done) {
fs.promises.lstat('link', {bigint: true}).then(function (stats) {
assert.isTrue(stats.isSymbolicLink());
assert.isFalse(stats.isFile());
assert.equal(typeof stats.mtimeMs, 'bigint');
done();
}, done);
fs.promises
.lstat('link', {bigint: true})
.then(function (stats) {
assert.isTrue(stats.isSymbolicLink());
assert.isFalse(stats.isFile());
assert.equal(typeof stats.mtimeMs, 'bigint');
done();
})
.catch(done);
});

it('stats a regular file', function (done) {
Expand Down Expand Up @@ -112,21 +118,27 @@ describe('fs.lstat(path, options, callback)', function () {
});

it('promise stats a regular file', function (done) {
fs.promises.lstat('file.txt').then(function (stats) {
assert.isTrue(stats.isFile());
assert.isFalse(stats.isSymbolicLink());
assert.equal(stats.mtime.getTime(), 1);
done();
}, done);
fs.promises
.lstat('file.txt')
.then(function (stats) {
assert.isTrue(stats.isFile());
assert.isFalse(stats.isSymbolicLink());
assert.equal(stats.mtime.getTime(), 1);
done();
})
.catch(done);
});

it('promise stats a regular file with bigint', function (done) {
fs.promises.lstat('file.txt', {bigint: true}).then(function (stats) {
assert.isTrue(stats.isFile());
assert.isFalse(stats.isSymbolicLink());
assert.equal(typeof stats.mtimeMs, 'bigint');
done();
}, done);
fs.promises
.lstat('file.txt', {bigint: true})
.then(function (stats) {
assert.isTrue(stats.isFile());
assert.isFalse(stats.isSymbolicLink());
assert.equal(typeof stats.mtimeMs, 'bigint');
done();
})
.catch(done);
});

it('fails on file not exist', function (done) {
Expand Down
34 changes: 21 additions & 13 deletions test/lib/fs.mkdir.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ describe('fs.mkdir(path, [mode], callback)', function () {
});

it('promise creates a new directory', function (done) {
fs.promises.mkdir('parent/dir').then(function () {
const stats = fs.statSync('parent/dir');
assert.isTrue(stats.isDirectory());
done();
}, done);
fs.promises
.mkdir('parent/dir')
.then(function () {
const stats = fs.statSync('parent/dir');
assert.isTrue(stats.isDirectory());
done();
})
.catch(done);
});

it('creates a new directory recursively', function (done) {
Expand Down Expand Up @@ -77,7 +80,8 @@ describe('fs.mkdir(path, [mode], callback)', function () {
stats = fs.statSync('parent/foo');
assert.isTrue(stats.isDirectory());
done();
}, done);
})
.catch(done);
});

it('accepts dir mode', function (done) {
Expand All @@ -93,12 +97,15 @@ describe('fs.mkdir(path, [mode], callback)', function () {
});

it('promise accepts dir mode', function (done) {
fs.promises.mkdir('parent/dir', parseInt('0755', 8)).then(function () {
const stats = fs.statSync('parent/dir');
assert.isTrue(stats.isDirectory());
assert.equal(stats.mode & parseInt('0777', 8), parseInt('0755', 8));
done();
}, done);
fs.promises
.mkdir('parent/dir', parseInt('0755', 8))
.then(function () {
const stats = fs.statSync('parent/dir');
assert.isTrue(stats.isDirectory());
assert.equal(stats.mode & parseInt('0777', 8), parseInt('0755', 8));
done();
})
.catch(done);
});

it('accepts dir mode recursively', function (done) {
Expand Down Expand Up @@ -141,7 +148,8 @@ describe('fs.mkdir(path, [mode], callback)', function () {
assert.isTrue(stats.isDirectory());
assert.equal(stats.mode & parseInt('0777', 8), parseInt('0755', 8));
done();
}, done);
})
.catch(done);
});

it('fails if parent does not exist', function (done) {
Expand Down
Loading
Loading