Skip to content
Merged
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
Prev Previous commit
fs: add tests for writeFileSync with no flag
  • Loading branch information
MuriloKakazu committed Dec 1, 2023
commit aaa4edda7d2e16a284f893c9cb49459b1271e4d5
16 changes: 16 additions & 0 deletions test/parallel/test-fs-write-file-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ tmpdir.refresh();
assert.strictEqual(content, 'hello world!');
}

// Test writeFileSync with no flags
{
const utf8Data = 'hello world!';
for (const test of [
{ data: utf8Data },
{ data: utf8Data, options: { encoding: 'utf8' } },
{ data: Buffer.from(utf8Data, 'utf8').toString('hex'), options: { encoding: 'hex' } },
]) {
const file = tmpdir.resolve(`testWriteFileSyncNewFile_${Math.random()}.txt`);
fs.writeFileSync(file, test.data, test.options);

const content = fs.readFileSync(file, { encoding: 'utf-8' });
assert.strictEqual(content, utf8Data);
}
}

// Test writeFileSync with an invalid input
{
const file = tmpdir.resolve('testWriteFileSyncInvalid.txt');
Expand Down