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

test: add fs/promises filehandle stat test #20492

Closed
Closed
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions test/parallel/test-fs-promises-file-handle-stat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const common = require('../common');

// The following tests validate base functionality for the fs/promises
// FileHandle.stat method.

const { open } = require('fs/promises');
const path = require('path');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const tmpDir = tmpdir.path;

tmpdir.refresh();
common.crashOnUnhandledRejection();

async function validateStat() {
const filePath = path.resolve(tmpDir, 'tmp-read-file.txt');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tmpDir is used used only once here.
Can we remove variable tmpDir and pass tmpdir.path here, so that there's no confusion between similar looking variables tmpdir and tmpDir

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trivikr
Thank you. I fixed it.

const fileHandle = await open(filePath, 'w+');
const stats = await fileHandle.stat();
assert.ok(stats.mtime instanceof Date);
}

validateStat()
.then(common.mustCall());