Skip to content

Commit

Permalink
fs: add tests for writeFileSync with no flag
Browse files Browse the repository at this point in the history
  • Loading branch information
MuriloKakazu committed Dec 1, 2023
1 parent c323642 commit aaa4edd
Showing 1 changed file with 16 additions and 0 deletions.
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

0 comments on commit aaa4edd

Please sign in to comment.